diff options
author | Sam Potts <sam@potts.es> | 2019-06-21 00:12:10 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-21 00:12:10 +1000 |
commit | 95092edc93d713b927c637cefc27945f8537d565 (patch) | |
tree | 27464f2f98a519f78ff3cc4a2c49ebdd5c6dab2c /demo/src/js/tab-focus.js | |
parent | 1e761e237aceb49b29291946a39eef958d6da966 (diff) | |
parent | c4b3e0672e86f2a2786f315bf8f54250cd1f7f78 (diff) | |
download | plyr-95092edc93d713b927c637cefc27945f8537d565.tar.lz plyr-95092edc93d713b927c637cefc27945f8537d565.tar.xz plyr-95092edc93d713b927c637cefc27945f8537d565.zip |
Merge pull request #1472 from sampotts/develop
v3.5.5
Diffstat (limited to 'demo/src/js/tab-focus.js')
-rw-r--r-- | demo/src/js/tab-focus.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/demo/src/js/tab-focus.js b/demo/src/js/tab-focus.js new file mode 100644 index 00000000..c1602cf0 --- /dev/null +++ b/demo/src/js/tab-focus.js @@ -0,0 +1,31 @@ +// Setup tab focus +const container = document.getElementById('container'); +const tabClassName = 'tab-focus'; + +// Remove class on blur +document.addEventListener('focusout', event => { + if (!event.target.classList || container.contains(event.target)) { + return; + } + + event.target.classList.remove(tabClassName); +}); + +// Add classname to tabbed elements +document.addEventListener('keydown', event => { + if (event.keyCode !== 9) { + return; + } + + // Delay the adding of classname until the focus has changed + // This event fires before the focusin event + setTimeout(() => { + const focused = document.activeElement; + + if (!focused || !focused.classList || container.contains(focused)) { + return; + } + + focused.classList.add(tabClassName); + }, 10); +}); |