Rollup merge of #106016 - notriddle:notriddle/link-has-onclick, r=GuillaumeGomez

rustdoc: simplify link anchor to section expand JS
This commit is contained in:
Matthias Krüger 2022-12-22 11:03:52 +01:00 committed by GitHub
commit 793df7f5f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -813,16 +813,14 @@ function loadCss(cssUrl) {
hideSidebar(); 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 // 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 // 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. // the height of the document so we wind up scrolled to the wrong place.
if (el.hash) { el.addEventListener("click", () => {
el.addEventListener("click", () => { expandSection(el.hash.slice(1));
expandSection(el.hash.slice(1)); hideSidebar();
hideSidebar(); });
});
}
}); });
onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => { onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => {