diff options
| -rw-r--r-- | emccpre.js | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -525,23 +525,20 @@ function initPuzzle() { command(4); }); - // Event handlers to fake :focus-within on browsers too old for + // Event handler to fake :focus-within on browsers too old for // it (like KaiOS 2.5). Browsers without :focus-within are also - // too old for focusin/out events, so we have to use focus and + // too old for focusin/out events, so we have to use focus events // which don't bubble but can be captured. - menuform.addEventListener("focus", function(event) { - var elem = event.target; - while (elem && elem !== menuform) { + // + // A button losing focus because it was disabled doesn't generate + // a blur event, so we do this entirely in the focus handler. + document.documentElement.addEventListener("focus", function(event) { + for (var elem = event.target; elem; elem = elem.parentElement) elem.classList.add("focus-within"); - elem = elem.parentElement; - } - }, true); - menuform.addEventListener("blur", function(event) { - var elem = event.target; - while (elem && !elem.contains(event.relatedTarget)) { - elem.classList.remove("focus-within"); - elem = elem.parentElement; - } + for (elem of + Array.from(document.getElementsByClassName("focus-within"))) + if (!elem.contains(event.target)) + elem.classList.remove("focus-within"); }, true); // Set up the function pointers we haven't already grabbed. |