Skip to content

Commit

Permalink
Merge pull request #1170 from ehuss/fix-theme-focus
Browse files Browse the repository at this point in the history
Fix theme selector focus.
  • Loading branch information
ehuss committed Apr 3, 2020
2 parents e839ef0 + f7ffffb commit 99ecd4f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function playpen_text(playpen) {
function showThemes() {
themePopup.style.display = 'block';
themeToggleButton.setAttribute('aria-expanded', true);
themePopup.querySelector("button#" + document.body.className).focus();
themePopup.querySelector("button#" + get_theme()).focus();
}

function hideThemes() {
Expand All @@ -294,6 +294,16 @@ function playpen_text(playpen) {
themeToggleButton.focus();
}

function get_theme() {
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
if (theme === null || theme === undefined) {
return default_theme;
} else {
return theme;
}
}

function set_theme(theme, store = true) {
let ace_theme;

Expand Down Expand Up @@ -325,9 +335,7 @@ function playpen_text(playpen) {
});
}

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

if (store) {
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
Expand All @@ -338,9 +346,7 @@ function playpen_text(playpen) {
}

// Set theme
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var theme = get_theme();

set_theme(theme, false);

Expand Down

0 comments on commit 99ecd4f

Please sign in to comment.