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
This commit is contained in:
commit
c8a32391c7
@ -375,10 +375,7 @@ function preLoadCss(cssUrl) {
|
|||||||
|
|
||||||
function handleEscape(ev) {
|
function handleEscape(ev) {
|
||||||
searchState.clearInputTimeout();
|
searchState.clearInputTimeout();
|
||||||
switchDisplayedElement(null);
|
searchState.hideResults();
|
||||||
if (browserSupportsHistoryApi()) {
|
|
||||||
history.replaceState(null, "", getNakedUrl() + window.location.hash);
|
|
||||||
}
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
searchState.defocus();
|
searchState.defocus();
|
||||||
window.hideAllModals(true); // true = reset focus for tooltips
|
window.hideAllModals(true); // true = reset focus for tooltips
|
||||||
@ -533,9 +530,11 @@ function preLoadCss(cssUrl) {
|
|||||||
// ignored are included in the attribute `data-ignore-extern-crates`.
|
// ignored are included in the attribute `data-ignore-extern-crates`.
|
||||||
const script = document
|
const script = document
|
||||||
.querySelector("script[data-ignore-extern-crates]");
|
.querySelector("script[data-ignore-extern-crates]");
|
||||||
const ignoreExternCrates = script ? script.getAttribute("data-ignore-extern-crates") : "";
|
const ignoreExternCrates = new Set(
|
||||||
|
(script ? script.getAttribute("data-ignore-extern-crates") : "").split(",")
|
||||||
|
);
|
||||||
for (const lib of libs) {
|
for (const lib of libs) {
|
||||||
if (lib === window.currentCrate || ignoreExternCrates.indexOf(lib) !== -1) {
|
if (lib === window.currentCrate || ignoreExternCrates.has(lib)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const structs = imp[lib];
|
const structs = imp[lib];
|
||||||
|
@ -2412,10 +2412,6 @@ function initSearch(rawSearchIndex) {
|
|||||||
const searchAfter500ms = () => {
|
const searchAfter500ms = () => {
|
||||||
searchState.clearInputTimeout();
|
searchState.clearInputTimeout();
|
||||||
if (searchState.input.value.length === 0) {
|
if (searchState.input.value.length === 0) {
|
||||||
if (browserSupportsHistoryApi()) {
|
|
||||||
history.replaceState(null, window.currentCrate + " - Rust",
|
|
||||||
getNakedUrl() + window.location.hash);
|
|
||||||
}
|
|
||||||
searchState.hideResults();
|
searchState.hideResults();
|
||||||
} else {
|
} else {
|
||||||
searchState.timeout = setTimeout(search, 500);
|
searchState.timeout = setTimeout(search, 500);
|
||||||
|
@ -52,12 +52,12 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
|
|||||||
const files = document.createElement("div");
|
const files = document.createElement("div");
|
||||||
files.className = "files";
|
files.className = "files";
|
||||||
if (elem[FILES_OFFSET]) {
|
if (elem[FILES_OFFSET]) {
|
||||||
|
const w = window.location.href.split("#")[0];
|
||||||
for (const file_text of elem[FILES_OFFSET]) {
|
for (const file_text of elem[FILES_OFFSET]) {
|
||||||
const file = document.createElement("a");
|
const file = document.createElement("a");
|
||||||
file.innerText = file_text;
|
file.innerText = file_text;
|
||||||
file.href = rootPath + "src/" + fullPath + file_text + ".html";
|
file.href = rootPath + "src/" + fullPath + file_text + ".html";
|
||||||
file.addEventListener("click", closeSidebarIfMobile);
|
file.addEventListener("click", closeSidebarIfMobile);
|
||||||
const w = window.location.href.split("#")[0];
|
|
||||||
if (!hasFoundFile && w === file.href) {
|
if (!hasFoundFile && w === file.href) {
|
||||||
file.className = "selected";
|
file.className = "selected";
|
||||||
dirEntry.open = true;
|
dirEntry.open = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user