Close the collapsible menu after choosing a link

Same-page anchors kept the details menu open. scrolled.js closes it on
any link click and loads only where a collapsible menu holds such links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kantarciandClaude Opus 5.5 committed 2026-10-12 16:50:23 +02:00
1 parent bb9d7c6b45
commit dd5bc16413
4 files changed
+99 -3

No files matched your search

+26 -1
View File
@@ -1,4 +1,7 @@
/**
* Das kleine Skript des Kopfbereichs: markiert die gescrollte Seite und schließt das Menü nach
* einer Wahl (initMenus, unten).
*
* Marks the page as scrolled.
*
* A header can carry a second set of colours for the scrolled page - transparent over the hero,
@@ -31,4 +34,26 @@ export function initScrolled(doc = document) {
};
}
if (!document.querySelector('#editor')) initScrolled();
/**
* Schließt das aufgeklappte Menü, sobald darin etwas gewählt wird (ADR 119).
*
* Ein Sprungziel wie #kontakt bleibt auf derselben Seite - das `details` blieb offen und lag über
* dem Ziel. Bei einem Link auf eine andere Seite stand es nach „Zurück“ (Seiten-Cache des
* Browsers) noch offen da. Ohne Skript bleibt es beim Klappen von Hand und beim Klick daneben.
*/
export function initMenus(doc = document) {
const onClick = (event) => {
const link = event.target.closest?.('.menu-burger-body a');
const menu = link?.closest('details.menu-burger');
if (menu) {
menu.open = false;
}
};
doc.addEventListener('click', onClick);
return () => doc.removeEventListener('click', onClick);
}
if (!document.querySelector('#editor')) {
initScrolled();
initMenus();
}