UNPKG

stylescape

Version:

Stylescape is a visual identity framework developed by Scape Agency.

31 lines 1.05 kB
export class DetailManager { constructor(selector = "details:not(.sidebar__accordion)") { this.details = document.querySelectorAll(selector); this.boundHandler = this.handleClick.bind(this); document.addEventListener("click", this.boundHandler); } handleClick(event) { const target = event.target; const summary = target.closest("summary"); const parent = summary?.parentElement; if (parent && parent.tagName === "DETAILS") { this.details.forEach((detail) => { if (detail !== parent) detail.removeAttribute("open"); }); } else { this.details.forEach((detail) => detail.removeAttribute("open")); } } toggle(detail, open) { if (open) detail.setAttribute("open", ""); else detail.removeAttribute("open"); } destroy() { document.removeEventListener("click", this.boundHandler); } } //# sourceMappingURL=DetailManager.js.map