bindSimpleSwitch()

This commit is contained in:
Maxim Devaev 2021-08-13 16:39:56 +03:00
parent c233e3bee7
commit 976662df83
4 changed files with 8 additions and 13 deletions

View File

@ -36,11 +36,7 @@ export function Atx() {
$("atx-power-led").title = "Power Led"; $("atx-power-led").title = "Power Led";
$("atx-hdd-led").title = "Disk Activity Led"; $("atx-hdd-led").title = "Disk Activity Led";
$("atx-ask-switch").checked = tools.storage.getBool("atx.ask", true); tools.storage.bindSimpleSwitch($("atx-ask-switch"), "atx.ask", true);
tools.el.setOnClick($("atx-ask-switch"), function() {
tools.storage.setBool("atx.ask", $("atx-ask-switch").checked);
}, false);
for (let args of [ for (let args of [
["atx-power-button", "power", "Are you sure you want to press the power button?"], ["atx-power-button", "power", "Are you sure you want to press the power button?"],

View File

@ -74,10 +74,7 @@ export function Hid(__getResolution) {
window.addEventListener("pagehide", __releaseAll); window.addEventListener("pagehide", __releaseAll);
window.addEventListener("blur", __releaseAll); window.addEventListener("blur", __releaseAll);
$("hid-pak-ask-switch").checked = tools.storage.getBool("hid.pak.ask", true); tools.storage.bindSimpleSwitch($("hid-pak-ask-switch"), "hid.pak.ask", true);
tools.el.setOnClick($("hid-pak-ask-switch"), function() {
tools.storage.setBool("hid.pak.ask", $("hid-pak-ask-switch").checked);
}, false);
$("hid-pak-keymap-selector").addEventListener("change", function() { $("hid-pak-keymap-selector").addEventListener("change", function() {
tools.storage.set("hid.pak.keymap", $("hid-pak-keymap-selector").value); tools.storage.set("hid.pak.keymap", $("hid-pak-keymap-selector").value);

View File

@ -61,10 +61,7 @@ export function Mouse(__getResolution, __recordWsEvent) {
$("stream-box").onwheel = __streamWheelHandler; $("stream-box").onwheel = __streamWheelHandler;
$("stream-box").ontouchstart = (event) => __streamTouchMoveHandler(event); $("stream-box").ontouchstart = (event) => __streamTouchMoveHandler(event);
$("hid-mouse-squash-switch").checked = tools.storage.getBool("hid.mouse.squash", true); tools.storage.bindSimpleSwitch($("hid-mouse-squash-switch"), "hid.mouse.squash", true);
tools.el.setOnClick($("hid-mouse-squash-switch"), function() {
tools.storage.setBool("hid.mouse.squash", $("hid-mouse-squash-switch").checked);
}, false);
setInterval(__sendMove, 100); setInterval(__sendMove, 100);
}; };

View File

@ -280,6 +280,11 @@ export var tools = new function() {
"getBool": (key, default_value) => !!parseInt(self.storage.get(key, (default_value ? "1" : "0"))), "getBool": (key, default_value) => !!parseInt(self.storage.get(key, (default_value ? "1" : "0"))),
"setBool": (key, value) => self.storage.set(key, (value ? "1" : "0")), "setBool": (key, value) => self.storage.set(key, (value ? "1" : "0")),
"bindSimpleSwitch": function(el, key, default_value) {
el.checked = self.storage.getBool(key, default_value);
self.el.setOnClick(el, () => self.storage.setBool(key, el.checked), false);
},
}; };
}; };