mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-21 22:36:05 +08:00
Upgraded app to Laravel 5.7
This commit is contained in:
23
resources/js/components/toggle-switch.js
Normal file
23
resources/js/components/toggle-switch.js
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
class ToggleSwitch {
|
||||
|
||||
constructor(elem) {
|
||||
this.elem = elem;
|
||||
this.input = elem.querySelector('input[type=hidden]');
|
||||
this.checkbox = elem.querySelector('input[type=checkbox]');
|
||||
|
||||
this.checkbox.addEventListener('change', this.stateChange.bind(this));
|
||||
}
|
||||
|
||||
stateChange() {
|
||||
this.input.value = (this.checkbox.checked ? 'true' : 'false');
|
||||
|
||||
// Dispatch change event from hidden input so they can be listened to
|
||||
// like a normal checkbox.
|
||||
const changeEvent = new Event('change');
|
||||
this.input.dispatchEvent(changeEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ToggleSwitch;
|
Reference in New Issue
Block a user