BookStack/resources/assets/js/components/toggle-switch.js
Dan Brown e3230f8f21
Standardised module loading system & fixed build system
Fixed broken build system in broken webpack version.
Also updates module system to standardise on ES6 import/exports,
Especially since babel has changed it's 'default' logic for the old
module system.
2018-11-09 21:17:35 +00:00

19 lines
No EOL
441 B
JavaScript

class ToggleSwitch {
constructor(elem) {
this.elem = elem;
this.input = elem.querySelector('input');
this.elem.onclick = this.onClick.bind(this);
}
onClick(event) {
let checked = this.input.value !== 'true';
this.input.value = checked ? 'true' : 'false';
checked ? this.elem.classList.add('active') : this.elem.classList.remove('active');
}
}
export default ToggleSwitch;