Spaces:
Sleeping
Sleeping
User commited on
Commit ·
a86a01f
1
Parent(s): e7b6f84
Deploy static theme toggle script
Browse files
TaskTrackingSystem.WebApp/Components/App.razor
CHANGED
|
@@ -325,6 +325,7 @@
|
|
| 325 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 326 |
<link rel="stylesheet" href="TaskTrackingSystem.WebApp.styles.css" />
|
| 327 |
<link rel="stylesheet" href="app.css" />
|
|
|
|
| 328 |
<script src="https://code.highcharts.com/highcharts.js"></script>
|
| 329 |
<script src="https://code.highcharts.com/gantt/modules/gantt.js"></script>
|
| 330 |
<script src="https://unpkg.com/lucide@latest"></script>
|
|
|
|
| 325 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 326 |
<link rel="stylesheet" href="TaskTrackingSystem.WebApp.styles.css" />
|
| 327 |
<link rel="stylesheet" href="app.css" />
|
| 328 |
+
<script src="theme-toggle.js?v=20260720-2" defer></script>
|
| 329 |
<script src="https://code.highcharts.com/highcharts.js"></script>
|
| 330 |
<script src="https://code.highcharts.com/gantt/modules/gantt.js"></script>
|
| 331 |
<script src="https://unpkg.com/lucide@latest"></script>
|
TaskTrackingSystem.WebApp/Components/Partial/ThemeToggle.razor
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
<button type="button"
|
| 2 |
class="control-button"
|
| 3 |
data-theme-toggle
|
| 4 |
-
onclick="return window.toggleTaskifyThemeButton && window.toggleTaskifyThemeButton(this);"
|
| 5 |
title="Switch to dark mode"
|
| 6 |
aria-label="Switch to dark mode"
|
| 7 |
aria-pressed="false">
|
|
|
|
| 1 |
<button type="button"
|
| 2 |
class="control-button"
|
| 3 |
data-theme-toggle
|
|
|
|
| 4 |
title="Switch to dark mode"
|
| 5 |
aria-label="Switch to dark mode"
|
| 6 |
aria-pressed="false">
|
TaskTrackingSystem.WebApp/wwwroot/theme-toggle.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function () {
|
| 2 |
+
const storageKey = "tts-theme";
|
| 3 |
+
|
| 4 |
+
function normalize(theme) {
|
| 5 |
+
return theme === "dark" || theme === "light" ? theme : "light";
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
function currentTheme() {
|
| 9 |
+
return normalize(
|
| 10 |
+
document.documentElement.dataset.theme ||
|
| 11 |
+
(document.documentElement.classList.contains("dark") ? "dark" : "light")
|
| 12 |
+
);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function setTheme(theme) {
|
| 16 |
+
const normalized = normalize(theme);
|
| 17 |
+
const isDark = normalized === "dark";
|
| 18 |
+
const root = document.documentElement;
|
| 19 |
+
|
| 20 |
+
root.classList.toggle("dark", isDark);
|
| 21 |
+
root.dataset.theme = normalized;
|
| 22 |
+
|
| 23 |
+
if (document.body) {
|
| 24 |
+
document.body.classList.toggle("dark", isDark);
|
| 25 |
+
document.body.dataset.theme = normalized;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
try {
|
| 29 |
+
localStorage.setItem(storageKey, normalized);
|
| 30 |
+
} catch {
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
updateControls();
|
| 34 |
+
return isDark;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function updateControls() {
|
| 38 |
+
const isDark = currentTheme() === "dark";
|
| 39 |
+
const title = isDark ? "Switch to light mode" : "Switch to dark mode";
|
| 40 |
+
const iconName = isDark ? "sun" : "moon";
|
| 41 |
+
|
| 42 |
+
document.querySelectorAll("[data-theme-toggle]").forEach(button => {
|
| 43 |
+
button.setAttribute("aria-pressed", String(isDark));
|
| 44 |
+
button.setAttribute("aria-label", title);
|
| 45 |
+
button.setAttribute("title", title);
|
| 46 |
+
|
| 47 |
+
const icon = button.querySelector("[data-lucide]");
|
| 48 |
+
if (icon) {
|
| 49 |
+
icon.setAttribute("data-lucide", iconName);
|
| 50 |
+
}
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
if (window.lucide) {
|
| 54 |
+
window.lucide.createIcons();
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function initTheme() {
|
| 59 |
+
let storedTheme = "light";
|
| 60 |
+
try {
|
| 61 |
+
storedTheme = normalize(localStorage.getItem(storageKey));
|
| 62 |
+
} catch {
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
setTheme(storedTheme);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
window.themePreference = {
|
| 69 |
+
apply: setTheme,
|
| 70 |
+
init: initTheme,
|
| 71 |
+
toggle() {
|
| 72 |
+
return setTheme(currentTheme() === "dark" ? "light" : "dark");
|
| 73 |
+
}
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
window.updateTaskifyThemeControls = updateControls;
|
| 77 |
+
window.toggleTaskifyThemeButton = function () {
|
| 78 |
+
window.themePreference.toggle();
|
| 79 |
+
return false;
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
if (!window.__taskifyThemeToggleBound) {
|
| 83 |
+
window.__taskifyThemeToggleBound = true;
|
| 84 |
+
document.addEventListener("click", event => {
|
| 85 |
+
const target = event.target instanceof Element ? event.target : event.target?.parentElement;
|
| 86 |
+
const button = target?.closest("[data-theme-toggle]");
|
| 87 |
+
if (!button) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
event.preventDefault();
|
| 92 |
+
event.stopPropagation();
|
| 93 |
+
window.themePreference.toggle();
|
| 94 |
+
}, true);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
if (document.readyState === "loading") {
|
| 98 |
+
document.addEventListener("DOMContentLoaded", initTheme, { once: true });
|
| 99 |
+
} else {
|
| 100 |
+
initTheme();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
window.addEventListener("pageshow", updateControls);
|
| 104 |
+
})();
|