Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically expand a section even after page load #53626

Merged
merged 3 commits into from
Aug 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,38 @@
}
}
}

function expandSection() {
var hash = getPageId();
if (hash === null) {
return;
}

var elem = document.getElementById(hash);
if (elem && isHidden(elem.offsetParent)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offsetParent can be null, please check it before calling isHidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

var h3 = elem.parentNode.previousSibling;

if (h3.tagName !== 'H3') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if h3 exists before accessing tagName.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done at 1f441a0

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.
Expand Down Expand Up @@ -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();
}
}());

Expand Down