Skip to content

Commit

Permalink
Rollup merge of #106016 - notriddle:notriddle/link-has-onclick, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

rustdoc: simplify link anchor to section expand JS
  • Loading branch information
matthiaskrgr authored Dec 22, 2022
2 parents d4aca6b + 5dfa6a8 commit 793df7f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,16 +813,14 @@ function loadCss(cssUrl) {
hideSidebar();
});

onEachLazy(document.getElementsByTagName("a"), el => {
onEachLazy(document.querySelectorAll("a[href^='#']"), el => {
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
// the height of the document so we wind up scrolled to the wrong place.
if (el.hash) {
el.addEventListener("click", () => {
expandSection(el.hash.slice(1));
hideSidebar();
});
}
el.addEventListener("click", () => {
expandSection(el.hash.slice(1));
hideSidebar();
});
});

onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => {
Expand Down

0 comments on commit 793df7f

Please sign in to comment.