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 55 <!--
66 Only other windows get notified when we change local storage, so
77 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
1010 -->
1111 < script type ="text/javascript ">
1212 onstorage = function ( ev ) {
Original file line number Diff line number Diff line change 2929 window . addEventListener ( "scroll" , maybeFixupViewPortPosition , { "once" : true } ) ;
3030 }
3131 }
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- } ) ;
3832</ 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 #}
4435< 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
31function applyTheme ( theme ) {
42 document . documentElement . dataset . theme = theme ;
53}
64
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+
718applyTheme ( window . localStorage . getItem ( 'rustdoc-theme' ) ) ;
You can’t perform that action at this time.
0 commit comments