Fix settings dark mode toggle double-binding and center it (#197)
CI / test (pull_request) Successful in 50s
CI / docker (pull_request) Skipped

topbar.js binds click handlers to every .dark-toggle, including the
settings one; settings.js then also wired a delegation that re-clicked
the topbar button, so each click flipped dark mode twice (net no-op).
Mark buttons as wired in topbar.js and only add a fallback handler in
settings.js when topbar.js did not run.

CSS: center the toggle horizontally under the Settings title with auto
margins, matching .settings-body padding.

Closes #197
This commit is contained in:
fen
2026-09-10 12:10:00 -05:00
parent b603b29359
commit 8042116a69
3 changed files with 19 additions and 6 deletions
+9 -5
View File
@@ -91,11 +91,15 @@
if (dt) dt.setAttribute('aria-pressed', s.dark ? 'true' : 'false');
}
sync();
// the topbar script runs before this button exists, so wire it here
// topbar.js already binds every .dark-toggle (deferred, so the settings
// button exists by then). Only wire here if it somehow did not run,
// otherwise the button would toggle twice per click and never change (#197).
var dt = document.getElementById('settings-dark-toggle');
dt.addEventListener('click', function () {
var btns = document.querySelectorAll('.topbar .dark-toggle');
if (btns.length) btns[0].click(); else document.dispatchEvent(new CustomEvent('palette-darkchange'));
});
if (dt && !dt.dataset.darkWired) {
dt.addEventListener('click', function () {
var btns = document.querySelectorAll('.topbar .dark-toggle');
if (btns.length) btns[0].click(); else document.dispatchEvent(new CustomEvent('palette-darkchange'));
});
}
document.addEventListener('palette-darkchange', sync);
})();