]> BookStack Code Mirror - bookstack/blob - resources/assets/js/components/toggle-switch.js
Standardised module loading system & fixed build system
[bookstack] / resources / assets / js / components / toggle-switch.js
1
2 class ToggleSwitch {
3
4     constructor(elem) {
5         this.elem = elem;
6         this.input = elem.querySelector('input');
7
8         this.elem.onclick = this.onClick.bind(this);
9     }
10
11     onClick(event) {
12         let checked = this.input.value !== 'true';
13         this.input.value = checked ? 'true' : 'false';
14         checked ? this.elem.classList.add('active') : this.elem.classList.remove('active');
15     }
16
17 }
18
19 export default ToggleSwitch;