From 82aef1bc3f954120e6332609f5c4de97aef2f309 Mon Sep 17 00:00:00 2001 From: Sorin Davidoi Date: Sat, 24 Feb 2018 10:23:45 +0100 Subject: [PATCH] fix(theme/book): Workaround focusout bug in macOS and iOS (#630) --- src/theme/book.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/theme/book.js b/src/theme/book.js index c2deb79c..df2c1251 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -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(); } });