Fix some bugs reported by eslint
This commit is contained in:
parent
b814b63983
commit
042facb935
@ -1,9 +1,6 @@
|
|||||||
// From rust:
|
|
||||||
/* global ALIASES */
|
|
||||||
|
|
||||||
// Local js definitions:
|
// Local js definitions:
|
||||||
/* global addClass, getCurrentValue, hasClass */
|
/* global addClass, getSettingValue, hasClass */
|
||||||
/* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
|
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
|
||||||
/* global hideThemeButtonState, showThemeButtonState */
|
/* global hideThemeButtonState, showThemeButtonState */
|
||||||
|
|
||||||
if (!String.prototype.startsWith) {
|
if (!String.prototype.startsWith) {
|
||||||
@ -2214,7 +2211,7 @@ function defocusSearchBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleAllDocs(pageId, fromAutoCollapse) {
|
function toggleAllDocs(fromAutoCollapse) {
|
||||||
var innerToggle = document.getElementById(toggleAllDocsId);
|
var innerToggle = document.getElementById(toggleAllDocsId);
|
||||||
if (!innerToggle) {
|
if (!innerToggle) {
|
||||||
return;
|
return;
|
||||||
@ -2257,14 +2254,14 @@ function defocusSearchBar() {
|
|||||||
}
|
}
|
||||||
if (!parent || !superParent || superParent.id !== "main" ||
|
if (!parent || !superParent || superParent.id !== "main" ||
|
||||||
hasClass(parent, "impl") === false) {
|
hasClass(parent, "impl") === false) {
|
||||||
collapseDocs(e, "hide", pageId);
|
collapseDocs(e, "hide");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function collapseDocs(toggle, mode, pageId) {
|
function collapseDocs(toggle, mode) {
|
||||||
if (!toggle || !toggle.parentNode) {
|
if (!toggle || !toggle.parentNode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2384,27 +2381,27 @@ function defocusSearchBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function collapser(pageId, e, collapse) {
|
function collapser(e, collapse) {
|
||||||
// inherent impl ids are like "impl" or impl-<number>'.
|
// inherent impl ids are like "impl" or impl-<number>'.
|
||||||
// they will never be hidden by default.
|
// they will never be hidden by default.
|
||||||
var n = e.parentElement;
|
var n = e.parentElement;
|
||||||
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
|
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
|
||||||
// Automatically minimize all non-inherent impls
|
// Automatically minimize all non-inherent impls
|
||||||
if (collapse || hasClass(n, "impl")) {
|
if (collapse || hasClass(n, "impl")) {
|
||||||
collapseDocs(e, "hide", pageId);
|
collapseDocs(e, "hide");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function autoCollapse(pageId, collapse) {
|
function autoCollapse(collapse) {
|
||||||
if (collapse) {
|
if (collapse) {
|
||||||
toggleAllDocs(pageId, true);
|
toggleAllDocs(true);
|
||||||
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
|
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
|
||||||
var impl_list = document.getElementById("trait-implementations-list");
|
var impl_list = document.getElementById("trait-implementations-list");
|
||||||
|
|
||||||
if (impl_list !== null) {
|
if (impl_list !== null) {
|
||||||
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
|
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
|
||||||
collapser(pageId, e, collapse);
|
collapser(e, collapse);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2412,7 +2409,7 @@ function defocusSearchBar() {
|
|||||||
|
|
||||||
if (blanket_list !== null) {
|
if (blanket_list !== null) {
|
||||||
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
|
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
|
||||||
collapser(pageId, e, collapse);
|
collapser(e, collapse);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2475,7 +2472,6 @@ function defocusSearchBar() {
|
|||||||
var toggle = createSimpleToggle(false);
|
var toggle = createSimpleToggle(false);
|
||||||
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
|
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
|
||||||
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
|
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
|
||||||
var pageId = getPageId();
|
|
||||||
|
|
||||||
var func = function(e) {
|
var func = function(e) {
|
||||||
var next = e.nextElementSibling;
|
var next = e.nextElementSibling;
|
||||||
@ -2489,7 +2485,7 @@ function defocusSearchBar() {
|
|||||||
var newToggle = toggle.cloneNode(true);
|
var newToggle = toggle.cloneNode(true);
|
||||||
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
|
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
|
||||||
if (hideMethodDocs === true && hasClass(e, "method") === true) {
|
if (hideMethodDocs === true && hasClass(e, "method") === true) {
|
||||||
collapseDocs(newToggle, "hide", pageId);
|
collapseDocs(newToggle, "hide");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2513,7 +2509,7 @@ function defocusSearchBar() {
|
|||||||
// In case the option "auto-collapse implementors" is not set to false, we collapse
|
// In case the option "auto-collapse implementors" is not set to false, we collapse
|
||||||
// all implementors.
|
// all implementors.
|
||||||
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
|
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
|
||||||
collapseDocs(newToggle, "hide", pageId);
|
collapseDocs(newToggle, "hide");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2527,7 +2523,7 @@ function defocusSearchBar() {
|
|||||||
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
|
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
|
||||||
// Automatically minimize all non-inherent impls
|
// Automatically minimize all non-inherent impls
|
||||||
if (hasClass(e, "impl") === true) {
|
if (hasClass(e, "impl") === true) {
|
||||||
collapseDocs(newToggle, "hide", pageId);
|
collapseDocs(newToggle, "hide");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2562,14 +2558,12 @@ function defocusSearchBar() {
|
|||||||
}
|
}
|
||||||
onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
|
onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
|
||||||
onEachLazy(e.getElementsByClassName("associatedconstant"), func);
|
onEachLazy(e.getElementsByClassName("associatedconstant"), func);
|
||||||
var hiddenElems = e.getElementsByClassName("hidden");
|
// We transform the DOM iterator into a vec of DOM elements to prevent performance
|
||||||
var needToggle = false;
|
// issues on webkit browsers.
|
||||||
|
var hiddenElems = Array.prototype.slice.call(e.getElementsByClassName("hidden"));
|
||||||
var needToggle = onEachLazy(e.getElementsByClassName("hidden"), function(hiddenElem) {
|
var needToggle = hiddenElems.some(function(hiddenElem) {
|
||||||
if (hasClass(hiddenElem, "content") === false &&
|
return hasClass(hiddenElem, "content") === false &&
|
||||||
hasClass(hiddenElem, "docblock") === false) {
|
hasClass(hiddenElem, "docblock") === false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (needToggle === true) {
|
if (needToggle === true) {
|
||||||
var inner_toggle = newToggle.cloneNode(true);
|
var inner_toggle = newToggle.cloneNode(true);
|
||||||
@ -2672,10 +2666,10 @@ function defocusSearchBar() {
|
|||||||
|
|
||||||
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
||||||
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
|
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
|
||||||
|
|
||||||
|
autoCollapse(getSettingValue("collapse") === "true");
|
||||||
|
|
||||||
var pageId = getPageId();
|
var pageId = getPageId();
|
||||||
|
|
||||||
autoCollapse(pageId, getSettingValue("collapse") === "true");
|
|
||||||
|
|
||||||
if (pageId !== null) {
|
if (pageId !== null) {
|
||||||
expandSection(pageId);
|
expandSection(pageId);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Local js definitions:
|
// Local js definitions:
|
||||||
/* global getCurrentValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
|
/* global getSettingValue, getVirtualKey, onEachLazy, updateLocalStorage, updateSystemTheme */
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
function changeSetting(settingName, value) {
|
function changeSetting(settingName, value) {
|
||||||
|
@ -113,6 +113,8 @@ function createSidebarToggle() {
|
|||||||
return sidebarToggle;
|
return sidebarToggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is called from "source-files.js", generated in `html/render/mod.rs`.
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function createSourceSidebar() {
|
function createSourceSidebar() {
|
||||||
if (window.rootPath.endsWith("/") === false) {
|
if (window.rootPath.endsWith("/") === false) {
|
||||||
window.rootPath += "/";
|
window.rootPath += "/";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// From rust:
|
// From rust:
|
||||||
/* global resourcesSuffix, getSettingValue */
|
/* global resourcesSuffix */
|
||||||
|
|
||||||
var darkThemes = ["dark", "ayu"];
|
var darkThemes = ["dark", "ayu"];
|
||||||
var currentTheme = document.getElementById("themeStyle");
|
var currentTheme = document.getElementById("themeStyle");
|
||||||
@ -35,10 +35,12 @@ var localStoredTheme = getSettingValue("theme");
|
|||||||
|
|
||||||
var savedHref = [];
|
var savedHref = [];
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function hasClass(elem, className) {
|
function hasClass(elem, className) {
|
||||||
return elem && elem.classList && elem.classList.contains(className);
|
return elem && elem.classList && elem.classList.contains(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function addClass(elem, className) {
|
function addClass(elem, className) {
|
||||||
if (!elem || !elem.classList) {
|
if (!elem || !elem.classList) {
|
||||||
return;
|
return;
|
||||||
@ -46,6 +48,7 @@ function addClass(elem, className) {
|
|||||||
elem.classList.add(className);
|
elem.classList.add(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function removeClass(elem, className) {
|
function removeClass(elem, className) {
|
||||||
if (!elem || !elem.classList) {
|
if (!elem || !elem.classList) {
|
||||||
return;
|
return;
|
||||||
@ -81,6 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
|
|||||||
reversed);
|
reversed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function hasOwnProperty(obj, property) {
|
function hasOwnProperty(obj, property) {
|
||||||
return Object.prototype.hasOwnProperty.call(obj, property);
|
return Object.prototype.hasOwnProperty.call(obj, property);
|
||||||
}
|
}
|
||||||
@ -148,6 +152,8 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is called from "theme.js", generated in `html/render/mod.rs`.
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function useSystemTheme(value) {
|
function useSystemTheme(value) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
value = true;
|
value = true;
|
||||||
@ -172,7 +178,7 @@ var updateSystemTheme = (function() {
|
|||||||
switchTheme(
|
switchTheme(
|
||||||
currentTheme,
|
currentTheme,
|
||||||
mainTheme,
|
mainTheme,
|
||||||
JSON.parse(cssTheme) || light,
|
JSON.parse(cssTheme) || "light",
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user