Skip to content

Commit 4d57583

Browse files
committed
Restrict re-focus to only apply for control buttons (#28)
1 parent 84ab526 commit 4d57583

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

videojs.hotkeys.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
var hotkeys = function(options) {
2323
var player = this;
2424
var pEl = player.el();
25+
var doc = document;
2526
var def_options = {
2627
volumeStep: 0.1,
2728
seekStep: 5,
@@ -74,21 +75,18 @@
7475
}
7576

7677
player.on('userinactive', function() {
77-
var transitionTime, focusingPlayerTimeout, cancelFocusingPlayer;
78-
79-
transitionTime = 1000;
80-
81-
cancelFocusingPlayer = function(){
78+
// When the control bar fades, re-apply focus to the player if last focus was a control button
79+
var cancelFocusingPlayer = function() {
8280
clearTimeout(focusingPlayerTimeout);
8381
};
84-
85-
focusingPlayerTimeout = setTimeout(function(){
82+
var focusingPlayerTimeout = setTimeout(function() {
8683
player.off('useractive', cancelFocusingPlayer);
87-
pEl.focus();
88-
}, transitionTime);
84+
if (doc.activeElement.parentElement == pEl.querySelector('.vjs-control-bar')) {
85+
pEl.focus();
86+
}
87+
}, 10);
8988

9089
player.one('useractive', cancelFocusingPlayer);
91-
9290
});
9391

9492
player.on('play', function() {
@@ -107,7 +105,7 @@
107105
if (player.controls()) {
108106

109107
// Don't catch keys if any control buttons are focused, unless alwaysCaptureHotkeys is true
110-
var activeEl = document.activeElement;
108+
var activeEl = doc.activeElement;
111109
if (alwaysCaptureHotkeys ||
112110
activeEl == pEl ||
113111
activeEl == pEl.querySelector('.vjs-tech') ||
@@ -223,7 +221,7 @@
223221
if (player.controls()) {
224222

225223
// Don't catch clicks if any control buttons are focused
226-
var activeEl = event.relatedTarget || event.toElement || document.activeElement;
224+
var activeEl = event.relatedTarget || event.toElement || doc.activeElement;
227225
if (activeEl == pEl ||
228226
activeEl == pEl.querySelector('.vjs-tech') ||
229227
activeEl == pEl.querySelector('.iframeblocker')) {
@@ -242,7 +240,7 @@
242240
var mouseScroll = function mouseScroll(event) {
243241
// When controls are disabled, hotkeys will be disabled as well
244242
if (player.controls()) {
245-
var activeEl = event.relatedTarget || event.toElement || document.activeElement;
243+
var activeEl = event.relatedTarget || event.toElement || doc.activeElement;
246244
if (alwaysCaptureHotkeys ||
247245
activeEl == pEl ||
248246
activeEl == pEl.querySelector('.vjs-tech') ||

0 commit comments

Comments
 (0)