Dateien nach "as-styleguide" hochladen
This commit is contained in:
47
as-styleguide/script.js
Normal file
47
as-styleguide/script.js
Normal file
@@ -0,0 +1,47 @@
|
||||
(() => {
|
||||
const navToggle = document.querySelector("[data-nav-toggle]");
|
||||
const nav = document.querySelector("[data-nav]");
|
||||
|
||||
if (navToggle && nav) {
|
||||
navToggle.addEventListener("click", () => {
|
||||
const isOpen = nav.classList.toggle("is-open");
|
||||
navToggle.setAttribute("aria-expanded", String(isOpen));
|
||||
});
|
||||
|
||||
nav.addEventListener("click", (e) => {
|
||||
const a = e.target.closest("a");
|
||||
if (!a) return;
|
||||
nav.classList.remove("is-open");
|
||||
navToggle.setAttribute("aria-expanded", "false");
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key !== "Escape") return;
|
||||
nav.classList.remove("is-open");
|
||||
navToggle.setAttribute("aria-expanded", "false");
|
||||
});
|
||||
}
|
||||
|
||||
const accordion = document.querySelector("[data-accordion]");
|
||||
if (accordion) {
|
||||
const items = [...accordion.querySelectorAll(".accordion-item")];
|
||||
items.forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const expanded = btn.getAttribute("aria-expanded") === "true";
|
||||
items.forEach((b) => {
|
||||
b.setAttribute("aria-expanded", "false");
|
||||
const panel = b.nextElementSibling;
|
||||
if (panel && panel.classList.contains("accordion-panel")) panel.hidden = true;
|
||||
});
|
||||
if (!expanded) {
|
||||
btn.setAttribute("aria-expanded", "true");
|
||||
const panel = btn.nextElementSibling;
|
||||
if (panel && panel.classList.contains("accordion-panel")) panel.hidden = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const yearEl = document.querySelector("[data-year]");
|
||||
if (yearEl) yearEl.textContent = String(new Date().getFullYear());
|
||||
})();
|
||||
Reference in New Issue
Block a user