Skip to content

Commit 493b622

Browse files
committed
Don't pollute the global function namespace with theme functions
1 parent f8d1f02 commit 493b622

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

templates/theme.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
function applyTheme(theme) {
2-
document.documentElement.dataset.theme = theme;
3-
}
4-
5-
window.addEventListener('storage', function (ev) {
6-
if (ev.key === 'rustdoc-theme') {
7-
applyTheme(ev.newValue);
1+
(function() {
2+
function applyTheme(theme) {
3+
document.documentElement.dataset.theme = theme;
84
}
9-
});
105

11-
// see ./storage-change-detection.html for details
12-
window.addEventListener('message', function (ev) {
13-
if (ev.data && ev.data.storage && ev.data.storage.key === 'rustdoc-theme') {
14-
applyTheme(ev.data.storage.value);
15-
}
16-
});
6+
window.addEventListener('storage', function (ev) {
7+
if (ev.key === 'rustdoc-theme') {
8+
applyTheme(ev.newValue);
9+
}
10+
});
11+
12+
// see ./storage-change-detection.html for details
13+
window.addEventListener('message', function (ev) {
14+
if (ev.data && ev.data.storage && ev.data.storage.key === 'rustdoc-theme') {
15+
applyTheme(ev.data.storage.value);
16+
}
17+
});
1718

18-
applyTheme(window.localStorage.getItem('rustdoc-theme'));
19+
applyTheme(window.localStorage.getItem('rustdoc-theme'));
20+
})()

0 commit comments

Comments
 (0)