Przeglądaj źródła

When navigating to a fragment inside a `<details>`, open it…

…this matches browsers' native behaviour.
Calum Smith 3 miesięcy temu
rodzic
commit
d6f16be79b

+ 10 - 0
assets/javascripts/lib/util.js

@@ -353,6 +353,16 @@ $.lockScroll = function (el, fn) {
   }
 };
 
+// If `el` is inside any `<details>` elements, expand them.
+$.openDetailsAncestors = function (el) {
+  while (el) {
+    if (el.tagName === "DETAILS") {
+      el.open = true;
+    }
+    el = el.parentElement;
+  }
+}
+
 let smoothScroll =
   (smoothStart =
   smoothEnd =

+ 1 - 0
assets/javascripts/views/content/content.js

@@ -114,6 +114,7 @@ app.views.Content = class Content extends app.View {
       $.scrollToWithImageLock(el, this.scrollEl, "top", {
         margin: this.scrollEl === this.el ? 0 : $.offset(this.el).top,
       });
+      $.openDetailsAncestors(el);
       $.highlight(el, { className: "_highlight" });
     } else {
       this.scrollTo(this.scrollMap[this.routeCtx.state.id]);