diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-12-22 11:03:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-22 11:03:52 +0100 |
| commit | 793df7f5f0b517961bf638bbc29c0ec172b4c1f3 (patch) | |
| tree | a01ae7daee6a7923e5a49ee027bbdbf93226c0dc | |
| parent | d4aca6bb2486e68acd611df2334196d856e4a15b (diff) | |
| parent | 5dfa6a8922245d0587c4acf3c9b004e5875066bf (diff) | |
| download | rust-793df7f5f0b517961bf638bbc29c0ec172b4c1f3.tar.gz rust-793df7f5f0b517961bf638bbc29c0ec172b4c1f3.zip | |
Rollup merge of #106016 - notriddle:notriddle/link-has-onclick, r=GuillaumeGomez
rustdoc: simplify link anchor to section expand JS
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 3f97e4e2e39..60e4e749224 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -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 => { |
