From 6410767fc830b31870b464d5562d56e29f18b97a Mon Sep 17 00:00:00 2001 From: Smitty Date: Sun, 11 Apr 2021 15:42:06 -0400 Subject: [PATCH] Properly set toggles on load --- public/script.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/public/script.js b/public/script.js index 98377b9..aaaa9ef 100644 --- a/public/script.js +++ b/public/script.js @@ -416,6 +416,17 @@ function curTransitionState() { }; } +function updateActionDom(action) { + const btn = document.getElementById("action-" + action.name); + if (btn) { + if (state[action.stateBool]) { + btn.classList.add("on"); + } else { + btn.classList.remove("on"); + } + } +} + function execAction(id, slow) { const action = ACTIONS[id]; if (action.actionType === "move") { @@ -432,14 +443,7 @@ function execAction(id, slow) { } else if (action.actionType === "toggle") { state[action.stateBool] = !state[action.stateBool]; state.rendering.gridDirty = true; - const btn = document.getElementById("action-" + action.name); - if (btn) { - if (state[action.stateBool]) { - btn.classList.add("on"); - } else { - btn.classList.remove("on"); - } - } + updateActionDom(action); } stateUpdated(); } @@ -508,6 +512,7 @@ document.addEventListener("DOMContentLoaded", () => { if (btn) { btn.onclick = () => execAction(id, false); } + updateActionDom(action); }); stateUpdated(); -- 2.45.2