-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (32 loc) · 1.03 KB
/
script.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
const Boxlayout = (() => {
const wrapper = document.body,
sections = [...document.querySelectorAll(".section")],
closeButtons = [...document.querySelectorAll(".close-section")],
expandedClass = "is-expanded",
hasExpandedClass = "has-expanded-item";
const initEvents = () => {
sections.forEach((element) => {
element.addEventListener("click", () => openSection(element));
});
closeButtons.forEach((element) => {
element.addEventListener("click", (event) => {
event.stopPropagation();
closeSection(element.parentElement);
});
});
};
const openSection = (element) => {
if (!element.classList.contains(expandedClass)) {
element.classList.add(expandedClass);
wrapper.classList.add(hasExpandedClass);
}
};
const closeSection = (element) => {
if (element.classList.contains(expandedClass)) {
element.classList.remove(expandedClass);
wrapper.classList.remove(hasExpandedClass);
}
};
return { init: initEvents };
})();
Boxlayout.init();