Skip to content

Commit 7efba33

Browse files
Unify storage getter and setter functions
1 parent a00e130 commit 7efba33

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ window.initSearch = function(rawSearchIndex) {
16191619
}
16201620

16211621
function updateCrate(ev) {
1622-
updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value);
1622+
updateLocalStorage("saved-filter-crate", ev.target.value);
16231623
// In case you "cut" the entry from the search input, then change the crate filter
16241624
// before paste back the previous search, you get the old search results without
16251625
// the filter. To prevent this, we need to remove the previous results.

src/librustdoc/html/static/js/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
(function () {
66
function changeSetting(settingName, value) {
7-
updateLocalStorage("rustdoc-" + settingName, value);
7+
updateLocalStorage(settingName, value);
88

99
switch (settingName) {
1010
case "theme":

src/librustdoc/html/static/js/source-script.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ function toggleSidebar() {
8282
if (child.innerText === ">") {
8383
sidebar.classList.add("expanded");
8484
child.innerText = "<";
85-
updateLocalStorage("rustdoc-source-sidebar-show", "true");
85+
updateLocalStorage("source-sidebar-show", "true");
8686
} else {
8787
sidebar.classList.remove("expanded");
8888
child.innerText = ">";
89-
updateLocalStorage("rustdoc-source-sidebar-show", "false");
89+
updateLocalStorage("source-sidebar-show", "false");
9090
}
9191
}
9292

@@ -97,7 +97,7 @@ function createSidebarToggle() {
9797

9898
var inner = document.createElement("div");
9999

100-
if (getCurrentValue("rustdoc-source-sidebar-show") === "true") {
100+
if (getCurrentValue("source-sidebar-show") === "true") {
101101
inner.innerText = "<";
102102
} else {
103103
inner.innerText = ">";
@@ -120,7 +120,7 @@ function createSourceSidebar() {
120120

121121
var sidebar = document.createElement("div");
122122
sidebar.id = "source-sidebar";
123-
if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") {
123+
if (getCurrentValue("source-sidebar-show") !== "true") {
124124
container.classList.remove("expanded");
125125
} else {
126126
container.classList.add("expanded");

src/librustdoc/html/static/js/storage.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var settingsDataset = (function () {
1515
})();
1616

1717
function getSettingValue(settingName) {
18-
var current = getCurrentValue('rustdoc-' + settingName);
18+
var current = getCurrentValue(settingName);
1919
if (current !== null) {
2020
return current;
2121
}
@@ -106,15 +106,15 @@ function hasOwnPropertyRustdoc(obj, property) {
106106

107107
function updateLocalStorage(name, value) {
108108
try {
109-
window.localStorage.setItem(name, value);
109+
window.localStorage.setItem("rustdoc-" + name, value);
110110
} catch(e) {
111111
// localStorage is not accessible, do nothing
112112
}
113113
}
114114

115115
function getCurrentValue(name) {
116116
try {
117-
return window.localStorage.getItem(name);
117+
return window.localStorage.getItem("rustdoc-" + name);
118118
} catch(e) {
119119
return null;
120120
}
@@ -127,7 +127,7 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
127127
// If this new value comes from a system setting or from the previously
128128
// saved theme, no need to save it.
129129
if (saveTheme) {
130-
updateLocalStorage("rustdoc-theme", newTheme);
130+
updateLocalStorage("theme", newTheme);
131131
}
132132

133133
if (styleElem.href === newHref) {
@@ -158,7 +158,7 @@ function useSystemTheme(value) {
158158
value = true;
159159
}
160160

161-
updateLocalStorage("rustdoc-use-system-theme", value);
161+
updateLocalStorage("use-system-theme", value);
162162

163163
// update the toggle if we're on the settings page
164164
var toggle = document.getElementById("use-system-theme");
@@ -231,7 +231,7 @@ if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) {
231231
if (getSettingValue("use-system-theme") === null
232232
&& getSettingValue("preferred-dark-theme") === null
233233
&& darkThemes.indexOf(localStoredTheme) >= 0) {
234-
updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme);
234+
updateLocalStorage("preferred-dark-theme", localStoredTheme);
235235
}
236236

237237
// call the function to initialize the theme at least once!

0 commit comments

Comments
 (0)