mirror of
https://github.com/welpo/tabi.git
synced 2026-02-16 08:07:19 +01:00
Added minified version of the new JS
This commit is contained in:
parent
9587da0139
commit
8582b16950
1 changed files with 1 additions and 1 deletions
2
static/js/themeSwitcher.min.js
vendored
2
static/js/themeSwitcher.min.js
vendored
|
|
@ -1 +1 @@
|
|||
const themeSwitcher=document.querySelector(".theme-switcher");let currentTheme=localStorage.getItem("theme")||document.documentElement.getAttribute("data-theme");function setTheme(e,t=!1){document.documentElement.setAttribute("data-theme",e);var r="dark"===(currentTheme=e)?"true":"false",r=(themeSwitcher.setAttribute("aria-pressed",r),t&&localStorage.setItem("theme",e),new CustomEvent("themeChanged",{detail:{theme:e}}));window.dispatchEvent(r)}function switchTheme(){setTheme("dark"===currentTheme?"light":"dark",!0)}themeSwitcher.addEventListener("click",switchTheme,!1),themeSwitcher.setAttribute("role","button"),themeSwitcher.setAttribute("aria-label","Toggle dark mode");let togglePressed="dark"===currentTheme?"true":"false";themeSwitcher.setAttribute("aria-pressed",togglePressed),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{setTheme(e.matches?"dark":"light")});
|
||||
// Get the theme switcher button element.const themeSwitcher = document.querySelector(".theme-switcher");// Retrieve theme from either the localStorage or the data-theme attribute on the document element.let currentTheme = localStorage.getItem("theme") || document.documentElement.getAttribute('data-theme');// Function to set themefunction setTheme(theme, saveToLocalStorage = false) { document.documentElement.setAttribute("data-theme", theme); currentTheme = theme; let togglePressed = theme === "dark" ? "true" : "false"; themeSwitcher.setAttribute("aria-pressed", togglePressed); if (saveToLocalStorage) { localStorage.setItem("theme", theme); } // Dispatch a custom event for comment systems. const event = new CustomEvent("themeChanged", { detail: { theme: theme } }); window.dispatchEvent(event);}// Function to switch between dark and light themes.function switchTheme() { // Set the new theme based on the current theme. const newTheme = currentTheme === "dark" ? "light" : "dark"; setTheme(newTheme, true); // Save the theme to localStorage when the user changes it.}// Initialize the theme switcher button.themeSwitcher.addEventListener("click", switchTheme, false);themeSwitcher.setAttribute("role", "button");let togglePressed = currentTheme === "dark" ? "true" : "false";themeSwitcher.setAttribute("aria-pressed", togglePressed);// Update the theme based on system preference if the user hasn't manually changed the theme.window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", e => { const newTheme = e.matches ? "dark" : "light"; setTheme(newTheme);});
|
||||
Loading…
Add table
Add a link
Reference in a new issue