-// From rust:
-/* global ALIASES, currentCrate, rootPath */
-
// Local js definitions:
-/* global addClass, getCurrentValue, hasClass */
-/* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
+/* global addClass, getSettingValue, hasClass */
+/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
/* global hideThemeButtonState, showThemeButtonState */
if (!String.prototype.startsWith) {
};
}
+(function () {
+ var rustdocVars = document.getElementById("rustdoc-vars");
+ if (rustdocVars) {
+ window.rootPath = rustdocVars.attributes["data-root-path"].value;
+ window.currentCrate = rustdocVars.attributes["data-current-crate"].value;
+ }
+ var 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,
+ };
+ }
+}());
// Gets the human-readable string for the virtual-key code of the
// given KeyboardEvent, ev.
return document.getElementById("theme-picker");
}
+// Returns the current URL without any query parameter or hash.
+function getNakedUrl() {
+ return window.location.href.split("?")[0].split("#")[0];
+}
+
// Sets the focus on the search bar at the top of the page
function focusSearchBar() {
getSearchInput().focus();
hideSearchResults(search);
var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
if (browserSupportsHistoryApi()) {
- history.replaceState(hash, "", "?search=#" + hash);
+ // `window.location.search`` contains all the query parameters, not just `search`.
+ history.replaceState(hash, "",
+ getNakedUrl() + window.location.search + "#" + hash);
}
elem = document.getElementById(hash);
if (elem) {
var i, match,
url = document.location.href,
stripped = "",
- len = rootPath.match(/\.\.\//g).length + 1;
+ len = window.rootPath.match(/\.\.\//g).length + 1;
for (i = 0; i < len; ++i) {
match = url.match(/\/[^\/]*$/);
if (type === "mod") {
displayPath = path + "::";
- href = rootPath + path.replace(/::/g, "/") + "/" +
+ href = window.rootPath + path.replace(/::/g, "/") + "/" +
name + "/index.html";
} else if (type === "primitive" || type === "keyword") {
displayPath = "";
- href = rootPath + path.replace(/::/g, "/") +
+ href = window.rootPath + path.replace(/::/g, "/") +
"/" + type + "." + name + ".html";
} else if (type === "externcrate") {
displayPath = "";
- href = rootPath + name + "/index.html";
+ href = window.rootPath + name + "/index.html";
} else if (item.parent !== undefined) {
var myparent = item.parent;
var anchor = "#" + type + "." + name;
} else {
displayPath = path + "::" + myparent.name + "::";
}
- href = rootPath + path.replace(/::/g, "/") +
+ href = window.rootPath + path.replace(/::/g, "/") +
"/" + pageType +
"." + pageName +
".html" + anchor;
} else {
displayPath = item.path + "::";
- href = rootPath + item.path.replace(/::/g, "/") +
+ href = window.rootPath + item.path.replace(/::/g, "/") +
"/" + type + "." + name + ".html";
}
return [displayPath, href];
var ret_in_args = addTab(results.in_args, query, false);
var ret_returned = addTab(results.returned, query, false);
+ // Navigate to the relevant tab if the current tab is empty, like in case users search
+ // for "-> String". If they had selected another tab previously, they have to click on
+ // it again.
+ if ((currentTab === 0 && ret_others[1] === 0) ||
+ (currentTab === 1 && ret_in_args[1] === 0) ||
+ (currentTab === 2 && ret_returned[1] === 0)) {
+ if (ret_others[1] !== 0) {
+ currentTab = 0;
+ } else if (ret_in_args[1] !== 0) {
+ currentTab = 1;
+ } else if (ret_returned[1] !== 0) {
+ currentTab = 2;
+ }
+ }
+
var output = "<h1>Results for " + escape(query.query) +
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
"<div id=\"titles\">" +
// Because searching is incremental by character, only the most
// recent search query is added to the browser history.
if (browserSupportsHistoryApi()) {
+ var newURL = getNakedUrl() + "?search=" + encodeURIComponent(query.raw) +
+ window.location.hash;
if (!history.state && !params.search) {
- history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
+ history.pushState(query, "", newURL);
} else {
- history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
+ history.replaceState(query, "", newURL);
}
}
clearInputTimeout();
if (search_input.value.length === 0) {
if (browserSupportsHistoryApi()) {
- history.replaceState("", window.currentCrate + " - Rust", "?search=");
+ history.replaceState("", window.currentCrate + " - Rust",
+ getNakedUrl() + window.location.hash);
}
hideSearchResults();
} else {
startSearch();
// Draw a convenient sidebar of known crates if we have a listing
- if (rootPath === "../" || rootPath === "./") {
+ if (window.rootPath === "../" || window.rootPath === "./") {
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
if (sidebar) {
var div = document.createElement("div");
crates.sort();
for (var i = 0; i < crates.length; ++i) {
var klass = "crate";
- if (rootPath !== "./" && crates[i] === window.currentCrate) {
+ if (window.rootPath !== "./" && crates[i] === window.currentCrate) {
klass += " current";
}
var link = document.createElement("a");
- link.href = rootPath + crates[i] + "/index.html";
+ link.href = window.rootPath + crates[i] + "/index.html";
// The summary in the search index has HTML, so we need to
// dynamically render it as plaintext.
link.title = convertHTMLToPlaintext(rawSearchIndex[crates[i]].doc);
var libs = Object.getOwnPropertyNames(imp);
for (var i = 0, llength = libs.length; i < llength; ++i) {
- if (libs[i] === currentCrate) { continue; }
+ if (libs[i] === window.currentCrate) { continue; }
var structs = imp[libs[i]];
struct_loop:
var href = elem.getAttribute("href");
if (href && href.indexOf("http") !== 0) {
- elem.setAttribute("href", rootPath + href);
+ elem.setAttribute("href", window.rootPath + href);
}
});
}
}
- function toggleAllDocs(pageId, fromAutoCollapse) {
+ function toggleAllDocs(fromAutoCollapse) {
var innerToggle = document.getElementById(toggleAllDocsId);
if (!innerToggle) {
return;
}
if (!parent || !superParent || superParent.id !== "main" ||
hasClass(parent, "impl") === false) {
- collapseDocs(e, "hide", pageId);
+ collapseDocs(e, "hide");
}
});
}
}
}
- function collapseDocs(toggle, mode, pageId) {
+ function collapseDocs(toggle, mode) {
if (!toggle || !toggle.parentNode) {
return;
}
}
}
- function collapser(pageId, e, collapse) {
+ function collapser(e, collapse) {
// inherent impl ids are like "impl" or impl-<number>'.
// they will never be hidden by default.
var n = e.parentElement;
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (collapse || hasClass(n, "impl")) {
- collapseDocs(e, "hide", pageId);
+ collapseDocs(e, "hide");
}
}
}
- function autoCollapse(pageId, collapse) {
+ function autoCollapse(collapse) {
if (collapse) {
- toggleAllDocs(pageId, true);
+ toggleAllDocs(true);
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");
if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
- collapser(pageId, e, collapse);
+ collapser(e, collapse);
});
}
if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
- collapser(pageId, e, collapse);
+ collapser(e, collapse);
});
}
}
var toggle = createSimpleToggle(false);
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
- var pageId = getPageId();
var func = function(e) {
var next = e.nextElementSibling;
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
if (hideMethodDocs === true && hasClass(e, "method") === true) {
- collapseDocs(newToggle, "hide", pageId);
+ collapseDocs(newToggle, "hide");
}
}
};
// In case the option "auto-collapse implementors" is not set to false, we collapse
// all implementors.
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
- collapseDocs(newToggle, "hide", pageId);
+ collapseDocs(newToggle, "hide");
}
}
};
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (hasClass(e, "impl") === true) {
- collapseDocs(newToggle, "hide", pageId);
+ collapseDocs(newToggle, "hide");
}
}
};
}
onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
onEachLazy(e.getElementsByClassName("associatedconstant"), func);
- var hiddenElems = e.getElementsByClassName("hidden");
- var needToggle = false;
-
- var needToggle = onEachLazy(e.getElementsByClassName("hidden"), function(hiddenElem) {
- if (hasClass(hiddenElem, "content") === false &&
- hasClass(hiddenElem, "docblock") === false) {
- return true;
- }
+ // We transform the DOM iterator into a vec of DOM elements to prevent performance
+ // issues on webkit browsers.
+ var hiddenElems = Array.prototype.slice.call(e.getElementsByClassName("hidden"));
+ var needToggle = hiddenElems.some(function(hiddenElem) {
+ return hasClass(hiddenElem, "content") === false &&
+ hasClass(hiddenElem, "docblock") === false;
});
if (needToggle === true) {
var inner_toggle = newToggle.cloneNode(true);
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
- var pageId = getPageId();
- autoCollapse(pageId, getSettingValue("collapse") === "true");
+ autoCollapse(getSettingValue("collapse") === "true");
+ var pageId = getPageId();
if (pageId !== null) {
expandSection(pageId);
}
if (search_input.value !== "" && hasClass(search, "hidden")) {
showSearchResults(search);
if (browserSupportsHistoryApi()) {
- history.replaceState(search_input.value,
- "",
- "?search=" + encodeURIComponent(search_input.value));
+ var extra = "?search=" + encodeURIComponent(search_input.value);
+ history.replaceState(search_input.value, "",
+ getNakedUrl() + extra + window.location.hash);
}
document.title = searchTitle;
}