1
0
Fork 0
mirror of synced 2024-07-06 23:21:05 +12:00
appwrite/public/scripts/views/forms/switch.js

34 lines
979 B
JavaScript
Raw Normal View History

2019-05-09 18:54:39 +12:00
(function (window) {
"use strict";
2019-05-09 20:01:51 +12:00
window.ls.container.get('view').add(
2019-05-09 18:54:39 +12:00
{
selector: 'data-forms-switch',
repeat: false,
controller: function(element) {
let input = window.document.createElement('input');
input.type = 'checkbox';
input.className = 'switch';
let syncA = function () {
element.value = (input.checked) ? 'on' : 'off';
};
let syncB = function () {
input.checked = (element.value === 'on');
};
input.addEventListener('input', syncA);
input.addEventListener('change', syncA);
element.addEventListener('input', syncB);
element.addEventListener('change', syncB);
syncA();
element.parentNode.insertBefore(input, element);
}
}
);
})(window);