-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (56 loc) · 2.28 KB
/
script.js
File metadata and controls
56 lines (56 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const html = document.documentElement;
const body = document.body;
const menuLinks = document.querySelectorAll(".admin-menu a");
const collapseBtn = document.querySelector(".admin-menu .collapse-btn");
const toggleMobileMenu = document.querySelector(".toggle-mob-menu");
const switchInput = document.querySelector(".switch input");
const switchLabel = document.querySelector(".switch label");
const switchLabelText = switchLabel.querySelector("span:last-child");
const collapsedClass = "collapsed";
const lightModeClass = "light-mode";
/*TOGGLE HEADER STATE*/ collapseBtn.addEventListener("click", function () {
body.classList.toggle(collapsedClass);
this.getAttribute("aria-expanded") == "true"
? this.setAttribute("aria-expanded", "false")
: this.setAttribute("aria-expanded", "true");
this.getAttribute("aria-label") == "collapse menu"
? this.setAttribute("aria-label", "expand menu")
: this.setAttribute("aria-label", "collapse menu");
});
/*TOGGLE MOBILE MENU*/ toggleMobileMenu.addEventListener("click", function () {
body.classList.toggle("mob-menu-opened");
this.getAttribute("aria-expanded") == "true"
? this.setAttribute("aria-expanded", "false")
: this.setAttribute("aria-expanded", "true");
this.getAttribute("aria-label") == "open menu"
? this.setAttribute("aria-label", "close menu")
: this.setAttribute("aria-label", "open menu");
});
/*SHOW TOOLTIP ON MENU LINK HOVER*/ for (const link of menuLinks) {
link.addEventListener("mouseenter", function () {
if (
body.classList.contains(collapsedClass) &&
window.matchMedia("(min-width: 768px)").matches
) {
const tooltip = this.querySelector("span").textContent;
this.setAttribute("title", tooltip);
} else {
this.removeAttribute("title");
}
});
}
/*TOGGLE LIGHT/DARK MODE*/ if (localStorage.getItem("dark-mode") === "false") {
html.classList.add(lightModeClass);
switchInput.checked = false;
switchLabelText.textContent = "Light";
}
switchInput.addEventListener("input", function () {
html.classList.toggle(lightModeClass);
if (html.classList.contains(lightModeClass)) {
switchLabelText.textContent = "Light";
localStorage.setItem("dark-mode", "false");
} else {
switchLabelText.textContent = "Dark";
localStorage.setItem("dark-mode", "true");
}
});