Skip to content

Commit cbdc2fd

Browse files
committed
catch error if attempting to select or deselect a non-existent theme.
1 parent b335dbf commit cbdc2fd

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/theme/book.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,17 @@ function playground_text(playground, hidden = true) {
361361
});
362362
}
363363

364-
var previousTheme = get_theme();
364+
var previousTheme = get_theme().replace(/\W+/g, '_').toLowerCase();
365+
var selectedTheme = theme.replace(/\W+/g, '_').toLowerCase();
365366
if (store) {
366367
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
367368
}
368369

369-
html.classList.remove(previousTheme.replace(/\W+/g, '_').toLowerCase());
370-
html.classList.add(theme.replace(/\W+/g, '_').toLowerCase());
370+
try {
371+
html.classList.remove( previousTheme );
372+
html.classList.add( selectedTheme );
373+
} catch (e) { }
374+
371375
updateThemeSelected();
372376
}
373377

src/theme/index.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@
8484
if (theme === null || theme === undefined) { theme = default_theme; }
8585
var html = document.querySelector('html');
8686
html.classList.remove('no-js')
87-
html.classList.remove('{{ default_theme }}')
88-
html.classList.add(theme.replace(/\W+/g, '_').toLowerCase());
87+
try {
88+
html.classList.remove('{{ default_theme }}');
89+
html.classList.add(theme.replace(/\W+/g, '_').toLowerCase());
90+
} catch(e) { }
8991
html.classList.add('js');
9092
</script>
9193

0 commit comments

Comments
 (0)