Skip to content

Commit c8a3239

Browse files
authored
Rollup merge of #110659 - notriddle:notriddle/js-cleanup-20230421, r=GuillaumeGomez
rustdoc: clean up JS * use `Set` for ignored crates in cross-crate trait impl JS, instead of `indexOf` string manipulation * lift constant `window.location.split` code out of a loop in source code sidebar builder * remove redundant history manipulation from search page exit
2 parents 617ecd2 + 0cd3874 commit c8a3239

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,7 @@ function preLoadCss(cssUrl) {
375375

376376
function handleEscape(ev) {
377377
searchState.clearInputTimeout();
378-
switchDisplayedElement(null);
379-
if (browserSupportsHistoryApi()) {
380-
history.replaceState(null, "", getNakedUrl() + window.location.hash);
381-
}
378+
searchState.hideResults();
382379
ev.preventDefault();
383380
searchState.defocus();
384381
window.hideAllModals(true); // true = reset focus for tooltips
@@ -533,9 +530,11 @@ function preLoadCss(cssUrl) {
533530
// ignored are included in the attribute `data-ignore-extern-crates`.
534531
const script = document
535532
.querySelector("script[data-ignore-extern-crates]");
536-
const ignoreExternCrates = script ? script.getAttribute("data-ignore-extern-crates") : "";
533+
const ignoreExternCrates = new Set(
534+
(script ? script.getAttribute("data-ignore-extern-crates") : "").split(",")
535+
);
537536
for (const lib of libs) {
538-
if (lib === window.currentCrate || ignoreExternCrates.indexOf(lib) !== -1) {
537+
if (lib === window.currentCrate || ignoreExternCrates.has(lib)) {
539538
continue;
540539
}
541540
const structs = imp[lib];

src/librustdoc/html/static/js/search.js

-4
Original file line numberDiff line numberDiff line change
@@ -2412,10 +2412,6 @@ function initSearch(rawSearchIndex) {
24122412
const searchAfter500ms = () => {
24132413
searchState.clearInputTimeout();
24142414
if (searchState.input.value.length === 0) {
2415-
if (browserSupportsHistoryApi()) {
2416-
history.replaceState(null, window.currentCrate + " - Rust",
2417-
getNakedUrl() + window.location.hash);
2418-
}
24192415
searchState.hideResults();
24202416
} else {
24212417
searchState.timeout = setTimeout(search, 500);

src/librustdoc/html/static/js/source-script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
5252
const files = document.createElement("div");
5353
files.className = "files";
5454
if (elem[FILES_OFFSET]) {
55+
const w = window.location.href.split("#")[0];
5556
for (const file_text of elem[FILES_OFFSET]) {
5657
const file = document.createElement("a");
5758
file.innerText = file_text;
5859
file.href = rootPath + "src/" + fullPath + file_text + ".html";
5960
file.addEventListener("click", closeSidebarIfMobile);
60-
const w = window.location.href.split("#")[0];
6161
if (!hasFoundFile && w === file.href) {
6262
file.className = "selected";
6363
dirEntry.open = true;

0 commit comments

Comments
 (0)