about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-04-11 20:28:49 -0700
committerGitHub <noreply@github.com>2023-04-11 20:28:49 -0700
commitd22b019dbf1f0dce715a19e48982beeaa37eadf9 (patch)
tree2e7ec99493254eb3b7df84f0d14df1130009281b /src/librustdoc
parente6975455d954d94248bb81f31b1e01ab36701a70 (diff)
parentdd28cfbc85160c08c57390adb50d03e755c8b425 (diff)
downloadrust-d22b019dbf1f0dce715a19e48982beeaa37eadf9.tar.gz
rust-d22b019dbf1f0dce715a19e48982beeaa37eadf9.zip
Rollup merge of #110162 - notriddle:notriddle/main-js-expand, r=GuillaumeGomez
rustdoc: remove redundant expandSection code from main.js

This functionality is already tested in `hash-item-expansion.goml`, and was implemented twice:

* First, in code that ran at load time and at hash change: 917cdd295d2eed213c135d6f984c650f016ee3d6

* Later, the hash change event handler was itself run at load time, and the code handling both cases diverged in implementation, though their behavior still matches pretty well: f66a331335f3ac931afabca6f927a9d7dc17db3e
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/html/static/js/main.js19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 56ee4c1510e..a6655663b82 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -331,10 +331,6 @@ function preLoadCss(cssUrl) {
         },
     };
 
-    function getPageId() {
-        return window.location.hash.replace(/^#/, "");
-    }
-
     const toggleAllDocsId = "toggle-all-docs";
     let savedHash = "";
 
@@ -355,12 +351,12 @@ function preLoadCss(cssUrl) {
             }
         }
         // 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;
+        const pageId = window.location.hash.replace(/^#/, "");
+        if (savedHash !== pageId) {
+            savedHash = pageId;
+            if (pageId !== "") {
+                expandSection(pageId);
             }
-            expandSection(savedHash.slice(1)); // we remove the '#'
         }
     }
 
@@ -699,11 +695,6 @@ function preLoadCss(cssUrl) {
             }
 
         });
-
-        const pageId = getPageId();
-        if (pageId !== "") {
-            expandSection(pageId);
-        }
     }());
 
     window.rustdoc_add_line_numbers_to_examples = () => {