summaryrefslogtreecommitdiffstats
path: root/docs/theme/ThemeSwitch.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 16:33:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 16:34:26 +0000
commitfa17ab3e15d98660ccdd505fb051ca7fa834791d (patch)
tree8dd2e06a8ca60d9ca276fe55d1504648a04756ed /docs/theme/ThemeSwitch.js
parentAdding upstream version 0.46. (diff)
downloadjinjax-fa17ab3e15d98660ccdd505fb051ca7fa834791d.tar.xz
jinjax-fa17ab3e15d98660ccdd505fb051ca7fa834791d.zip
Adding upstream version 0.47+dfsg.upstream/0.47+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'docs/theme/ThemeSwitch.js')
-rw-r--r--docs/theme/ThemeSwitch.js41
1 files changed, 0 insertions, 41 deletions
diff --git a/docs/theme/ThemeSwitch.js b/docs/theme/ThemeSwitch.js
deleted file mode 100644
index c8b2847..0000000
--- a/docs/theme/ThemeSwitch.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import { on } from "./jxui.js";
-
-const SEL_TARGET = ".cd-theme-switch";
-const STORAGE_KEY = "theme";
-
-const DARK = "dark";
-const LIGHT = "light";
-const theme = {value: getColorPreference()};
-
-reflectPreference();
-on("click", SEL_TARGET, onClick);
-// sync with system changes
-window
- .matchMedia("(prefers-color-scheme: dark)")
- .addEventListener("change", ({matches:isDark}) => {
- theme.value = isDark ? DARK : LIGHT
- setPreference()
- });
-
-function onClick (event, target) {
- if (target.matches("[disabled]")) return;
- theme.value = theme.value === LIGHT ? DARK : LIGHT;
- setPreference();
-}
-function setPreference () {
- localStorage.setItem(STORAGE_KEY, theme.value);
- reflectPreference();
-}
-function reflectPreference () {
- const value = getColorPreference ();
- if (value === DARK) {
- document.documentElement.classList.add(DARK);
- document.documentElement.classList.remove(LIGHT);
- } else {
- document.documentElement.classList.add(LIGHT);
- document.documentElement.classList.remove(DARK);
- }
-}
-function getColorPreference () {
- return localStorage.getItem(STORAGE_KEY);
-} \ No newline at end of file