From f7ffffbd1e09c304348c1e6323417c20d444bb5c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Mar 2020 11:10:50 -0700 Subject: [PATCH] Fix theme selector focus. --- src/theme/book.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index 8fda7a6c..d27c0114 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -284,7 +284,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() { @@ -293,6 +293,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; @@ -324,9 +334,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) { } @@ -337,9 +345,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);