rustdoc: clean up storage.js
This converts a few functions to more compact versions of themselves, and moves `RUSTDOC_MOBILE_BREAKPOINT` to main.js where it's actually used.
This commit is contained in:
parent
9852980594
commit
ba3d6055ad
3 changed files with 14 additions and 30 deletions
|
@ -1538,7 +1538,7 @@ However, it's not needed with smaller screen width because the doc/code block is
|
||||||
/*
|
/*
|
||||||
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
|
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
|
||||||
If you update this line, then you also need to update the line with the same warning
|
If you update this line, then you also need to update the line with the same warning
|
||||||
in storage.js
|
in main.js
|
||||||
*/
|
*/
|
||||||
@media (max-width: 700px) {
|
@media (max-width: 700px) {
|
||||||
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
|
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
|
||||||
|
// If you update this line, then you also need to update the media query with the same
|
||||||
|
// warning in rustdoc.css
|
||||||
|
window.RUSTDOC_MOBILE_BREAKPOINT = 700;
|
||||||
|
|
||||||
// Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL
|
// 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.
|
// for a resource under the root-path, with the resource-suffix.
|
||||||
function resourcePath(basename, extension) {
|
function resourcePath(basename, extension) {
|
||||||
|
|
|
@ -8,29 +8,14 @@
|
||||||
const darkThemes = ["dark", "ayu"];
|
const darkThemes = ["dark", "ayu"];
|
||||||
window.currentTheme = document.getElementById("themeStyle");
|
window.currentTheme = document.getElementById("themeStyle");
|
||||||
|
|
||||||
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
|
|
||||||
// If you update this line, then you also need to update the media query with the same
|
|
||||||
// warning in rustdoc.css
|
|
||||||
window.RUSTDOC_MOBILE_BREAKPOINT = 700;
|
|
||||||
|
|
||||||
const settingsDataset = (function() {
|
const settingsDataset = (function() {
|
||||||
const settingsElement = document.getElementById("default-settings");
|
const settingsElement = document.getElementById("default-settings");
|
||||||
if (settingsElement === null) {
|
return settingsElement && settingsElement.dataset ? settingsElement.dataset : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const dataset = settingsElement.dataset;
|
|
||||||
if (dataset === undefined) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return dataset;
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function getSettingValue(settingName) {
|
function getSettingValue(settingName) {
|
||||||
const current = getCurrentValue(settingName);
|
const current = getCurrentValue(settingName);
|
||||||
if (current !== null) {
|
if (current === null && settingsDataset !== null) {
|
||||||
return current;
|
|
||||||
}
|
|
||||||
if (settingsDataset !== null) {
|
|
||||||
// See the comment for `default_settings.into_iter()` etc. in
|
// See the comment for `default_settings.into_iter()` etc. in
|
||||||
// `Options::from_matches` in `librustdoc/config.rs`.
|
// `Options::from_matches` in `librustdoc/config.rs`.
|
||||||
const def = settingsDataset[settingName.replace(/-/g,"_")];
|
const def = settingsDataset[settingName.replace(/-/g,"_")];
|
||||||
|
@ -38,7 +23,7 @@ function getSettingValue(settingName) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
const localStoredTheme = getSettingValue("theme");
|
const localStoredTheme = getSettingValue("theme");
|
||||||
|
@ -49,19 +34,17 @@ function hasClass(elem, className) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addClass(elem, className) {
|
function addClass(elem, className) {
|
||||||
if (!elem || !elem.classList) {
|
if (elem && elem.classList) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
elem.classList.add(className);
|
elem.classList.add(className);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
function removeClass(elem, className) {
|
function removeClass(elem, className) {
|
||||||
if (!elem || !elem.classList) {
|
if (elem && elem.classList) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
elem.classList.remove(className);
|
elem.classList.remove(className);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a callback for every element of an Array.
|
* Run a callback for every element of an Array.
|
||||||
|
@ -127,11 +110,7 @@ function getCurrentValue(name) {
|
||||||
// Rust to the JS. If there is no such element, return null.
|
// Rust to the JS. If there is no such element, return null.
|
||||||
const getVar = (function getVar(name) {
|
const getVar = (function getVar(name) {
|
||||||
const el = document.getElementById("rustdoc-vars");
|
const el = document.getElementById("rustdoc-vars");
|
||||||
if (el) {
|
return el ? el.attributes["data-" + name].value : null;
|
||||||
return el.attributes["data-" + name].value;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function switchTheme(newThemeName, saveTheme) {
|
function switchTheme(newThemeName, saveTheme) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue