about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/storage.js
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-03-23 14:19:50 -0700
committerMichael Howell <michael@notriddle.com>2023-03-23 14:19:50 -0700
commitba3d6055adf0a93800d79ea2281222df81b44b59 (patch)
tree8bcd44f94b9f603598f834ab0e1572c1bbb5b59f /src/librustdoc/html/static/js/storage.js
parent98529805949e66a0cfe8e02f7a1ddd496aa330fb (diff)
downloadrust-ba3d6055adf0a93800d79ea2281222df81b44b59.tar.gz
rust-ba3d6055adf0a93800d79ea2281222df81b44b59.zip
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.
Diffstat (limited to 'src/librustdoc/html/static/js/storage.js')
-rw-r--r--src/librustdoc/html/static/js/storage.js37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js
index c3fed9a72d4..aa90d9f6be9 100644
--- a/src/librustdoc/html/static/js/storage.js
+++ b/src/librustdoc/html/static/js/storage.js
@@ -8,29 +8,14 @@
 const darkThemes = ["dark", "ayu"];
 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 settingsElement = document.getElementById("default-settings");
-    if (settingsElement === null) {
-        return null;
-    }
-    const dataset = settingsElement.dataset;
-    if (dataset === undefined) {
-        return null;
-    }
-    return dataset;
+    return settingsElement && settingsElement.dataset ? settingsElement.dataset : null;
 })();
 
 function getSettingValue(settingName) {
     const current = getCurrentValue(settingName);
-    if (current !== null) {
-        return current;
-    }
-    if (settingsDataset !== null) {
+    if (current === null && settingsDataset !== null) {
         // See the comment for `default_settings.into_iter()` etc. in
         // `Options::from_matches` in `librustdoc/config.rs`.
         const def = settingsDataset[settingName.replace(/-/g,"_")];
@@ -38,7 +23,7 @@ function getSettingValue(settingName) {
             return def;
         }
     }
-    return null;
+    return current;
 }
 
 const localStoredTheme = getSettingValue("theme");
@@ -49,18 +34,16 @@ function hasClass(elem, className) {
 }
 
 function addClass(elem, className) {
-    if (!elem || !elem.classList) {
-        return;
+    if (elem && elem.classList) {
+        elem.classList.add(className);
     }
-    elem.classList.add(className);
 }
 
 // eslint-disable-next-line no-unused-vars
 function removeClass(elem, className) {
-    if (!elem || !elem.classList) {
-        return;
+    if (elem && elem.classList) {
+        elem.classList.remove(className);
     }
-    elem.classList.remove(className);
 }
 
 /**
@@ -127,11 +110,7 @@ function getCurrentValue(name) {
 // Rust to the JS. If there is no such element, return null.
 const getVar = (function getVar(name) {
     const el = document.getElementById("rustdoc-vars");
-    if (el) {
-        return el.attributes["data-" + name].value;
-    } else {
-        return null;
-    }
+    return el ? el.attributes["data-" + name].value : null;
 });
 
 function switchTheme(newThemeName, saveTheme) {