mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
clean up js, start adding hamburger
This commit is contained in:
parent
b8901b68d7
commit
137f5a2b05
11 changed files with 120 additions and 41 deletions
1
static/js/hamburger.js
Normal file
1
static/js/hamburger.js
Normal file
|
@ -0,0 +1 @@
|
|||
function activateHamburger() {}
|
36
static/js/lightmode.js
Normal file
36
static/js/lightmode.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const checkbox = document.getElementById("darkmode-toggle");
|
||||
const colorswitchers = document.getElementsByClassName("colorswitch");
|
||||
|
||||
function switchToLight() {
|
||||
for (let item of colorswitchers) {
|
||||
item.classList.add("light");
|
||||
}
|
||||
}
|
||||
|
||||
function switchToDark() {
|
||||
for (let item of colorswitchers) {
|
||||
console.log(item);
|
||||
item.classList.remove("light");
|
||||
}
|
||||
}
|
||||
|
||||
export function updateMode() {
|
||||
if (localStorage.getItem("light")) {
|
||||
switchToLight();
|
||||
} else {
|
||||
switchToDark();
|
||||
}
|
||||
checkbox.checked = localStorage.getItem("dark");
|
||||
checkbox.addEventListener("change", function () {
|
||||
localStorage.setItem("light", this.checked);
|
||||
if (this.checked) {
|
||||
switchToLight();
|
||||
} else {
|
||||
localStorage.removeItem("light");
|
||||
switchToDark();
|
||||
}
|
||||
});
|
||||
if (localStorage.getItem("light")) {
|
||||
checkbox.checked = true;
|
||||
}
|
||||
}
|
|
@ -1,36 +1,7 @@
|
|||
const checkbox = document.getElementById("darkmode-toggle");
|
||||
const colorswitchers = document.getElementsByClassName("colorswitch");
|
||||
|
||||
function switchToLight() {
|
||||
for (let item of colorswitchers) {
|
||||
item.classList.add("light");
|
||||
}
|
||||
}
|
||||
|
||||
function switchToDark() {
|
||||
for (let item of colorswitchers) {
|
||||
console.log(item);
|
||||
item.classList.remove("light");
|
||||
}
|
||||
}
|
||||
import { updateMode } from "./lightmode.js";
|
||||
import { activateHamburger } from "./hamburger.js";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if (localStorage.getItem("light")) {
|
||||
switchToLight();
|
||||
} else {
|
||||
switchToDark();
|
||||
}
|
||||
checkbox.checked = localStorage.getItem("dark");
|
||||
checkbox.addEventListener("change", function () {
|
||||
localStorage.setItem("light", this.checked);
|
||||
if (this.checked) {
|
||||
switchToLight();
|
||||
} else {
|
||||
localStorage.removeItem("light");
|
||||
switchToDark();
|
||||
}
|
||||
});
|
||||
if (localStorage.getItem("light")) {
|
||||
checkbox.checked = true;
|
||||
}
|
||||
updateMode();
|
||||
activateHamburger();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue