28 lines
771 B
JavaScript
28 lines
771 B
JavaScript
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));
|
|
})
|
|
}
|
|
}
|