+// storage.js is loaded in the `<head>` of all rustdoc pages and doesn't
+// use `async` or `defer`. That means it blocks further parsing and rendering
+// of the page: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script.
+// This makes it the correct place to act on settings that affect the display of
+// the page, so we don't see major layout changes during the load of the page.
"use strict";
const darkThemes = ["dark", "ayu"];
window.currentTheme = document.getElementById("themeStyle");
window.mainTheme = document.getElementById("mainThemeStyle");
-const settingsDataset = (function () {
+const settingsDataset = (function() {
const settingsElement = document.getElementById("default-settings");
if (settingsElement === null) {
return null;
reversed);
}
-// eslint-disable-next-line no-unused-vars
-function hasOwnPropertyRustdoc(obj, property) {
- return Object.prototype.hasOwnProperty.call(obj, property);
-}
-
function updateLocalStorage(name, value) {
try {
window.localStorage.setItem("rustdoc-" + name, value);
- } catch(e) {
+ } catch (e) {
// localStorage is not accessible, do nothing
}
}
function getCurrentValue(name) {
try {
return window.localStorage.getItem("rustdoc-" + name);
- } catch(e) {
+ } catch (e) {
return null;
}
}
}
}
-const updateSystemTheme = (function () {
+const updateSystemTheme = (function() {
if (!window.matchMedia) {
// fallback to the CSS computed value
return () => {
switchToSavedTheme();
}
+if (getSettingValue("source-sidebar-show") === "true") {
+ // At this point in page load, `document.body` is not available yet.
+ // Set a class on the `<html>` element instead.
+ addClass(document.documentElement, "source-sidebar-expanded");
+}
+
// If we navigate away (for example to a settings page), and then use the back or
// forward button to get back to a page, the theme may have changed in the meantime.
// But scripts may not be re-loaded in such a case due to the bfcache