Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db0169f34b | ||
|
|
b4a968d991 |
@@ -15,6 +15,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
/* 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) => {
|
||||
@@ -23,6 +24,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
}
|
||||
|
||||
const changeToLightTheme = () => {
|
||||
window.localStorage.setItem("theme", "light");
|
||||
document.documentElement.classList.remove("dark");
|
||||
themeBtn?.setAttribute("title", "turn the light off");
|
||||
Array.from(imgs).forEach((img) => {
|
||||
@@ -46,6 +48,27 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
window.addEventListener("resize", () => isMenuOpen() && closeMenu());
|
||||
main.addEventListener("click", () => isMenuOpen() && closeMenu());
|
||||
|
||||
/* Language persistence */
|
||||
const currentLang = document.documentElement.lang || "sr";
|
||||
const anchors = document.getElementsByTagName("a");
|
||||
Array.from(anchors).forEach((a) => {
|
||||
// Skip language switcher links
|
||||
if (a.classList.contains("lang")) return;
|
||||
const href = a.getAttribute("href");
|
||||
if (!href) return;
|
||||
if (href.startsWith("/")) {
|
||||
// Replace existing language prefix or add one
|
||||
if (href.startsWith("/sr") || href.startsWith("/en")) {
|
||||
if (!href.startsWith(`/${currentLang}`)) {
|
||||
a.setAttribute("href", `/${currentLang}${href.slice(3)}`);
|
||||
}
|
||||
} else {
|
||||
// No language prefix, prepend currentLang
|
||||
a.setAttribute("href", `/${currentLang}${href}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
hamburger?.addEventListener("click", () => isMenuOpen() ? closeMenu() : openMenu());
|
||||
|
||||
themeBtn.addEventListener("click", () => {
|
||||
|
||||
Reference in New Issue
Block a user