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) {
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
// 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.

View File

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

View File

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

View File

@ -15,7 +15,7 @@ var settingsDataset = (function () {
})();
function getSettingValue(settingName) {
var current = getCurrentValue('rustdoc-' + settingName);
var current = getCurrentValue(settingName);
if (current !== null) {
return current;
}
@ -106,7 +106,7 @@ function hasOwnPropertyRustdoc(obj, property) {
function updateLocalStorage(name, value) {
try {
window.localStorage.setItem(name, value);
window.localStorage.setItem("rustdoc-" + name, value);
} catch(e) {
// localStorage is not accessible, do nothing
}
@ -114,7 +114,7 @@ function updateLocalStorage(name, value) {
function getCurrentValue(name) {
try {
return window.localStorage.getItem(name);
return window.localStorage.getItem("rustdoc-" + name);
} catch(e) {
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
// saved theme, no need to save it.
if (saveTheme) {
updateLocalStorage("rustdoc-theme", newTheme);
updateLocalStorage("theme", newTheme);
}
if (styleElem.href === newHref) {
@ -158,7 +158,7 @@ function useSystemTheme(value) {
value = true;
}
updateLocalStorage("rustdoc-use-system-theme", value);
updateLocalStorage("use-system-theme", value);
// update the toggle if we're on the settings page
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
&& getSettingValue("preferred-dark-theme") === null
&& 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!