2018-03-18 16:13:46 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:17:35 +01:00
|
|
|
export default ToggleSwitch;
|