Skip to content

Commit 917cdd2

Browse files
committed
Automatically expand a section even after page load
Fixes rust-lang#52774
1 parent 786ccc3 commit 917cdd2

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/librustdoc/html/static/main.js

+32-16
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,38 @@
223223
}
224224
}
225225
}
226+
227+
function expandSection() {
228+
var hash = getPageId();
229+
if (hash === null) {
230+
return;
231+
}
232+
233+
var elem = document.getElementById(hash);
234+
if (elem && isHidden(elem.offsetParent)) {
235+
var h3 = elem.parentNode.previousSibling;
236+
237+
if (h3.tagName !== 'H3') {
238+
h3 = h3.previousSibling; // skip div.docblock
239+
}
240+
241+
if (h3) {
242+
var collapses = h3.getElementsByClassName("collapse-toggle");
243+
if (collapses.length > 0) {
244+
// The element is not visible, we need to make it appear!
245+
collapseDocs(collapses[0], "show");
246+
}
247+
}
248+
}
249+
}
250+
251+
function onHashChange(ev) {
252+
highlightSourceLines(ev);
253+
expandSection();
254+
}
255+
226256
highlightSourceLines(null);
227-
window.onhashchange = highlightSourceLines;
257+
window.onhashchange = onHashChange;
228258

229259
// Gets the human-readable string for the virtual-key code of the
230260
// given KeyboardEvent, ev.
@@ -2213,21 +2243,7 @@
22132243
autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
22142244

22152245
if (window.location.hash && window.location.hash.length > 0) {
2216-
var hash = getPageId();
2217-
if (hash !== null) {
2218-
var elem = document.getElementById(hash);
2219-
if (elem && elem.offsetParent === null) {
2220-
if (elem.parentNode && elem.parentNode.previousSibling) {
2221-
var collapses = elem.parentNode
2222-
.previousSibling
2223-
.getElementsByClassName("collapse-toggle");
2224-
if (collapses.length > 0) {
2225-
// The element is not visible, we need to make it appear!
2226-
collapseDocs(collapses[0], "show");
2227-
}
2228-
}
2229-
}
2230-
}
2246+
expandSection();
22312247
}
22322248
}());
22332249

0 commit comments

Comments
 (0)