Skip to content

Commit d22b019

Browse files
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: 917cdd2 * 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: f66a331
2 parents e697545 + dd28cfb commit d22b019

File tree

1 file changed

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

1 file changed

+5
-14
lines changed

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

+5-14
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ function preLoadCss(cssUrl) {
331331
},
332332
};
333333

334-
function getPageId() {
335-
return window.location.hash.replace(/^#/, "");
336-
}
337-
338334
const toggleAllDocsId = "toggle-all-docs";
339335
let savedHash = "";
340336

@@ -355,12 +351,12 @@ function preLoadCss(cssUrl) {
355351
}
356352
}
357353
// This part is used in case an element is not visible.
358-
if (savedHash !== window.location.hash) {
359-
savedHash = window.location.hash;
360-
if (savedHash.length === 0) {
361-
return;
354+
const pageId = window.location.hash.replace(/^#/, "");
355+
if (savedHash !== pageId) {
356+
savedHash = pageId;
357+
if (pageId !== "") {
358+
expandSection(pageId);
362359
}
363-
expandSection(savedHash.slice(1)); // we remove the '#'
364360
}
365361
}
366362

@@ -699,11 +695,6 @@ function preLoadCss(cssUrl) {
699695
}
700696

701697
});
702-
703-
const pageId = getPageId();
704-
if (pageId !== "") {
705-
expandSection(pageId);
706-
}
707698
}());
708699

709700
window.rustdoc_add_line_numbers_to_examples = () => {

0 commit comments

Comments
 (0)