From 67778e1ecab4747cf886e8ffcb6a11f96ccc279c Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 30 Jan 2023 22:54:06 +0100 Subject: remove: Settings.reloadSwitches() and .switch() We now just use a click event listener, and check through what's at the click location, and toggle classes as needed. --- src/app/js/settings.js | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/src/app/js/settings.js b/src/app/js/settings.js index 63b4b99..645a9ed 100644 --- a/src/app/js/settings.js +++ b/src/app/js/settings.js @@ -24,37 +24,6 @@ var Settings = { settings = {...settings, ...Settings.get()}; ipcRenderer.send("save-settings", Settings.get()); }, - reloadSwitches: () => { - let switches = document.querySelectorAll(".switch"); - - for (let i = 0; i < switches.length; i++) { - switches[i].setAttribute("onclick", `Settings.switch(${i})`); - } - }, - switch: (element, state) => { - let switches = document.querySelectorAll(".switch"); - if (switches[element]) { - element = switches[element]; - } - - let on = () => { - element.classList.add("on"); - element.classList.remove("off"); - } - - let off = () => { - element.classList.add("off"); - element.classList.remove("on"); - } - - if (state != undefined) { - if (state) {on()} else {off()} - } else { - if (element.classList.contains("on")) {off()} else {on()} - } - - Settings.reloadSwitches(); - }, get: () => { let opts = {}; let options = document.querySelectorAll(".option"); @@ -133,5 +102,11 @@ var Settings = { } } -Settings.reloadSwitches(); +document.body.addEventListener("click", (e) => { + let el = document.elementFromPoint(e.clientX, e.clientY); + if (el.classList.contains("switch") && el.tagName == "BUTTON") { + el.classList.toggle("on"); + } +}) + Settings.load(); -- cgit v1.2.3