Move themes and version into rustdoc-vars
We had been injecting the list of themes and the rustdoc version into main.js by rewriting it at doc generation time. By avoiding this rewrite, we can make it easier to edit main.js without regenerating all the docs. Added a more convenient accessor for rustdoc-vars. Changed storage.js to not rely on resourcesSuffix. It could in theory use rustdoc-vars, but because rustdoc-vars is at the end of the HTML, it's not available when storage.js runs (very early in page load).
This commit is contained in:
parent
3649b90b33
commit
f0683f98fa
5 changed files with 37 additions and 49 deletions
|
@ -37,14 +37,29 @@ if (!DOMTokenList.prototype.remove) {
|
|||
};
|
||||
}
|
||||
|
||||
(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;
|
||||
window.searchJS = rustdocVars.attributes["data-search-js"].value;
|
||||
window.searchIndexJS = rustdocVars.attributes["data-search-index-js"].value;
|
||||
// Get a value from the rustdoc-vars div, which is used to convey data from
|
||||
// Rust to the JS. If there is no such element, return null.
|
||||
function getVar(name) {
|
||||
var el = document.getElementById("rustdoc-vars");
|
||||
if (el) {
|
||||
return el.attributes["data-" + name].value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL
|
||||
// for a resource under the root-path, with the resource-suffix.
|
||||
function resourcePath(basename, extension) {
|
||||
return getVar("root-path") + basename + getVar("resource-suffix") + extension;
|
||||
}
|
||||
|
||||
|
||||
(function () {
|
||||
window.rootPath = getVar("root-path");
|
||||
window.currentCrate = getVar("current-crate");
|
||||
window.searchJS = resourcePath("search", "js");
|
||||
window.searchIndexJS = resourcePath("search-index", "js");
|
||||
var sidebarVars = document.getElementById("sidebar-vars");
|
||||
if (sidebarVars) {
|
||||
window.sidebarCurrent = {
|
||||
|
@ -115,7 +130,7 @@ function hideThemeButtonState() {
|
|||
(function () {
|
||||
var themeChoices = getThemesElement();
|
||||
var themePicker = getThemePickerElement();
|
||||
var availableThemes/* INSERT THEMES HERE */;
|
||||
var availableThemes = getVar("themes").split(",");
|
||||
|
||||
function switchThemeButtonState() {
|
||||
if (themeChoices.style.display === "block") {
|
||||
|
@ -980,7 +995,7 @@ function hideThemeButtonState() {
|
|||
var rustdoc_version = document.createElement("span");
|
||||
rustdoc_version.className = "bottom";
|
||||
var rustdoc_version_code = document.createElement("code");
|
||||
rustdoc_version_code.innerText = "/* INSERT RUSTDOC_VERSION HERE */";
|
||||
rustdoc_version_code.innerText = "rustdoc " + getVar("rustdoc-version");
|
||||
rustdoc_version.appendChild(rustdoc_version_code);
|
||||
|
||||
container.appendChild(rustdoc_version);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue