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