split javascript file into multiple

This commit is contained in:
2026-09-21 21:25:31 +02:00
parent b09f2029ed
commit cc91f7d4ff
17 changed files with 473 additions and 461 deletions
+22
View File
@@ -0,0 +1,22 @@
import { getCookie, setCookie } from "../core/cookies.js";
const THEME_MAX_AGE = 60 * 60 * 24 * 7;
// Wires a dark-mode toggle and keeps the other toggles (sidebar / mobile bar) in sync.
export function setupThemeToggle(toggleId, otherToggleIds) {
const toggle = document.getElementById(toggleId);
const otherToggles = otherToggleIds.map(id => document.getElementById(id));
toggle.addEventListener("change", () => {
document.documentElement.classList.toggle("dark", toggle.checked);
setCookie("theme", toggle.checked ? "dark" : "light", THEME_MAX_AGE);
otherToggles.forEach(other => {
other.checked = toggle.checked;
});
});
if (getCookie("theme") === "dark") {
document.documentElement.classList.add("dark");
toggle.checked = true;
}
}