fix(theme/book): Workaround focusout bug in macOS and iOS (#630)

This commit is contained in:
Sorin Davidoi 2018-02-24 10:23:45 +01:00 committed by Michael Bryan
parent 38c883e1ef
commit 82aef1bc3f
1 changed files with 9 additions and 1 deletions

View File

@ -372,7 +372,15 @@ function playpen_text(playpen) {
});
themePopup.addEventListener('focusout', function(e) {
if (!themePopup.contains(e.relatedTarget)) {
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
if (!!e.relatedTarget && !themePopup.contains(e.relatedTarget)) {
hideThemes();
}
});
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang-nursery/mdBook/issues/628
document.addEventListener('click', function(e) {
if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {
hideThemes();
}
});