-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
No more hidden elements #66123
Merged
Merged
No more hidden elements #66123
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,17 +161,18 @@ function getSearchElement() { | |
return window.history && typeof window.history.pushState === "function"; | ||
} | ||
|
||
function isHidden(elem) { | ||
return elem.offsetHeight === 0; | ||
} | ||
|
||
var main = document.getElementById("main"); | ||
var savedHash = ""; | ||
|
||
function onHashChange(ev) { | ||
// If we're in mobile mode, we should hide the sidebar in any case. | ||
hideSidebar(); | ||
var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); | ||
if (match) { | ||
return highlightSourceLines(match, ev); | ||
} | ||
function handleHashes(ev) { | ||
var search = getSearchElement(); | ||
if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) { | ||
// This block occurs when clicking on an element in the navbar while | ||
// in a search. | ||
addClass(search, "hidden"); | ||
removeClass(main, "hidden"); | ||
var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1); | ||
|
@@ -183,6 +184,35 @@ function getSearchElement() { | |
elem.scrollIntoView(); | ||
} | ||
} | ||
// This part is used in case an element is not visible. | ||
if (savedHash !== window.location.hash) { | ||
savedHash = window.location.hash; | ||
if (savedHash.length === 0) { | ||
return; | ||
} | ||
var elem = document.getElementById(savedHash.slice(1)); // we remove the '#' | ||
if (!elem || !isHidden(elem)) { | ||
return; | ||
} | ||
var parent = elem.parentNode; | ||
if (parent && hasClass(parent, "impl-items")) { | ||
// In case this is a trait implementation item, we first need to toggle | ||
// the "Show hidden undocumented items". | ||
onEachLazy(parent.getElementsByClassName("collapsed"), function(e) { | ||
if (e.parentNode === parent) { | ||
// Only click on the toggle we're looking for. | ||
e.click(); | ||
return true; | ||
} | ||
}); | ||
if (isHidden(elem)) { | ||
// The whole parent is collapsed. We need to click on its toggle as well! | ||
if (hasClass(parent.lastElementChild, "collapse-toggle")) { | ||
parent.lastElementChild.click(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function highlightSourceLines(match, ev) { | ||
|
@@ -228,6 +258,16 @@ function getSearchElement() { | |
} | ||
} | ||
|
||
function onHashChange(ev) { | ||
// If we're in mobile mode, we should hide the sidebar in any case. | ||
hideSidebar(); | ||
var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); | ||
if (match) { | ||
return highlightSourceLines(match, ev); | ||
} | ||
handleHashes(); | ||
} | ||
|
||
function expandSection(id) { | ||
var elem = document.getElementById(id); | ||
if (elem && isHidden(elem)) { | ||
|
@@ -246,9 +286,6 @@ function getSearchElement() { | |
} | ||
} | ||
|
||
highlightSourceLines(); | ||
window.onhashchange = onHashChange; | ||
|
||
// Gets the human-readable string for the virtual-key code of the | ||
// given KeyboardEvent, ev. | ||
// | ||
|
@@ -2615,6 +2652,10 @@ function getSearchElement() { | |
insertAfter(popup, getSearchElement()); | ||
} | ||
|
||
handleHashes(); | ||
highlightSourceLines(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be more future-proof to just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took me a while to think about it but I think you're right. I updated the code. Thanks! |
||
window.onhashchange = onHashChange; | ||
|
||
buildHelperPopup(); | ||
}()); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems odd to have, there's code further down which called an
isHidden()
function you don't appear to have removed, so is this shadowing one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right! I removed the old one.