Move javascript files from dir source to assets
This commit is contained in:
parent
702e87ed7d
commit
fdd4b8ec05
4 changed files with 0 additions and 0 deletions
18
assets/js/theme.js
Normal file
18
assets/js/theme.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Toggle theme
|
||||
|
||||
const getTheme = window.localStorage && window.localStorage.getItem("theme");
|
||||
const themeToggle = document.querySelector(".theme-toggle");
|
||||
const isDark = getTheme === "dark";
|
||||
|
||||
if (getTheme !== null) {
|
||||
document.body.classList.toggle("dark-theme", isDark);
|
||||
}
|
||||
|
||||
themeToggle.addEventListener("click", () => {
|
||||
document.body.classList.toggle("dark-theme");
|
||||
window.localStorage &&
|
||||
window.localStorage.setItem(
|
||||
"theme",
|
||||
document.body.classList.contains("dark-theme") ? "dark" : "light",
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue