@@ -329,7 +329,13 @@ aria-label="Show hidden lines"></button>';
329
329
themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
330
330
el . classList . remove ( 'theme-selected' ) ;
331
331
} ) ;
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' ) ;
333
339
}
334
340
335
341
function hideThemes ( ) {
@@ -338,13 +344,22 @@ aria-label="Show hidden lines"></button>';
338
344
themeToggleButton . focus ( ) ;
339
345
}
340
346
341
- function get_theme ( ) {
342
- let theme ;
347
+ function get_saved_theme ( ) {
348
+ var theme = null ;
343
349
try {
344
350
theme = localStorage . getItem ( 'mdbook-theme' ) ;
345
351
} catch ( e ) {
346
352
// ignore error.
347
353
}
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 ( ) ;
348
363
if ( theme === null || theme === undefined || ! themeIds . includes ( theme ) ) {
349
364
if ( typeof default_dark_theme === 'undefined' ) {
350
365
// A customized index.hbs might not define this, so fall back to
@@ -430,7 +445,12 @@ aria-label="Show hidden lines"></button>';
430
445
} else {
431
446
return ;
432
447
}
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
+ }
434
454
} ) ;
435
455
436
456
themePopup . addEventListener ( 'focusout' , function ( e ) {
0 commit comments