]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/toggle-switch.js
added rtl support for hebrew + added to localMap
[bookstack] / resources / assets / js / components / toggle-switch.js
index 8eb559506d5bd562220cbe8d1d96b6724c6baec1..3dd1ce85ccb4bd3d94983e34605a2651d3d47be0 100644 (file)
@@ -3,17 +3,16 @@ 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.stateChange.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');
+    stateChange() {
+        this.input.value = (this.checkbox.checked ? 'true' : 'false');
     }
 
 }
 
-module.exports = ToggleSwitch;
\ No newline at end of file
+export default ToggleSwitch;
\ No newline at end of file