Skip to content

Commit f7ffffb

Browse files
committed
Fix theme selector focus.
1 parent 760c9b0 commit f7ffffb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/theme/book.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function playpen_text(playpen) {
284284
function showThemes() {
285285
themePopup.style.display = 'block';
286286
themeToggleButton.setAttribute('aria-expanded', true);
287-
themePopup.querySelector("button#" + document.body.className).focus();
287+
themePopup.querySelector("button#" + get_theme()).focus();
288288
}
289289

290290
function hideThemes() {
@@ -293,6 +293,16 @@ function playpen_text(playpen) {
293293
themeToggleButton.focus();
294294
}
295295

296+
function get_theme() {
297+
var theme;
298+
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
299+
if (theme === null || theme === undefined) {
300+
return default_theme;
301+
} else {
302+
return theme;
303+
}
304+
}
305+
296306
function set_theme(theme, store = true) {
297307
let ace_theme;
298308

@@ -324,9 +334,7 @@ function playpen_text(playpen) {
324334
});
325335
}
326336

327-
var previousTheme;
328-
try { previousTheme = localStorage.getItem('mdbook-theme'); } catch (e) { }
329-
if (previousTheme === null || previousTheme === undefined) { previousTheme = default_theme; }
337+
var previousTheme = get_theme();
330338

331339
if (store) {
332340
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
@@ -337,9 +345,7 @@ function playpen_text(playpen) {
337345
}
338346

339347
// Set theme
340-
var theme;
341-
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
342-
if (theme === null || theme === undefined) { theme = default_theme; }
348+
var theme = get_theme();
343349

344350
set_theme(theme, false);
345351

0 commit comments

Comments
 (0)