Files
siphalor.de/assets/js/main.js
2021-05-05 13:48:59 +02:00

39 lines
1.0 KiB
JavaScript

(() => {
// Theme switch
const body = document.body;
const lamp = document.getElementById("mode");
const toggleTheme = (state) => {
if (state === "dark") {
localStorage.setItem("theme", "light");
body.removeAttribute("data-theme");
} else if (state === "light") {
localStorage.setItem("theme", "dark");
body.setAttribute("data-theme", "dark");
} else {
initTheme(state);
}
};
lamp.addEventListener("click", () =>
toggleTheme(localStorage.getItem("theme"))
);
// Blur the content when the menu is open
const cbox = document.getElementById("menu-trigger");
cbox.addEventListener("change", function () {
const area = document.querySelector(".wrapper");
this.checked
? area.classList.add("blurry")
: area.classList.remove("blurry");
});
// Enable keyboard steering for the navigation menu
document.getElementById("menu-icon").addEventListener("keydown", (evt) => {
if (evt.key == "Enter" || evt.key == " ") {
cbox.checked = !cbox.checked;
}
});
})();