1
Fork 0

Unify storage getter and setter functions

This commit is contained in:
Guillaume Gomez 2022-01-10 14:50:16 +01:00
parent a00e130dae
commit 7efba33582
4 changed files with 12 additions and 12 deletions

View file

@ -1619,7 +1619,7 @@ window.initSearch = function(rawSearchIndex) {
} }
function updateCrate(ev) { function updateCrate(ev) {
updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value); updateLocalStorage("saved-filter-crate", ev.target.value);
// In case you "cut" the entry from the search input, then change the crate filter // In case you "cut" the entry from the search input, then change the crate filter
// before paste back the previous search, you get the old search results without // before paste back the previous search, you get the old search results without
// the filter. To prevent this, we need to remove the previous results. // the filter. To prevent this, we need to remove the previous results.

View file

@ -4,7 +4,7 @@
(function () { (function () {
function changeSetting(settingName, value) { function changeSetting(settingName, value) {
updateLocalStorage("rustdoc-" + settingName, value); updateLocalStorage(settingName, value);
switch (settingName) { switch (settingName) {
case "theme": case "theme":

View file

@ -82,11 +82,11 @@ function toggleSidebar() {
if (child.innerText === ">") { if (child.innerText === ">") {
sidebar.classList.add("expanded"); sidebar.classList.add("expanded");
child.innerText = "<"; child.innerText = "<";
updateLocalStorage("rustdoc-source-sidebar-show", "true"); updateLocalStorage("source-sidebar-show", "true");
} else { } else {
sidebar.classList.remove("expanded"); sidebar.classList.remove("expanded");
child.innerText = ">"; child.innerText = ">";
updateLocalStorage("rustdoc-source-sidebar-show", "false"); updateLocalStorage("source-sidebar-show", "false");
} }
} }
@ -97,7 +97,7 @@ function createSidebarToggle() {
var inner = document.createElement("div"); var inner = document.createElement("div");
if (getCurrentValue("rustdoc-source-sidebar-show") === "true") { if (getCurrentValue("source-sidebar-show") === "true") {
inner.innerText = "<"; inner.innerText = "<";
} else { } else {
inner.innerText = ">"; inner.innerText = ">";
@ -120,7 +120,7 @@ function createSourceSidebar() {
var sidebar = document.createElement("div"); var sidebar = document.createElement("div");
sidebar.id = "source-sidebar"; sidebar.id = "source-sidebar";
if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") { if (getCurrentValue("source-sidebar-show") !== "true") {
container.classList.remove("expanded"); container.classList.remove("expanded");
} else { } else {
container.classList.add("expanded"); container.classList.add("expanded");

View file

@ -15,7 +15,7 @@ var settingsDataset = (function () {
})(); })();
function getSettingValue(settingName) { function getSettingValue(settingName) {
var current = getCurrentValue('rustdoc-' + settingName); var current = getCurrentValue(settingName);
if (current !== null) { if (current !== null) {
return current; return current;
} }
@ -106,7 +106,7 @@ function hasOwnPropertyRustdoc(obj, property) {
function updateLocalStorage(name, value) { function updateLocalStorage(name, value) {
try { try {
window.localStorage.setItem(name, value); window.localStorage.setItem("rustdoc-" + name, value);
} catch(e) { } catch(e) {
// localStorage is not accessible, do nothing // localStorage is not accessible, do nothing
} }
@ -114,7 +114,7 @@ function updateLocalStorage(name, value) {
function getCurrentValue(name) { function getCurrentValue(name) {
try { try {
return window.localStorage.getItem(name); return window.localStorage.getItem("rustdoc-" + name);
} catch(e) { } catch(e) {
return null; return null;
} }
@ -127,7 +127,7 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
// If this new value comes from a system setting or from the previously // If this new value comes from a system setting or from the previously
// saved theme, no need to save it. // saved theme, no need to save it.
if (saveTheme) { if (saveTheme) {
updateLocalStorage("rustdoc-theme", newTheme); updateLocalStorage("theme", newTheme);
} }
if (styleElem.href === newHref) { if (styleElem.href === newHref) {
@ -158,7 +158,7 @@ function useSystemTheme(value) {
value = true; value = true;
} }
updateLocalStorage("rustdoc-use-system-theme", value); updateLocalStorage("use-system-theme", value);
// update the toggle if we're on the settings page // update the toggle if we're on the settings page
var toggle = document.getElementById("use-system-theme"); var toggle = document.getElementById("use-system-theme");
@ -231,7 +231,7 @@ if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) {
if (getSettingValue("use-system-theme") === null if (getSettingValue("use-system-theme") === null
&& getSettingValue("preferred-dark-theme") === null && getSettingValue("preferred-dark-theme") === null
&& darkThemes.indexOf(localStoredTheme) >= 0) { && darkThemes.indexOf(localStoredTheme) >= 0) {
updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme); updateLocalStorage("preferred-dark-theme", localStoredTheme);
} }
// call the function to initialize the theme at least once! // call the function to initialize the theme at least once!