Skip to content

Commit

Permalink
Rollup merge of #110162 - notriddle:notriddle/main-js-expand, r=Guill…
Browse files Browse the repository at this point in the history
…aumeGomez

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
  • Loading branch information
compiler-errors authored Apr 12, 2023
2 parents e697545 + dd28cfb commit d22b019
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ function preLoadCss(cssUrl) {
},
};

function getPageId() {
return window.location.hash.replace(/^#/, "");
}

const toggleAllDocsId = "toggle-all-docs";
let savedHash = "";

Expand All @@ -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 '#'
}
}

Expand Down Expand Up @@ -699,11 +695,6 @@ function preLoadCss(cssUrl) {
}

});

const pageId = getPageId();
if (pageId !== "") {
expandSection(pageId);
}
}());

window.rustdoc_add_line_numbers_to_examples = () => {
Expand Down

0 comments on commit d22b019

Please sign in to comment.