feat: add light theme toggle
This commit is contained in:
1 parent
448e7a723d
commit
2fcb29e3fe
8 files changed
+132
-13
No files matched your search
@@ -8,6 +8,7 @@ const STATUS_LABEL = {
|
||||
ignore: "скрыта",
|
||||
};
|
||||
const PER_PAGE = 60;
|
||||
const THEME_KEY = "sb.theme";
|
||||
|
||||
const state = {
|
||||
view: "library",
|
||||
@@ -141,6 +142,27 @@ function applyMaintenance(open) {
|
||||
maintenanceToggle.addEventListener("click", () => applyMaintenance(!maintenanceOpen));
|
||||
applyMaintenance(maintenanceOpen);
|
||||
|
||||
const themeToggle = $("#themeToggle");
|
||||
function syncThemeButton() {
|
||||
const light = document.documentElement.dataset.theme === "light";
|
||||
themeToggle.title = light ? "Тёмная тема" : "Светлая тема";
|
||||
themeToggle.setAttribute("aria-label", themeToggle.title);
|
||||
themeToggle.setAttribute("aria-pressed", String(light));
|
||||
}
|
||||
themeToggle.addEventListener("click", () => {
|
||||
const light = document.documentElement.dataset.theme === "light";
|
||||
if (light) {
|
||||
delete document.documentElement.dataset.theme;
|
||||
} else {
|
||||
document.documentElement.dataset.theme = "light";
|
||||
}
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, light ? "dark" : "light");
|
||||
} catch (_) {}
|
||||
syncThemeButton();
|
||||
});
|
||||
syncThemeButton();
|
||||
|
||||
function esc(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
|
||||
Reference in new issue
Block a user