Skip to content

Commit 5ec88f7

Browse files
committed
feat: Open details tag on hashchange event
1 parent 24c60ba commit 5ec88f7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/assets/js/app.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ $(() => {
1010
});
1111
hljs.highlightAll();
1212

13+
// Open details that is at the same level as the target of the hash
14+
window.addEventListener("hashchange", () => {
15+
const target = document.querySelector(window.location.hash);
16+
if (!target) return;
17+
18+
const siblingDetails = target
19+
.closest("div.method")
20+
?.querySelector("details");
21+
if (siblingDetails) {
22+
siblingDetails.open = true;
23+
}
24+
});
25+
1326
$("#navigation").load(`${config.rootPath}navigation.html`, () => {
1427
$(".sidebar-sticky .icon").on("click", function (e) {
1528
e.preventDefault();

0 commit comments

Comments
 (0)