aboutsummaryrefslogtreecommitdiffstats
path: root/demo/src/js/lib/tab-focus.js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2017-10-25 23:59:53 +1100
committerSam Potts <me@sampotts.me>2017-10-25 23:59:53 +1100
commit378aa159b8d91b2d9950575141a6ee67e7db350c (patch)
tree1baaa3b1d94efd49e016d74b60ff6ae14d17b33a /demo/src/js/lib/tab-focus.js
parent57517a9dcc7ce75aef455b157fb6d1b97eab4e79 (diff)
downloadplyr-378aa159b8d91b2d9950575141a6ee67e7db350c.tar.lz
plyr-378aa159b8d91b2d9950575141a6ee67e7db350c.tar.xz
plyr-378aa159b8d91b2d9950575141a6ee67e7db350c.zip
Docs/demo refresh
Diffstat (limited to 'demo/src/js/lib/tab-focus.js')
-rw-r--r--demo/src/js/lib/tab-focus.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/demo/src/js/lib/tab-focus.js b/demo/src/js/lib/tab-focus.js
new file mode 100644
index 00000000..06e51203
--- /dev/null
+++ b/demo/src/js/lib/tab-focus.js
@@ -0,0 +1,26 @@
+// ==========================================================================
+// tab-focus.js
+// Detect keyboard tabbing
+// ==========================================================================
+
+(function() {
+ var className = 'tab-focus';
+
+ // Remove class on blur
+ document.addEventListener('focusout', function(event) {
+ event.target.classList.remove(className);
+ });
+
+ // Add classname to tabbed elements
+ document.addEventListener('keydown', function(event) {
+ if (event.keyCode !== 9) {
+ return;
+ }
+
+ // Delay the adding of classname until the focus has changed
+ // This event fires before the focusin event
+ window.setTimeout(function() {
+ document.activeElement.classList.add(className);
+ }, 0);
+ });
+})();