Skip to content

Commit 8bdad67

Browse files
committed
Rollup merge of rust-lang#48381 - GuillaumeGomez:rustdoc-theme-securities, r=QuietMisdreavus
Rustdoc theme securities rust-lang#48381 Fixes rust-lang#48375. Fixes rust-lang#48376.
2 parents 5cd8eb2 + 8d51c33 commit 8bdad67

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/librustdoc/html/static/main.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@
9696
}
9797
}
9898

99-
function onEach(arr, func) {
100-
if (arr && arr.length > 0 && func) {
101-
for (var i = 0; i < arr.length; i++) {
102-
func(arr[i]);
103-
}
104-
}
105-
}
106-
10799
function isHidden(elem) {
108100
return (elem.offsetParent === null)
109101
}

src/librustdoc/html/static/rustdoc.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,10 @@ kbd {
11891189
top: 19px;
11901190
}
11911191

1192+
.theme-picker button {
1193+
outline: none;
1194+
}
1195+
11921196
#theme-picker {
11931197
padding: 4px;
11941198
width: 27px;

src/librustdoc/html/static/storage.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
var currentTheme = document.getElementById("themeStyle");
1414
var mainTheme = document.getElementById("mainThemeStyle");
1515

16+
var savedHref = [];
17+
18+
function onEach(arr, func) {
19+
if (arr && arr.length > 0 && func) {
20+
for (var i = 0; i < arr.length; i++) {
21+
if (func(arr[i]) === true) {
22+
break;
23+
}
24+
}
25+
}
26+
}
27+
1628
function updateLocalStorage(name, value) {
1729
if (typeof(Storage) !== "undefined") {
1830
localStorage[name] = value;
@@ -29,8 +41,24 @@ function getCurrentValue(name) {
2941
}
3042

3143
function switchTheme(styleElem, mainStyleElem, newTheme) {
32-
styleElem.href = mainStyleElem.href.replace("rustdoc.css", newTheme + ".css");
33-
updateLocalStorage('theme', newTheme);
44+
var newHref = mainStyleElem.href.replace("rustdoc.css", newTheme + ".css");
45+
var found = false;
46+
47+
if (savedHref.length === 0) {
48+
onEach(document.getElementsByTagName("link"), function(el) {
49+
savedHref.push(el.href);
50+
});
51+
}
52+
onEach(savedHref, function(el) {
53+
if (el === newHref) {
54+
found = true;
55+
return true;
56+
}
57+
});
58+
if (found === true) {
59+
styleElem.href = newHref;
60+
updateLocalStorage('rustdoc-theme', newTheme);
61+
}
3462
}
3563

36-
switchTheme(currentTheme, mainTheme, getCurrentValue('theme') || 'main');
64+
switchTheme(currentTheme, mainTheme, getCurrentValue('rustdoc-theme') || 'main');

0 commit comments

Comments
 (0)