@@ -329,7 +329,13 @@ aria-label="Show hidden lines"></button>';
329329 themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
330330 el . classList . remove ( 'theme-selected' ) ;
331331 } ) ;
332- themePopup . querySelector ( 'button#' + get_theme ( ) ) . classList . add ( 'theme-selected' ) ;
332+ const selected = get_saved_theme ( ) ?? "default_theme" ;
333+ var element = themePopup . querySelector ( "button#" + selected ) ;
334+ if ( element === null ) {
335+ // Fall back in case there is no "Default" item.
336+ element = themePopup . querySelector ( "button#" + get_theme ( ) ) ;
337+ }
338+ element . classList . add ( 'theme-selected' ) ;
333339 }
334340
335341 function hideThemes ( ) {
@@ -338,13 +344,22 @@ aria-label="Show hidden lines"></button>';
338344 themeToggleButton . focus ( ) ;
339345 }
340346
341- function get_theme ( ) {
342- let theme ;
347+ function get_saved_theme ( ) {
348+ var theme = null ;
343349 try {
344350 theme = localStorage . getItem ( 'mdbook-theme' ) ;
345351 } catch ( e ) {
346352 // ignore error.
347353 }
354+ return theme ;
355+ }
356+
357+ function delete_saved_theme ( ) {
358+ localStorage . removeItem ( 'mdbook-theme' ) ;
359+ }
360+
361+ function get_theme ( ) {
362+ var theme = get_saved_theme ( ) ;
348363 if ( theme === null || theme === undefined || ! themeIds . includes ( theme ) ) {
349364 if ( typeof default_dark_theme === 'undefined' ) {
350365 // A customized index.hbs might not define this, so fall back to
@@ -430,7 +445,12 @@ aria-label="Show hidden lines"></button>';
430445 } else {
431446 return ;
432447 }
433- set_theme ( theme ) ;
448+ if ( theme === "default_theme" || theme == null ) {
449+ delete_saved_theme ( ) ;
450+ set_theme ( get_theme ( ) , false ) ;
451+ } else {
452+ set_theme ( theme ) ;
453+ }
434454 } ) ;
435455
436456 themePopup . addEventListener ( 'focusout' , function ( e ) {
0 commit comments