]> git.proxmox.com Git - rustc.git/blobdiff - src/librustdoc/html/static/js/storage.js
New upstream version 1.63.0+dfsg1
[rustc.git] / src / librustdoc / html / static / js / storage.js
index 21de7d77d64e7f60a3b449051e1758539d64e337..1c4c88344888cf28dd6c6aca00d3fcae540790d2 100644 (file)
@@ -1,10 +1,15 @@
+// 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;
@@ -100,15 +105,10 @@ function onEachLazy(lazyArray, func, reversed) {
         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
     }
 }
@@ -116,7 +116,7 @@ function updateLocalStorage(name, value) {
 function getCurrentValue(name) {
     try {
         return window.localStorage.getItem("rustdoc-" + name);
-    } catch(e) {
+    } catch (e) {
         return null;
     }
 }
@@ -168,7 +168,7 @@ function useSystemTheme(value) {
     }
 }
 
-const updateSystemTheme = (function () {
+const updateSystemTheme = (function() {
     if (!window.matchMedia) {
         // fallback to the CSS computed value
         return () => {
@@ -241,6 +241,12 @@ if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) {
     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