about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-08-09 16:58:41 +0800
committerGitHub <noreply@github.com>2018-08-09 16:58:41 +0800
commitdad5b6c554b034a5a366067a8aef31cef3772a61 (patch)
treea46cb4f2464d5080957ad36fd510bf533f5ad59c /src/librustdoc/html
parentc6f55bca7f19d9325e46678d47178447ad02732e (diff)
parentc70eb4b6eaeb0256422d32bed949b15ecc37bac9 (diff)
downloadrust-dad5b6c554b034a5a366067a8aef31cef3772a61.tar.gz
rust-dad5b6c554b034a5a366067a8aef31cef3772a61.zip
Rollup merge of #53094 - GuillaumeGomez:automatic-expand, r=nrc
Automatically expand section if url id point to one of its component

Fixes #52517.

r? @nrc
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/static/main.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 62ef5626ee5..07507047dc2 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -2208,6 +2208,25 @@
     };
 
     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) {
+                console.log(elem, elem.parentNode);
+                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");
+                    }
+                }
+            }
+        }
+    }
 }());
 
 // Sets the focus on the search bar at the top of the page