diff options
| author | Kazuyoshi Kato <kato.kazuyoshi@gmail.com> | 2018-08-25 03:34:04 -0700 |
|---|---|---|
| committer | Kazuyoshi Kato <kato.kazuyoshi@gmail.com> | 2018-08-25 03:36:17 -0700 |
| commit | 2c61f3ce9e82fa5eb0cb780400b8d95cd5a76571 (patch) | |
| tree | c936f7d43ed24db6785d70d4518cc2055f62367f | |
| parent | 1f441a0905700e6fa5cad76097afba52a8775435 (diff) | |
| download | rust-2c61f3ce9e82fa5eb0cb780400b8d95cd5a76571.tar.gz rust-2c61f3ce9e82fa5eb0cb780400b8d95cd5a76571.zip | |
Expand a collapsed element on onclick
Doing the expansion on onhashchange seems too late. Fixes #48726
| -rw-r--r-- | src/librustdoc/html/static/main.js | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7c0f58f4ee6..e994c85c7ec 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -224,14 +224,9 @@ } } - function expandSection() { - var hash = getPageId(); - if (hash === null) { - return; - } - - var elem = document.getElementById(hash); - if (elem && elem.offsetParent && isHidden(elem.offsetParent)) { + function expandSection(id) { + var elem = document.getElementById(id); + if (elem && isHidden(elem)) { var h3 = elem.parentNode.previousSibling; if (h3 && h3.tagName !== 'H3') { h3 = h3.previousSibling; // skip div.docblock @@ -247,13 +242,7 @@ } } - function onHashChange(ev) { - highlightSourceLines(ev); - expandSection(); - } - - highlightSourceLines(null); - window.onhashchange = onHashChange; + window.onhashchange = highlightSourceLines; // Gets the human-readable string for the virtual-key code of the // given KeyboardEvent, ev. @@ -346,6 +335,15 @@ } } + function findParentElement(elem, tagName) { + do { + if (elem && elem.tagName === tagName) { + return elem; + } + } while (elem = elem.parentNode); + return null; + } + document.onkeypress = handleShortcut; document.onkeydown = handleShortcut; document.onclick = function(ev) { @@ -383,6 +381,13 @@ } else if (!hasClass(document.getElementById("help"), "hidden")) { addClass(document.getElementById("help"), "hidden"); removeClass(document.body, "blur"); + } else { + // Making a collapsed element visible on onhashchange seems + // too late + var a = findParentElement(ev.target, 'A'); + if (a && a.hash) { + expandSection(a.hash.replace(/^#/, '')); + } } }; @@ -2242,7 +2247,7 @@ autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); if (window.location.hash && window.location.hash.length > 0) { - expandSection(); + expandSection(window.location.hash.replace(/^#/, '')); } }()); |
