Remove inline script tags
This commit is contained in:
parent
efdb859dcd
commit
1d1ab21ad9
5 changed files with 33 additions and 23 deletions
|
@ -111,10 +111,7 @@ crate fn render<T: Print, S: Print>(
|
||||||
<section id=\"search\" class=\"content hidden\"></section>\
|
<section id=\"search\" class=\"content hidden\"></section>\
|
||||||
<section class=\"footer\"></section>\
|
<section class=\"footer\"></section>\
|
||||||
{after_content}\
|
{after_content}\
|
||||||
<script>\
|
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\"></div>
|
||||||
window.rootPath = \"{root_path}\";\
|
|
||||||
window.currentCrate = \"{krate}\";\
|
|
||||||
</script>\
|
|
||||||
<script src=\"{static_root_path}main{suffix}.js\"></script>\
|
<script src=\"{static_root_path}main{suffix}.js\"></script>\
|
||||||
{static_extra_scripts}\
|
{static_extra_scripts}\
|
||||||
{extra_scripts}\
|
{extra_scripts}\
|
||||||
|
|
|
@ -1313,6 +1313,8 @@ fn init_id_map() -> FxHashMap<String, usize> {
|
||||||
map.insert("toggle-all-docs".to_owned(), 1);
|
map.insert("toggle-all-docs".to_owned(), 1);
|
||||||
map.insert("all-types".to_owned(), 1);
|
map.insert("all-types".to_owned(), 1);
|
||||||
map.insert("default-settings".to_owned(), 1);
|
map.insert("default-settings".to_owned(), 1);
|
||||||
|
map.insert("rustdoc-vars".to_owned(), 1);
|
||||||
|
map.insert("sidebar-vars".to_owned(), 1);
|
||||||
// This is the list of IDs used by rustdoc sections.
|
// This is the list of IDs used by rustdoc sections.
|
||||||
map.insert("fields".to_owned(), 1);
|
map.insert("fields".to_owned(), 1);
|
||||||
map.insert("variants".to_owned(), 1);
|
map.insert("variants".to_owned(), 1);
|
||||||
|
|
|
@ -4216,11 +4216,8 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer, cache:
|
||||||
let relpath = if it.is_mod() { "../" } else { "" };
|
let relpath = if it.is_mod() { "../" } else { "" };
|
||||||
write!(
|
write!(
|
||||||
buffer,
|
buffer,
|
||||||
"<script>window.sidebarCurrent = {{\
|
"<div id=\"sidebar-vars\" data-name=\"{name}\" data-ty=\"{ty}\" data-relpath=\"{path}\">\
|
||||||
name: \"{name}\", \
|
</div>",
|
||||||
ty: \"{ty}\", \
|
|
||||||
relpath: \"{path}\"\
|
|
||||||
}};</script>",
|
|
||||||
name = it.name.unwrap_or(kw::Empty),
|
name = it.name.unwrap_or(kw::Empty),
|
||||||
ty = it.type_(),
|
ty = it.type_(),
|
||||||
path = relpath
|
path = relpath
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// From rust:
|
// From rust:
|
||||||
/* global ALIASES, currentCrate, rootPath */
|
/* global ALIASES */
|
||||||
|
|
||||||
// Local js definitions:
|
// Local js definitions:
|
||||||
/* global addClass, getCurrentValue, hasClass */
|
/* global addClass, getCurrentValue, hasClass */
|
||||||
|
@ -40,6 +40,21 @@ 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;
|
||||||
|
}
|
||||||
|
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
|
// Gets the human-readable string for the virtual-key code of the
|
||||||
// given KeyboardEvent, ev.
|
// given KeyboardEvent, ev.
|
||||||
|
@ -565,7 +580,7 @@ function defocusSearchBar() {
|
||||||
var i, match,
|
var i, match,
|
||||||
url = document.location.href,
|
url = document.location.href,
|
||||||
stripped = "",
|
stripped = "",
|
||||||
len = rootPath.match(/\.\.\//g).length + 1;
|
len = window.rootPath.match(/\.\.\//g).length + 1;
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
match = url.match(/\/[^\/]*$/);
|
match = url.match(/\/[^\/]*$/);
|
||||||
|
@ -1504,15 +1519,15 @@ function defocusSearchBar() {
|
||||||
|
|
||||||
if (type === "mod") {
|
if (type === "mod") {
|
||||||
displayPath = path + "::";
|
displayPath = path + "::";
|
||||||
href = rootPath + path.replace(/::/g, "/") + "/" +
|
href = window.rootPath + path.replace(/::/g, "/") + "/" +
|
||||||
name + "/index.html";
|
name + "/index.html";
|
||||||
} else if (type === "primitive" || type === "keyword") {
|
} else if (type === "primitive" || type === "keyword") {
|
||||||
displayPath = "";
|
displayPath = "";
|
||||||
href = rootPath + path.replace(/::/g, "/") +
|
href = window.rootPath + path.replace(/::/g, "/") +
|
||||||
"/" + type + "." + name + ".html";
|
"/" + type + "." + name + ".html";
|
||||||
} else if (type === "externcrate") {
|
} else if (type === "externcrate") {
|
||||||
displayPath = "";
|
displayPath = "";
|
||||||
href = rootPath + name + "/index.html";
|
href = window.rootPath + name + "/index.html";
|
||||||
} else if (item.parent !== undefined) {
|
} else if (item.parent !== undefined) {
|
||||||
var myparent = item.parent;
|
var myparent = item.parent;
|
||||||
var anchor = "#" + type + "." + name;
|
var anchor = "#" + type + "." + name;
|
||||||
|
@ -1535,13 +1550,13 @@ function defocusSearchBar() {
|
||||||
} else {
|
} else {
|
||||||
displayPath = path + "::" + myparent.name + "::";
|
displayPath = path + "::" + myparent.name + "::";
|
||||||
}
|
}
|
||||||
href = rootPath + path.replace(/::/g, "/") +
|
href = window.rootPath + path.replace(/::/g, "/") +
|
||||||
"/" + pageType +
|
"/" + pageType +
|
||||||
"." + pageName +
|
"." + pageName +
|
||||||
".html" + anchor;
|
".html" + anchor;
|
||||||
} else {
|
} else {
|
||||||
displayPath = item.path + "::";
|
displayPath = item.path + "::";
|
||||||
href = rootPath + item.path.replace(/::/g, "/") +
|
href = window.rootPath + item.path.replace(/::/g, "/") +
|
||||||
"/" + type + "." + name + ".html";
|
"/" + type + "." + name + ".html";
|
||||||
}
|
}
|
||||||
return [displayPath, href];
|
return [displayPath, href];
|
||||||
|
@ -1973,7 +1988,7 @@ function defocusSearchBar() {
|
||||||
startSearch();
|
startSearch();
|
||||||
|
|
||||||
// Draw a convenient sidebar of known crates if we have a listing
|
// 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];
|
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
|
||||||
if (sidebar) {
|
if (sidebar) {
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
|
@ -1992,11 +2007,11 @@ function defocusSearchBar() {
|
||||||
crates.sort();
|
crates.sort();
|
||||||
for (var i = 0; i < crates.length; ++i) {
|
for (var i = 0; i < crates.length; ++i) {
|
||||||
var klass = "crate";
|
var klass = "crate";
|
||||||
if (rootPath !== "./" && crates[i] === window.currentCrate) {
|
if (window.rootPath !== "./" && crates[i] === window.currentCrate) {
|
||||||
klass += " current";
|
klass += " current";
|
||||||
}
|
}
|
||||||
var link = document.createElement("a");
|
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
|
// The summary in the search index has HTML, so we need to
|
||||||
// dynamically render it as plaintext.
|
// dynamically render it as plaintext.
|
||||||
link.title = convertHTMLToPlaintext(rawSearchIndex[crates[i]].doc);
|
link.title = convertHTMLToPlaintext(rawSearchIndex[crates[i]].doc);
|
||||||
|
@ -2118,7 +2133,7 @@ function defocusSearchBar() {
|
||||||
|
|
||||||
var libs = Object.getOwnPropertyNames(imp);
|
var libs = Object.getOwnPropertyNames(imp);
|
||||||
for (var i = 0, llength = libs.length; i < llength; ++i) {
|
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]];
|
var structs = imp[libs[i]];
|
||||||
|
|
||||||
struct_loop:
|
struct_loop:
|
||||||
|
@ -2143,7 +2158,7 @@ function defocusSearchBar() {
|
||||||
var href = elem.getAttribute("href");
|
var href = elem.getAttribute("href");
|
||||||
|
|
||||||
if (href && href.indexOf("http") !== 0) {
|
if (href && href.indexOf("http") !== 0) {
|
||||||
elem.setAttribute("href", rootPath + href);
|
elem.setAttribute("href", window.rootPath + href);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -263,8 +263,7 @@ function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
|
||||||
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch"];
|
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch"];
|
||||||
|
|
||||||
ALIASES = {};
|
ALIASES = {};
|
||||||
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
|
finalJS += 'window = { "currentCrate": "' + crate + '", rootPath: "../" };\n';
|
||||||
finalJS += 'var rootPath = "../";\n';
|
|
||||||
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
|
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
|
||||||
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
|
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
|
||||||
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
|
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue