aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2025-07-29 21:07:46 +0200
committerThomas Voss <mail@thomasvoss.com> 2025-07-29 21:07:46 +0200
commit88c51f363437ac38e5ecf1618d28852b7078ecea (patch)
tree2d8deb05a2f30e98bb63c5d34a315102ae8b3d7a /src
parent23adeec51e0960d650ea933eaeebef425ac474b8 (diff)
Scope JavaScript properly
Diffstat (limited to 'src')
-rw-r--r--src/templates/-base.html.tmpl32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/templates/-base.html.tmpl b/src/templates/-base.html.tmpl
index 46b81eb..42ec216 100644
--- a/src/templates/-base.html.tmpl
+++ b/src/templates/-base.html.tmpl
@@ -13,23 +13,25 @@
const $ = q => document.querySelector(q);
const $$ = q => document.querySelectorAll(q);
- const validate = theme =>
- ["light", "dark"].includes(theme) ? theme : "light";
- const toggle = theme =>
- theme == "light" ? "dark" : "light";
+ (() => {
+ const validate = theme =>
+ ["light", "dark"].includes(theme) ? theme : "light";
+ const toggle = theme =>
+ theme == "light" ? "dark" : "light";
- const setTheme = theme => {
- localStorage.setItem("theme", theme);
- $("html").setAttribute("data-theme", theme);
- $(`#nav-icon-theme-${theme}`).style.display = "";
- $(`#nav-icon-theme-${toggle(theme)}`).style.display = "none";
- };
+ const setTheme = theme => {
+ localStorage.setItem("theme", theme);
+ $("html").setAttribute("data-theme", theme);
+ $(`#nav-icon-theme-${theme}`).style.display = "";
+ $(`#nav-icon-theme-${toggle(theme)}`).style.display = "none";
+ };
- document.addEventListener("DOMContentLoaded", _ => {
- $("#theme-button").onclick = () =>
- setTheme(toggle(validate(localStorage.getItem("theme"))));
- setTheme(validate(localStorage.getItem("theme")));
- });
+ document.addEventListener("DOMContentLoaded", _ => {
+ $("#theme-button").onclick = () =>
+ setTheme(toggle(validate(localStorage.getItem("theme"))));
+ setTheme(validate(localStorage.getItem("theme")));
+ });
+ })();
</script>
{{ includeIfExists "header" . }}
</head>