Skip to content

Commit d6f16be

Browse files
committed
When navigating to a fragment inside a <details>, open it…
…this matches browsers' native behaviour.
1 parent dd2c3e5 commit d6f16be

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

assets/javascripts/lib/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ $.lockScroll = function (el, fn) {
353353
}
354354
};
355355

356+
// If `el` is inside any `<details>` elements, expand them.
357+
$.openDetailsAncestors = function (el) {
358+
while (el) {
359+
if (el.tagName === "DETAILS") {
360+
el.open = true;
361+
}
362+
el = el.parentElement;
363+
}
364+
}
365+
356366
let smoothScroll =
357367
(smoothStart =
358368
smoothEnd =

assets/javascripts/views/content/content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ app.views.Content = class Content extends app.View {
114114
$.scrollToWithImageLock(el, this.scrollEl, "top", {
115115
margin: this.scrollEl === this.el ? 0 : $.offset(this.el).top,
116116
});
117+
$.openDetailsAncestors(el);
117118
$.highlight(el, { className: "_highlight" });
118119
} else {
119120
this.scrollTo(this.scrollMap[this.routeCtx.state.id]);

0 commit comments

Comments
 (0)