File tree Expand file tree Collapse file tree 6 files changed +43
-1
lines changed Expand file tree Collapse file tree 6 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < script type ="text/javascript ">
6+ onstorage = function ( ev ) {
7+ parent . postMessage ( {
8+ storage : {
9+ key : ev . key ,
10+ value : ev . newValue ,
11+ }
12+ } )
13+ }
14+ </ script >
15+ </ head >
16+ </ html >
Original file line number Diff line number Diff line change 2121 < link rel ="search " href ="/-/static/opensearch.xml " type ="application/opensearchdescription+xml " title ="Docs.rs " />
2222
2323 < title > {%- block title -%} Docs.rs {%- endblock title -%}</ title >
24+
25+ < script type ="text/javascript "> { % - include "theme.js" - % } </ script >
2426 </ head >
2527
2628 < body >
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+ } ) ;
3238</ 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+ -->
44+ < 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 22 < link rel ="stylesheet " href ="/-/static/style.css?{{ docsrs_version() | slugify }} " type ="text/css " media ="all " />
33
44 < link rel ="search " href ="/-/static/opensearch.xml " type ="application/opensearchdescription+xml " title ="Docs.rs " />
5+
6+ < script type ="text/javascript "> { % - include "theme.js" - % } </ script >
Original file line number Diff line number Diff line change 11// Standard white theme
2- body {
2+ html {
33 --color-background-code : #f5f5f5 ;
44 --color-background : #fff ;
55 --color-border-light : lighten (#ddd , 5% );
2020 --color-warn-hover : darken (#e57300 , 10% );
2121 --color-warn : #e57300 ;
2222}
23+
24+ // To add a new theme, copy the above theme into a new `html[data-theme="name"]`
25+ // block below and change the colors
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+ function applyTheme ( theme ) {
4+ document . documentElement . dataset . theme = theme ;
5+ }
6+
7+ applyTheme ( window . localStorage . getItem ( 'rustdoc-theme' ) ) ;
You can’t perform that action at this time.
0 commit comments