summaryrefslogtreecommitdiff
path: root/web/share/js/tools.js
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-03-11 19:54:55 +0300
committerMaxim Devaev <[email protected]>2022-03-11 19:54:55 +0300
commitf04617ac4f3bbe4b4512d09efacd0787b950bf8d (patch)
tree6fdcbd67f157cb06c0408a66ae06922e39de6dbd /web/share/js/tools.js
parent6d6630a4dd4f194b567f1ccd47144b57f6943f42 (diff)
pikvm/pikvm#616: secure text switch
Diffstat (limited to 'web/share/js/tools.js')
-rw-r--r--web/share/js/tools.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/web/share/js/tools.js b/web/share/js/tools.js
index 31e8b9b4..59b8ba13 100644
--- a/web/share/js/tools.js
+++ b/web/share/js/tools.js
@@ -319,9 +319,18 @@ export var tools = new function() {
"getBool": (key, default_value) => !!parseInt(self.storage.get(key, (default_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);
+ "bindSimpleSwitch": function(el, key, default_value, callback=null) {
+ let value = self.storage.getBool(key, default_value);
+ el.checked = value;
+ if (callback) {
+ callback(value);
+ }
+ self.el.setOnClick(el, function() {
+ if (callback) {
+ callback(el.checked);
+ }
+ self.storage.setBool(key, el.checked);
+ }, false);
},
};
};