This repository has been archived on 2026-05-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blowfish/layouts/shortcodes/accordion.html
T
2026-01-31 20:18:41 +00:00

24 lines
681 B
HTML

{{ $id := delimit (slice "accordion" (partial "functions/uid.html" .)) "-" }}
{{ $mode := .Get "mode" | default "collapse" }}
<div id="{{ $id }}" class="space-y-2" data-accordion="{{ $mode }}">
{{- .Inner -}}
</div>
{{ if eq $mode "collapse" }}
<script>
(() => {
const root = document.getElementById("{{ $id }}");
if (!root) return;
const items = root.querySelectorAll("details[data-accordion-item]");
items.forEach((item) => {
item.addEventListener("toggle", () => {
if (!item.open) return;
items.forEach((other) => {
if (other !== item) other.removeAttribute("open");
});
});
});
})();
</script>
{{ end }}