1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00
appwrite/public/scripts/views/forms/switch.js
2019-09-13 13:47:07 +03:00

31 lines
743 B
JavaScript

(function(window) {
"use strict";
window.ls.container.get("view").add({
selector: "data-forms-switch",
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);