about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorKazuyoshi Kato <kato.kazuyoshi@gmail.com>2018-08-23 00:43:06 -0700
committerKazuyoshi Kato <kato.kazuyoshi@gmail.com>2018-08-23 00:45:43 -0700
commit917cdd295d2eed213c135d6f984c650f016ee3d6 (patch)
treee6b54d2205009812559125143e3830ec004d6032 /src/librustdoc/html
parent786ccc336dc684cdb00402e84abe4a9bc53857cf (diff)
downloadrust-917cdd295d2eed213c135d6f984c650f016ee3d6.tar.gz
rust-917cdd295d2eed213c135d6f984c650f016ee3d6.zip
Automatically expand a section even after page load
Fixes #52774
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/static/main.js48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 70782973e42..a5c93bc8230 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -223,8 +223,38 @@
             }
         }
     }
+
+    function expandSection() {
+        var hash = getPageId();
+        if (hash === null) {
+            return;
+        }
+
+        var elem = document.getElementById(hash);
+        if (elem && isHidden(elem.offsetParent)) {
+            var h3 = elem.parentNode.previousSibling;
+
+            if (h3.tagName !== 'H3') {
+                h3 = h3.previousSibling; // skip div.docblock
+            }
+
+            if (h3) {
+                var collapses = h3.getElementsByClassName("collapse-toggle");
+                if (collapses.length > 0) {
+                    // The element is not visible, we need to make it appear!
+                    collapseDocs(collapses[0], "show");
+                }
+            }
+        }
+    }
+
+    function onHashChange(ev) {
+        highlightSourceLines(ev);
+        expandSection();
+    }
+
     highlightSourceLines(null);
-    window.onhashchange = highlightSourceLines;
+    window.onhashchange = onHashChange;
 
     // Gets the human-readable string for the virtual-key code of the
     // given KeyboardEvent, ev.
@@ -2213,21 +2243,7 @@
     autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
 
     if (window.location.hash && window.location.hash.length > 0) {
-        var hash = getPageId();
-        if (hash !== null) {
-            var elem = document.getElementById(hash);
-            if (elem && elem.offsetParent === null) {
-                if (elem.parentNode && elem.parentNode.previousSibling) {
-                    var collapses = elem.parentNode
-                                        .previousSibling
-                                        .getElementsByClassName("collapse-toggle");
-                    if (collapses.length > 0) {
-                        // The element is not visible, we need to make it appear!
-                        collapseDocs(collapses[0], "show");
-                    }
-                }
-            }
-        }
+        expandSection();
     }
 }());