@@ -19,6 +19,9 @@ let determineComputedTheme = () => {
1919 return ( userPref && userPref ( "(prefers-color-scheme: dark)" ) . matches ) ? "dark" : "light" ;
2020} ;
2121
22+ // detect OS/browser preference
23+ const browserPref = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ;
24+
2225// Set the theme on page load or when explicitly called
2326let setTheme = ( theme ) => {
2427 const use_theme =
@@ -50,7 +53,7 @@ var toggleTheme = () => {
5053
5154// Read the Plotly data from the code block, hide it, and render the chart as new node. This allows for the
5255// JSON data to be retrieve when the theme is switched.
53- import { plotlyDarkLayout , plotlyLightLayout } from './theme.js' ;
56+ import { plotlyDarkLayout , plotlyLightLayout } from './theme.js' ;
5457document . addEventListener ( "readystatechange" , ( ) => {
5558 if ( document . readyState === "complete" ) {
5659 document . querySelectorAll ( "pre>code.language-plotly" ) . forEach ( ( elem ) => {
@@ -60,7 +63,7 @@ document.addEventListener("readystatechange", () => {
6063
6164 // Add the Plotly node
6265 let chartElement = document . createElement ( "div" ) ;
63- elem . parentElement . after ( chartElement ) ;
66+ elem . parentElement . after ( chartElement ) ;
6467
6568 // Set the theme for the plot and render it
6669 const theme = ( determineComputedTheme ( ) === "dark" ) ? plotlyDarkLayout : plotlyLightLayout ;
@@ -79,11 +82,6 @@ document.addEventListener("readystatechange", () => {
7982 ========================================================================== */
8083
8184$ ( document ) . ready ( function ( ) {
82- // detect OS/browser preference
83- const browserPref = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
84- ? 'dark'
85- : 'light' ;
86-
8785 setTheme ( ) ;
8886
8987 // if user hasn't chosen a theme, follow OS changes
@@ -135,10 +133,10 @@ $(document).ready(function () {
135133 } ) ;
136134
137135 // init smooth scroll, this needs to be slightly more than then fixed masthead height
138- $ ( "a" ) . smoothScroll ( {
136+ $ ( "a" ) . smoothScroll ( {
139137 offset : - 75 , // needs to match $masthead-height
140138 preventDefault : false ,
141- } ) ;
139+ } ) ;
142140
143141 // add lightbox class to all image links
144142 // Add "image-popup" to links ending in image extensions,
@@ -149,14 +147,14 @@ $(document).ready(function () {
149147 a[href$='.png'],\
150148 a[href$='.gif'],\
151149 a[href$='.webp']" )
152- . not ( ':has(img)' )
153- . addClass ( "image-popup" ) ;
150+ . not ( ':has(img)' )
151+ . addClass ( "image-popup" ) ;
154152
155153 // 1) Wrap every <p><img> (except emoji images) in an <a> pointing at the image, and give it the lightbox class
156- $ ( 'p > img' ) . not ( '.emoji' ) . each ( function ( ) {
154+ $ ( 'p > img' ) . not ( '.emoji' ) . each ( function ( ) {
157155 var $img = $ ( this ) ;
158156 // skip if it’s already wrapped in an <a.image-popup>
159- if ( ! $img . parent ( ) . is ( 'a.image-popup' ) ) {
157+ if ( ! $img . parent ( ) . is ( 'a.image-popup' ) ) {
160158 $ ( '<a>' )
161159 . addClass ( 'image-popup' )
162160 . attr ( 'href' , $img . attr ( 'src' ) )
0 commit comments