UNPKG

playable

Version:

Video player based on HTML5Video

68 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // Unspecified error on Internet Explorer with document.activeElement // https://github.com/reactjs/react-tabs/issues/193 var canUseActiveElement = typeof window !== 'undefined' && window.document && typeof window.document.activeElement !== 'unknown'; // inspired by https://gist.github.com/aFarkas/a7e0d85450f323d5e164 var FOCUS_WITHIN_CLASSNAME = 'focus-within'; var clearFocusWithinClass = function (element) { Array.prototype.slice .call(element.getElementsByClassName(FOCUS_WITHIN_CLASSNAME)) .forEach(function (elem) { elem.classList.remove(FOCUS_WITHIN_CLASSNAME); }); }; function isElementNode(node) { return typeof node.classList !== 'undefined'; } var addFocusWithinClass = function (boundaryElement, activeElement) { var currentNode = activeElement; while (currentNode !== boundaryElement && isElementNode(currentNode)) { currentNode.classList.add(FOCUS_WITHIN_CLASSNAME); currentNode = currentNode.parentNode; } }; var focusWithin = function (rootElement, onFocusEnter, onFocusLeave) { var update = (function () { var running; var last; var isFocused; var action = function () { var activeElement = canUseActiveElement ? document.activeElement : null; running = false; if (last !== activeElement) { last = activeElement; clearFocusWithinClass(rootElement); if (!rootElement.contains(activeElement)) { if (isFocused) { isFocused = false; onFocusLeave(); } return; } if (!isFocused) { isFocused = true; onFocusEnter(); } addFocusWithinClass(rootElement, activeElement); } }; return function () { if (!running) { requestAnimationFrame(action); running = true; } }; })(); rootElement.addEventListener('focus', update, true); rootElement.addEventListener('blur', update, true); update(); return function () { rootElement.removeEventListener('focus', update, true); rootElement.removeEventListener('blur', update, true); }; }; exports.default = focusWithin; //# sourceMappingURL=focus-within.js.map