File tree Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 5
5
<!--
6
6
Only other windows get notified when we change local storage, so
7
7
this is used in an invisible iframe to send a message to JS in
8
- ../templates/rustdoc/body.html when local storage changes so we can
9
- detect rustdoc changing the theme
8
+ ../templates/theme.js when rustdoc in the current window changes the
9
+ theme
10
10
-->
11
11
< script type ="text/javascript ">
12
12
onstorage = function ( ev ) {
Original file line number Diff line number Diff line change 29
29
window . addEventListener ( "scroll" , maybeFixupViewPortPosition , { "once" : true } ) ;
30
30
}
31
31
}
32
-
33
- window . addEventListener ( 'message' , function ( ev ) {
34
- if ( ev . data && ev . data . storage && ev . data . storage . key === 'rustdoc-theme' ) {
35
- applyTheme ( ev . data . storage . value ) ;
36
- }
37
- } ) ;
38
32
</ script >
39
- <!--
40
- Only other windows get notified when we change local storage, so we have an
41
- invisible iframe that sends us a message when local storage changes so we
42
- can detect rustdoc changing the theme
43
- -->
33
+
34
+ {# see comment in ../../static/storage-change-detection.html for details #}
44
35
< iframe src ="/-/static/storage-change-detection.html " width ="0 " height ="0 " style ="display: none "> </ iframe >
Original file line number Diff line number Diff line change 1
- // This is a global function also called from a script in ./rustdoc/body.html
2
- // which detects when the rustdoc theme is changed
3
1
function applyTheme ( theme ) {
4
2
document . documentElement . dataset . theme = theme ;
5
3
}
6
4
5
+ window . addEventListener ( 'storage' , function ( ev ) {
6
+ if ( ev . key === 'rustdoc-theme' ) {
7
+ applyTheme ( ev . newValue ) ;
8
+ }
9
+ } ) ;
10
+
11
+ // see ../static/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
+ } ) ;
17
+
7
18
applyTheme ( window . localStorage . getItem ( 'rustdoc-theme' ) ) ;
You can’t perform that action at this time.
0 commit comments