add darkmode, minimize js/css
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
export default class extends Controller {
|
||||
modes;
|
||||
currentState;
|
||||
connect() {
|
||||
this.modes = $(this.element).find('p');
|
||||
this.currentState = localStorage.getItem('themeMode');
|
||||
this.changeState()
|
||||
}
|
||||
switch(event) {
|
||||
var mode = event.params.mode;
|
||||
this.changeState(mode);
|
||||
|
||||
}
|
||||
|
||||
changeState(newState) {
|
||||
if (typeof newState !== 'undefined') {
|
||||
localStorage.setItem("themeMode", newState);
|
||||
this.currentState = newState;
|
||||
}
|
||||
// $('html').attr('data-bs-theme', this.currentState);
|
||||
this.modes.filter((e,tmp)=>{
|
||||
const obj = $(tmp);
|
||||
obj.toggle(!obj.hasClass(this.currentState));
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user