Skip to content

Commit 793df7f

Browse files
authored
Rollup merge of #106016 - notriddle:notriddle/link-has-onclick, r=GuillaumeGomez
rustdoc: simplify link anchor to section expand JS
2 parents d4aca6b + 5dfa6a8 commit 793df7f

File tree

1 file changed

+5
-7
lines changed
  • src/librustdoc/html/static/js

1 file changed

+5
-7
lines changed

src/librustdoc/html/static/js/main.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -813,16 +813,14 @@ function loadCss(cssUrl) {
813813
hideSidebar();
814814
});
815815

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

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

0 commit comments

Comments
 (0)