]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/toggle-switch.js
Update maintenance.php
[bookstack] / resources / assets / js / components / toggle-switch.js
index 8eb559506d5bd562220cbe8d1d96b6724c6baec1..3be67d5dc94afb0f0f10ec6788c6590541ab04f0 100644 (file)
@@ -3,17 +3,17 @@ class ToggleSwitch {
 
     constructor(elem) {
         this.elem = elem;
-        this.input = elem.querySelector('input');
+        this.input = elem.querySelector('input[type=hidden]');
+        this.checkbox = elem.querySelector('input[type=checkbox]');
 
-        this.elem.onclick = this.onClick.bind(this);
+        this.checkbox.addEventListener('change', this.onClick.bind(this));
     }
 
     onClick(event) {
-        let checked = this.input.value !== 'true';
+        let checked = this.checkbox.checked;
         this.input.value = checked ? 'true' : 'false';
-        checked ? this.elem.classList.add('active') : this.elem.classList.remove('active');
     }
 
 }
 
-module.exports = ToggleSwitch;
\ No newline at end of file
+export default ToggleSwitch;
\ No newline at end of file