forked from Decentrala/website
[Theme] fix persist pages
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@
|
||||
<link rel="stylesheet" href="/styles/style.css">
|
||||
<link rel="stylesheet" href="/styles/404.css">
|
||||
<link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon">
|
||||
<script src="/scripts/main.js" defer></script>
|
||||
<script src="/scripts/main.js"></script>
|
||||
<title>404</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+1
-11
@@ -1,16 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="sr">
|
||||
<head>
|
||||
<script>
|
||||
(function () {
|
||||
const theme = localStorage.getItem("theme");
|
||||
const prefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
if (theme === "dark" || (!theme && prefersDark))
|
||||
document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
@@ -42,7 +32,7 @@
|
||||
<link rel="stylesheet" href="/styles/style.css" />
|
||||
<link rel="stylesheet" href="/styles/deconference.css">
|
||||
<link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon" />
|
||||
<script src="/scripts/main.js" defer></script>
|
||||
<script src="/scripts/main.js"></script>
|
||||
<title>Dekonferencija Decentrala</title>
|
||||
<link rel="alternate" hreflang="en" href="/en/deconference" />
|
||||
</head>
|
||||
|
||||
+36
-34
@@ -1,5 +1,37 @@
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
(function () {
|
||||
const theme = window.localStorage.getItem("theme");
|
||||
const prefersDark = window?.matchMedia?.("(prefers-color-scheme: dark)").matches;
|
||||
const isDark = theme === "dark" || (!theme && prefersDark);
|
||||
|
||||
if (isDark) document.documentElement.classList.add("dark");
|
||||
|
||||
// Swap images as soon as DOM is ready (script runs in <head>, imgs not parsed yet)
|
||||
if (isDark) {
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll("img[src*='-light']").forEach((img) => {
|
||||
img.src = img.src.replace("-light", "-dark");
|
||||
});
|
||||
}, { once: true });
|
||||
}
|
||||
|
||||
window.changeTheme = (toDark) => {
|
||||
if (toDark) {
|
||||
window.localStorage.setItem("theme", "dark");
|
||||
document.documentElement.classList.add("dark");
|
||||
document.querySelectorAll("img[src*='-light']").forEach((img) => {
|
||||
img.src = img.src.replace("-light", "-dark");
|
||||
});
|
||||
} else {
|
||||
window.localStorage.setItem("theme", "light");
|
||||
document.documentElement.classList.remove("dark");
|
||||
document.querySelectorAll("img[src*='-dark']").forEach((img) => {
|
||||
img.src = img.src.replace("-dark", "-light");
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
const getById = (id) => document.getElementById(id);
|
||||
const getByClass = (className) => document.getElementsByClassName(className)[0];
|
||||
|
||||
@@ -7,31 +39,11 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
const hamburger = getByClass("hamburger");
|
||||
const hamburgerIcon = hamburger?.children[0];
|
||||
const menu = document.getElementsByTagName("nav")[0];
|
||||
const imgs = document.getElementsByTagName("img");
|
||||
const main = document.getElementsByTagName("main")[0];
|
||||
const isMenuOpen = () => hamburger?.classList.contains("open");
|
||||
const theme = window.localStorage.getItem("theme");
|
||||
|
||||
/* Functions */
|
||||
|
||||
const changeToDarkTheme = () => {
|
||||
window.localStorage.setItem("theme", "dark");
|
||||
document.documentElement.classList.add("dark");
|
||||
themeBtn?.setAttribute("title", "turn the light on");
|
||||
Array.from(imgs).forEach((img) => {
|
||||
if (img.src.includes("-light")) img.src = img.src.replace("-light", "-dark");
|
||||
});
|
||||
}
|
||||
|
||||
const changeToLightTheme = () => {
|
||||
window.localStorage.setItem("theme", "light");
|
||||
document.documentElement.classList.remove("dark");
|
||||
themeBtn?.setAttribute("title", "turn the light off");
|
||||
Array.from(imgs).forEach((img) => {
|
||||
if (img.src.includes("-dark")) img.src = img.src.replace("-dark", "-light");
|
||||
});
|
||||
}
|
||||
|
||||
const closeMenu = () => {
|
||||
hamburger.classList = "hamburger closed"
|
||||
hamburgerIcon.src = hamburgerIcon.src.replace("opened", "closed");
|
||||
@@ -73,18 +85,8 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
if (themeBtn) {
|
||||
themeBtn.addEventListener("click", () => {
|
||||
const title = themeBtn.getAttribute("title") ?? "off"
|
||||
if (title.indexOf("off") !== -1) changeToDarkTheme();
|
||||
else changeToLightTheme();
|
||||
const isDark = document.documentElement.classList.contains("dark");
|
||||
changeTheme(!isDark);
|
||||
});
|
||||
}
|
||||
|
||||
/* Rest */
|
||||
|
||||
const userPerfersDark = window?.matchMedia?.("(prefers-color-scheme: dark)").matches
|
||||
if (themeBtn) {
|
||||
if (!theme && userPerfersDark) changeToDarkTheme();
|
||||
else if (theme === "light") changeToLightTheme();
|
||||
else if (!theme && !userPerfersDark) changeToDarkTheme();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script>
|
||||
(function () {
|
||||
const theme = localStorage.getItem("theme");
|
||||
const prefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
if (theme === "dark" || (!theme && prefersDark))
|
||||
document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
|
||||
+1
-11
@@ -1,16 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="sr">
|
||||
<head>
|
||||
<script>
|
||||
(function () {
|
||||
const theme = localStorage.getItem("theme");
|
||||
const prefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
if (theme === "dark" || (!theme && prefersDark))
|
||||
document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
@@ -42,7 +32,7 @@
|
||||
<link rel="stylesheet" href="/styles/style.css" />
|
||||
<!--ADDITIONAL_STYLE-->
|
||||
<link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon" />
|
||||
<script src="/scripts/main.js" defer></script>
|
||||
<script src="/scripts/main.js"></script>
|
||||
<title><!--TITLE--> Decentrala</title>
|
||||
<link rel="alternate" hreflang="en" href="/en/PAGE_NAME" />
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user