@@ -309,7 +309,13 @@ function playground_text(playground, hidden = true) {
309
309
themePopup . querySelectorAll ( '.theme-selected' ) . forEach ( function ( el ) {
310
310
el . classList . remove ( 'theme-selected' ) ;
311
311
} ) ;
312
- themePopup . querySelector ( "button#" + get_theme ( ) ) . classList . add ( 'theme-selected' ) ;
312
+ const selected = get_saved_theme ( ) ?? "default_theme" ;
313
+ var element = themePopup . querySelector ( "button#" + selected ) ;
314
+ if ( element === null ) {
315
+ // Fall back in case there is no "Default" item.
316
+ element = themePopup . querySelector ( "button#" + get_theme ( ) ) ;
317
+ }
318
+ element . classList . add ( 'theme-selected' ) ;
313
319
}
314
320
315
321
function hideThemes ( ) {
@@ -318,9 +324,18 @@ function playground_text(playground, hidden = true) {
318
324
themeToggleButton . focus ( ) ;
319
325
}
320
326
321
- function get_theme ( ) {
322
- var theme ;
327
+ function get_saved_theme ( ) {
328
+ var theme = null ;
323
329
try { theme = localStorage . getItem ( 'mdbook-theme' ) ; } catch ( e ) { }
330
+ return theme ;
331
+ }
332
+
333
+ function delete_saved_theme ( ) {
334
+ localStorage . removeItem ( 'mdbook-theme' ) ;
335
+ }
336
+
337
+ function get_theme ( ) {
338
+ var theme = get_saved_theme ( ) ;
324
339
if ( theme === null || theme === undefined || ! themeIds . includes ( theme ) ) {
325
340
if ( typeof default_dark_theme === 'undefined' ) {
326
341
// A customized index.hbs might not define this, so fall back to
@@ -402,7 +417,12 @@ function playground_text(playground, hidden = true) {
402
417
} else {
403
418
return ;
404
419
}
405
- set_theme ( theme ) ;
420
+ if ( theme === "default_theme" || theme == null ) {
421
+ delete_saved_theme ( ) ;
422
+ set_theme ( get_theme ( ) , false ) ;
423
+ } else {
424
+ set_theme ( theme ) ;
425
+ }
406
426
} ) ;
407
427
408
428
themePopup . addEventListener ( 'focusout' , function ( e ) {
0 commit comments