forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.client.ts
37 lines (35 loc) · 1.25 KB
/
sidebar.client.ts
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
for (const el of document.querySelectorAll("[data-accordion-trigger]")) {
el.addEventListener("click", (e) => {
e.preventDefault();
const parent = el.parentElement!;
const content = parent.querySelector("[data-accordion-content]");
const hidden = content!.classList
.toggle("hidden");
el.querySelector("svg")!.style.transform = hidden
? "rotate(90deg)"
: "rotate(180deg)";
for (const el of document.querySelectorAll("[data-accordion-content]")) {
if (el !== content) {
el.classList.add("hidden");
el.parentElement!.querySelector("svg")!.style.transform =
"rotate(90deg)";
}
}
});
}
const sidebar = document.getElementById("sidebar")!;
const sidebarOpen = document.getElementById("sidebar-open");
const sidebarClose = document.getElementById("sidebar-close");
const sidebarCover = document.getElementById("sidebar-cover")!;
sidebarOpen?.addEventListener("click", () => {
sidebar.dataset.open = "true";
sidebarCover.dataset.open = "true";
});
sidebarClose?.addEventListener("click", () => {
sidebar.dataset.open = "false";
sidebarCover.dataset.open = "false";
});
sidebarCover?.addEventListener("click", () => {
sidebar.dataset.open = "false";
sidebarCover.dataset.open = "false";
});