-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
68 lines (58 loc) · 1.61 KB
/
scripts.js
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
57
58
59
60
61
62
63
64
65
66
67
68
// menu button
const menu = document.getElementById("menu");
// menu popup
const menuContent = document.getElementById("menu-content");
// options submenus
const submenus = document.getElementsByClassName("has-items");
const anchors = document.getElementsByClassName("menuAnchor");
// state of menu / open or closed
let menuFocused = false;
// close menu if click outside of the popup
function hideMenus(event) {
if (!menuContent.contains(event.target) && !menu.contains(event.target)) {
menuFocused = false;
return document
.getElementById("menu-content")
.classList.remove("popup-animation");
}
if (menu.contains(event.target) && !menuFocused) {
menuFocused = false;
return document
.getElementById("menu-content")
.classList.remove("popup-animation");
}
for (const elem of submenus) {
if (!elem.contains(event.target)) {
elem.classList.remove("active");
elem.children[1].classList.remove("showSubMenu");
}
}
}
for (const anchor of anchors) {
anchor.addEventListener("click", (event) => {
menuFocused = false;
return document
.getElementById("menu-content")
.classList.remove("popup-animation");
})
}
menu.addEventListener("click", () => {
if (menuFocused) {
menuFocused = false;
return document
.getElementById("menu-content")
.classList.remove("popup-animation");
}
if (!menuFocused) {
menuFocused = true;
return document
.getElementById("menu-content")
.classList.add("popup-animation");
}
});
for (const elem of submenus) {
elem.addEventListener("click", () => {
elem.classList.add("active");
elem.children[1].classList.add("showSubMenu");
});
}