From 3499501b448f4b5596e3b04310bb86aaa7e8cb38 Mon Sep 17 00:00:00 2001 From: daudix Date: Sun, 25 Aug 2024 02:01:22 +0300 Subject: [PATCH] Close all other navbar dropdowns when different one opens (fixes #59) --- static/details.js | 18 ++++++++++++++++++ templates/partials/head.html | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 static/details.js diff --git a/static/details.js b/static/details.js new file mode 100644 index 0000000..dbdfbd2 --- /dev/null +++ b/static/details.js @@ -0,0 +1,18 @@ +document.addEventListener("DOMContentLoaded", function () { + const nav = document.getElementById("site-nav"); + const details = nav.querySelectorAll("details"); + + details.forEach((detail) => { + detail.addEventListener("toggle", () => { + if (detail.open) setTargetDetail(detail); + }); + }); + + function setTargetDetail(targetDetail) { + details.forEach((detail) => { + if (detail !== targetDetail) { + detail.open = false; + } + }); + } +}) diff --git a/templates/partials/head.html b/templates/partials/head.html index a15ff79..c2bbc88 100644 --- a/templates/partials/head.html +++ b/templates/partials/head.html @@ -100,6 +100,10 @@ {%- set scripts = scripts | concat(with=["theme-switcher.js"]) %} {%- endif %} + {%- if config.show_theme_switcher or config.languages | length > 0 %} + {%- set scripts = scripts | concat(with=["details.js"]) %} + {%- endif %} + {%- if config.extra.scripts %} {%- set scripts = scripts | concat(with=config.extra.scripts) %} {%- endif %}