", path);
}
- // Sidebar refers to the enclosing module, not this module.
- let relpath = if it.is_mod() && parentlen != 0 { "./" } else { "" };
- write!(
- buffer,
- "
\
-
",
- name = it.name.unwrap_or(kw::Empty),
- ty = it.type_(),
- path = relpath
- );
- write!(
- buffer,
- "",
- relpath, cx.shared.resource_suffix
- );
// Closes sidebar-elems div.
buffer.write_str("");
}
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index 9bddee199c7bf..27ad91d09e064 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -475,8 +475,6 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
description: "List of crates",
keywords: BASIC_KEYWORDS,
resource_suffix: &shared.resource_suffix,
- extra_scripts: &[],
- static_extra_scripts: &[],
};
let content = format!(
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs
index 524c90e1f4d64..1971d08e5bef5 100644
--- a/src/librustdoc/html/sources.rs
+++ b/src/librustdoc/html/sources.rs
@@ -203,8 +203,6 @@ impl SourceCollector<'_, '_> {
description: &desc,
keywords: BASIC_KEYWORDS,
resource_suffix: &shared.resource_suffix,
- extra_scripts: &[&format!("source-files{}", shared.resource_suffix)],
- static_extra_scripts: &[&format!("source-script{}", shared.resource_suffix)],
};
let v = layout::render(
&shared.layout,
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 414bca850e3dc..b320db9104612 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -66,26 +66,18 @@ function showMain() {
(function() {
window.rootPath = getVar("root-path");
window.currentCrate = getVar("current-crate");
- window.searchJS = resourcePath("search", ".js");
- window.searchIndexJS = resourcePath("search-index", ".js");
- window.settingsJS = resourcePath("settings", ".js");
- const sidebarVars = document.getElementById("sidebar-vars");
- if (sidebarVars) {
- window.sidebarCurrent = {
- name: sidebarVars.attributes["data-name"].value,
- ty: sidebarVars.attributes["data-ty"].value,
- relpath: sidebarVars.attributes["data-relpath"].value,
- };
- // FIXME: It would be nicer to generate this text content directly in HTML,
- // but with the current code it's hard to get the right information in the right place.
- const mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
- const locationTitle = document.querySelector(".sidebar h2.location");
- if (mobileLocationTitle && locationTitle) {
- mobileLocationTitle.innerHTML = locationTitle.innerHTML;
- }
- }
}());
+function setMobileTopbar() {
+ // FIXME: It would be nicer to generate this text content directly in HTML,
+ // but with the current code it's hard to get the right information in the right place.
+ const mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
+ const locationTitle = document.querySelector(".sidebar h2.location");
+ if (mobileLocationTitle && locationTitle) {
+ mobileLocationTitle.innerHTML = locationTitle.innerHTML;
+ }
+}
+
// Gets the human-readable string for the virtual-key code of the
// given KeyboardEvent, ev.
//
@@ -227,7 +219,7 @@ function loadCss(cssFileName) {
// Sending request for the CSS and the JS files at the same time so it will
// hopefully be loaded when the JS will generate the settings content.
loadCss("settings");
- loadScript(window.settingsJS);
+ loadScript(resourcePath("settings", ".js"));
};
window.searchState = {
@@ -304,8 +296,8 @@ function loadCss(cssFileName) {
function loadSearch() {
if (!searchLoaded) {
searchLoaded = true;
- loadScript(window.searchJS);
- loadScript(window.searchIndexJS);
+ loadScript(resourcePath("search", ".js"));
+ loadScript(resourcePath("search-index", ".js"));
}
}
@@ -485,40 +477,11 @@ function loadCss(cssFileName) {
document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);
- // delayed sidebar rendering.
- window.initSidebarItems = items => {
- const sidebar = document.getElementsByClassName("sidebar-elems")[0];
- let others;
- const current = window.sidebarCurrent;
-
- function addSidebarCrates(crates) {
- if (!hasClass(document.body, "crate")) {
- // We only want to list crates on the crate page.
- return;
- }
- // Draw a convenient sidebar of known crates if we have a listing
- const div = document.createElement("div");
- div.className = "block crate";
- div.innerHTML = "
Crates
";
- const ul = document.createElement("ul");
- div.appendChild(ul);
-
- for (const crate of crates) {
- let klass = "crate";
- if (window.rootPath !== "./" && crate === window.currentCrate) {
- klass += " current";
- }
- const link = document.createElement("a");
- link.href = window.rootPath + crate + "/index.html";
- link.className = klass;
- link.textContent = crate;
-
- const li = document.createElement("li");
- li.appendChild(link);
- ul.appendChild(li);
- }
- others.appendChild(div);
+ function addSidebarItems() {
+ if (!window.SIDEBAR_ITEMS) {
+ return;
}
+ const sidebar = document.getElementsByClassName("sidebar-elems")[0];
/**
* Append to the sidebar a "block" of links - a heading along with a list (`
`) of items.
@@ -529,7 +492,7 @@ function loadCss(cssFileName) {
* "Modules", or "Macros".
*/
function block(shortty, id, longty) {
- const filtered = items[shortty];
+ const filtered = window.SIDEBAR_ITEMS[shortty];
if (!filtered) {
return;
}
@@ -546,17 +509,18 @@ function loadCss(cssFileName) {
const desc = item[1]; // can be null
let klass = shortty;
- if (name === current.name && shortty === current.ty) {
- klass += " current";
- }
let path;
if (shortty === "mod") {
path = name + "/index.html";
} else {
path = shortty + "." + name + ".html";
}
+ const current_page = document.location.href.split("/").pop();
+ if (path === current_page) {
+ klass += " current";
+ }
const link = document.createElement("a");
- link.href = current.relpath + path;
+ link.href = path;
link.title = desc;
link.className = klass;
link.textContent = name;
@@ -565,14 +529,10 @@ function loadCss(cssFileName) {
ul.appendChild(li);
}
div.appendChild(ul);
- others.appendChild(div);
+ sidebar.appendChild(div);
}
if (sidebar) {
- others = document.createElement("div");
- others.className = "others";
- sidebar.appendChild(others);
-
const isModule = hasClass(document.body, "mod");
if (!isModule) {
block("primitive", "primitives", "Primitive Types");
@@ -590,12 +550,8 @@ function loadCss(cssFileName) {
block("keyword", "keywords", "Keywords");
block("traitalias", "trait-aliases", "Trait Aliases");
}
-
- // `crates{version}.js` should always be loaded before this script, so we can use
- // it safely.
- addSidebarCrates(window.ALL_CRATES);
}
- };
+ }
window.register_implementors = imp => {
const implementors = document.getElementById("implementors-list");
@@ -680,6 +636,39 @@ function loadCss(cssFileName) {
window.register_implementors(window.pending_implementors);
}
+ function addSidebarCrates() {
+ if (!window.ALL_CRATES) {
+ return;
+ }
+ const sidebarElems = document.getElementsByClassName("sidebar-elems")[0];
+ if (!sidebarElems) {
+ return;
+ }
+ // Draw a convenient sidebar of known crates if we have a listing
+ const div = document.createElement("div");
+ div.className = "block crate";
+ div.innerHTML = "
Crates
";
+ const ul = document.createElement("ul");
+ div.appendChild(ul);
+
+ for (const crate of window.ALL_CRATES) {
+ let klass = "crate";
+ if (window.rootPath !== "./" && crate === window.currentCrate) {
+ klass += " current";
+ }
+ const link = document.createElement("a");
+ link.href = window.rootPath + crate + "/index.html";
+ link.className = klass;
+ link.textContent = crate;
+
+ const li = document.createElement("li");
+ li.appendChild(link);
+ ul.appendChild(li);
+ }
+ sidebarElems.appendChild(div);
+ }
+
+
function labelForToggleButton(sectionIsCollapsed) {
if (sectionIsCollapsed) {
// button will expand the section
@@ -924,6 +913,9 @@ function loadCss(cssFileName) {
buildHelperPopup = () => {};
};
+ setMobileTopbar();
+ addSidebarItems();
+ addSidebarCrates();
onHashChange(null);
window.addEventListener("hashchange", onHashChange);
searchState.setup();
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index c0b274c0a3fd3..cb1609d498340 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -1719,10 +1719,11 @@ function initSearch(rawSearchIndex) {
}
let crates = "";
- if (window.ALL_CRATES.length > 1) {
+ const crates_list = Object.keys(rawSearchIndex);
+ if (crates_list.length > 1) {
crates = " in ";
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js
index 14d8a942977d6..10f93a1c058da 100644
--- a/src/librustdoc/html/static/js/source-script.js
+++ b/src/librustdoc/html/static/js/source-script.js
@@ -9,33 +9,19 @@
(function() {
-function getCurrentFilePath() {
- const parts = window.location.pathname.split("/");
- const rootPathParts = window.rootPath.split("/");
+const rootPath = document.getElementById("rustdoc-vars").attributes["data-root-path"].value;
- for (const rootPathPart of rootPathParts) {
- if (rootPathPart === "..") {
- parts.pop();
- }
- }
- let file = window.location.pathname.substring(parts.join("/").length);
- if (file.startsWith("/")) {
- file = file.substring(1);
- }
- return file.substring(0, file.length - 5);
-}
-
-function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
+function createDirEntry(elem, parent, fullPath, hasFoundFile) {
const name = document.createElement("div");
name.className = "name";
fullPath += elem["name"] + "/";
- name.onclick = () => {
- if (hasClass(name, "expand")) {
- removeClass(name, "expand");
+ name.onclick = ev => {
+ if (hasClass(ev.target, "expand")) {
+ removeClass(ev.target, "expand");
} else {
- addClass(name, "expand");
+ addClass(ev.target, "expand");
}
};
name.innerText = elem["name"];
@@ -46,7 +32,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
folders.className = "folders";
if (elem.dirs) {
for (const dir of elem.dirs) {
- if (createDirEntry(dir, folders, fullPath, currentFile, hasFoundFile)) {
+ if (createDirEntry(dir, folders, fullPath, hasFoundFile)) {
addClass(name, "expand");
hasFoundFile = true;
}
@@ -60,8 +46,9 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
for (const file_text of elem.files) {
const file = document.createElement("a");
file.innerText = file_text;
- file.href = window.rootPath + "src/" + fullPath + file_text + ".html";
- if (!hasFoundFile && currentFile === fullPath + file_text) {
+ file.href = rootPath + "src/" + fullPath + file_text + ".html";
+ const w = window.location.href.split("#")[0];
+ if (!hasFoundFile && w === file.href) {
file.className = "selected";
addClass(name, "expand");
hasFoundFile = true;
@@ -72,7 +59,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
children.appendChild(files);
parent.appendChild(name);
parent.appendChild(children);
- return hasFoundFile && currentFile.startsWith(fullPath);
+ return hasFoundFile;
}
function toggleSidebar() {
@@ -109,9 +96,6 @@ function createSidebarToggle() {
// This function is called from "source-files.js", generated in `html/render/mod.rs`.
// eslint-disable-next-line no-unused-vars
function createSourceSidebar() {
- if (!window.rootPath.endsWith("/")) {
- window.rootPath += "/";
- }
const container = document.querySelector("nav.sidebar");
const sidebarToggle = createSidebarToggle();
@@ -125,7 +109,6 @@ function createSourceSidebar() {
container.classList.add("expanded");
}
- const currentFile = getCurrentFilePath();
let hasFoundFile = false;
const title = document.createElement("div");
@@ -135,7 +118,7 @@ function createSourceSidebar() {
Object.keys(sourcesIndex).forEach(key => {
sourcesIndex[key].name = key;
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "",
- currentFile, hasFoundFile);
+ hasFoundFile);
});
container.appendChild(sidebar);
diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html
index cd672aadd7e93..c4999e2c74fce 100644
--- a/src/librustdoc/html/templates/page.html
+++ b/src/librustdoc/html/templates/page.html
@@ -34,17 +34,18 @@
{%- endfor -%}
> {#- -#}
{#- -#}
- {#- -#}
+ {%- if page.css_class.contains("crate") -%}
+ {#- -#}
+ {%- else if page.css_class == "source" -%}
+ {#- -#}
+ {#- -#}
+ {%- else -%}
+ {#- -#}
+ {%- endif -%}
{#- -#}
- {%- for script in page.static_extra_scripts -%}
- {#- -#}
- {% endfor %}
{%- if layout.scrape_examples_extension -%}
{#- -#}
{%- endif -%}
- {%- for script in page.extra_scripts -%}
- {#- -#}
- {% endfor %}