1
0
Fork 0
mirror of synced 2024-07-08 16:06:02 +12:00
appwrite/public/scripts/views/forms/switch.js

31 lines
743 B
JavaScript
Raw Normal View History

(function(window) {
"use strict";
2019-05-09 18:54:39 +12:00
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";
2019-05-09 18:54:39 +12:00
let syncA = function() {
element.value = input.checked ? "on" : "off";
};
2019-05-09 18:54:39 +12:00
let syncB = function() {
input.checked = element.value === "on";
};
2019-05-09 18:54:39 +12:00
input.addEventListener("input", syncA);
input.addEventListener("change", syncA);
2019-05-09 18:54:39 +12:00
element.addEventListener("input", syncB);
element.addEventListener("change", syncB);
2019-05-09 18:54:39 +12:00
syncA();
2019-05-09 18:54:39 +12:00
element.parentNode.insertBefore(input, element);
}
});
})(window);