aboutsummaryrefslogtreecommitdiffstats
path: root/demo/src/js/tab-focus.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-01-30 14:23:10 +0000
committerGitHub <noreply@github.com>2020-01-30 14:23:10 +0000
commit9d512911252cf4835c2b7364cb4ae392cb277a1d (patch)
tree5e6dcc7647285e49683f05d8a49187e8078d0d2b /demo/src/js/tab-focus.js
parent44d3a17870949e828e5b1a4619a30dfcb626a174 (diff)
parentb2ac730572ad81aa9755e8b7852c53ceba0e8e9f (diff)
downloadplyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.lz
plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.xz
plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.zip
Merge pull request #1663 from sampotts/master
Merge back to beta
Diffstat (limited to 'demo/src/js/tab-focus.js')
-rw-r--r--demo/src/js/tab-focus.js31
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);
+});