diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index e382e5aa234..28bd1ba5247 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -89,7 +89,7 @@ function defocusSearchBar() {
"derive",
"traitalias"];
- var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
+ var disableShortcuts = getSettingValue("disable-shortcuts") === "true";
var search_input = getSearchInput();
var searchTimeout = null;
var toggleAllDocsId = "toggle-all-docs";
@@ -1580,7 +1580,7 @@ function defocusSearchBar() {
function showResults(results) {
var search = getSearchElement();
if (results.others.length === 1
- && getCurrentValue("rustdoc-go-to-only-result") === "true"
+ && getSettingValue("go-to-only-result") === "true"
// By default, the search DOM element is "empty" (meaning it has no children not
// text content). Once a search has been run, it won't be empty, even if you press
// ESC or empty the search input (which also "cancels" the search).
@@ -2296,7 +2296,7 @@ function defocusSearchBar() {
function autoCollapse(pageId, collapse) {
if (collapse) {
toggleAllDocs(pageId, true);
- } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
+ } else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");
if (impl_list !== null) {
@@ -2370,8 +2370,8 @@ function defocusSearchBar() {
}
var toggle = createSimpleToggle(false);
- var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
- var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
+ var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
+ var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var pageId = getPageId();
var func = function(e) {
@@ -2487,7 +2487,7 @@ function defocusSearchBar() {
});
}
}
- var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
+ var showItemDeclarations = getSettingValue("auto-hide-" + className);
if (showItemDeclarations === null) {
if (className === "enum" || className === "macro") {
showItemDeclarations = "false";
@@ -2495,7 +2495,7 @@ function defocusSearchBar() {
showItemDeclarations = "true";
} else {
// In case we found an unknown type, we just use the "parent" value.
- showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
+ showItemDeclarations = getSettingValue("auto-hide-declarations");
}
}
showItemDeclarations = showItemDeclarations === "false";
@@ -2569,7 +2569,7 @@ function defocusSearchBar() {
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
var pageId = getPageId();
- autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
+ autoCollapse(pageId, getSettingValue("collapse") === "true");
if (pageId !== null) {
expandSection(pageId);
@@ -2592,7 +2592,7 @@ function defocusSearchBar() {
(function() {
// To avoid checking on "rustdoc-item-attributes" value on every loop...
var itemAttributesFunc = function() {};
- if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
+ if (getSettingValue("auto-hide-attributes") !== "false") {
itemAttributesFunc = function(x) {
collapseDocs(x.previousSibling.childNodes[0], "toggle");
};
@@ -2611,7 +2611,7 @@ function defocusSearchBar() {
(function() {
// To avoid checking on "rustdoc-line-numbers" value on every loop...
var lineNumbersFunc = function() {};
- if (getCurrentValue("rustdoc-line-numbers") === "true") {
+ if (getSettingValue("line-numbers") === "true") {
lineNumbersFunc = function(x) {
var count = x.textContent.split("\n").length;
var elems = [];
@@ -2768,7 +2768,7 @@ function defocusSearchBar() {
}
return 0;
});
- var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
+ var savedCrate = getSettingValue("saved-filter-crate");
for (var i = 0; i < crates_text.length; ++i) {
var option = document.createElement("option");
option.value = crates_text[i];
diff --git a/src/librustdoc/html/static/settings.js b/src/librustdoc/html/static/settings.js
index 00a01ac30bc..da3378ccf0d 100644
--- a/src/librustdoc/html/static/settings.js
+++ b/src/librustdoc/html/static/settings.js
@@ -14,10 +14,6 @@
}
}
- function getSettingValue(settingName) {
- return getCurrentValue("rustdoc-" + settingName);
- }
-
function setEvents() {
var elems = {
toggles: document.getElementsByClassName("slider"),
diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js
index ef734f260af..179d7132057 100644
--- a/src/librustdoc/html/static/storage.js
+++ b/src/librustdoc/html/static/storage.js
@@ -1,10 +1,15 @@
// From rust:
-/* global resourcesSuffix */
+/* global resourcesSuffix, getSettingValue */
var darkThemes = ["dark", "ayu"];
var currentTheme = document.getElementById("themeStyle");
var mainTheme = document.getElementById("mainThemeStyle");
-var localStoredTheme = getCurrentValue("rustdoc-theme");
+
+function getSettingValue(settingName) {
+ return getCurrentValue('rustdoc-' + settingName);
+}
+
+var localStoredTheme = getSettingValue("theme");
var savedHref = [];
@@ -156,9 +161,9 @@ var updateSystemTheme = (function() {
function handlePreferenceChange(mql) {
// maybe the user has disabled the setting in the meantime!
- if (getCurrentValue("rustdoc-use-system-theme") !== "false") {
- var lightTheme = getCurrentValue("rustdoc-preferred-light-theme") || "light";
- var darkTheme = getCurrentValue("rustdoc-preferred-dark-theme") || "dark";
+ if (getSettingValue("use-system-theme") !== "false") {
+ var lightTheme = getSettingValue("preferred-light-theme") || "light";
+ var darkTheme = getSettingValue("preferred-dark-theme") || "dark";
if (mql.matches) {
// prefers a dark theme
@@ -181,11 +186,11 @@ var updateSystemTheme = (function() {
};
})();
-if (getCurrentValue("rustdoc-use-system-theme") !== "false" && window.matchMedia) {
+if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) {
// update the preferred dark theme if the user is already using a dark theme
// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
- if (getCurrentValue("rustdoc-use-system-theme") === null
- && getCurrentValue("rustdoc-preferred-dark-theme") === null
+ if (getSettingValue("use-system-theme") === null
+ && getSettingValue("preferred-dark-theme") === null
&& darkThemes.indexOf(localStoredTheme) >= 0) {
updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme);
}
@@ -196,7 +201,7 @@ if (getCurrentValue("rustdoc-use-system-theme") !== "false" && window.matchMedia
switchTheme(
currentTheme,
mainTheme,
- getCurrentValue("rustdoc-theme") || "light",
+ getSettingValue("theme") || "light",
false
);
}