jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
74 lines (59 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var array = require('./array.js');
var tabOrder = require('./tabOrder.js');
var tabUtils = require('./tabUtils.js');
var isElementHidden = function isElementHidden(computedStyle) {
if (!computedStyle || !computedStyle.getPropertyValue) {
return false;
}
return computedStyle.getPropertyValue('display') === 'none' || computedStyle.getPropertyValue('visibility') === 'hidden';
};
var isVisible = function isVisible(node) {
return !node || node === document || node.nodeType === Node.DOCUMENT_NODE || !isElementHidden(window.getComputedStyle(node, null)) && isVisible(node.parentNode);
};
var notHiddenInput = function notHiddenInput(node) {
return !((node.tagName === 'INPUT' || node.tagName === 'BUTTON') && (node.type === 'hidden' || node.disabled));
};
var getParents = function getParents(node) {
var parents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
parents.push(node);
if (node.parentNode) {
getParents(node.parentNode, parents);
}
return parents;
};
var getCommonParent = function getCommonParent(nodea, nodeb) {
var parentsA = getParents(nodea);
var parentsB = getParents(nodeb);
for (var i = 0; i < parentsA.length; i += 1) {
var currentParent = parentsA[i];
if (parentsB.indexOf(currentParent) >= 0) {
return currentParent;
}
}
return false;
};
var filterFocusable = function filterFocusable(nodes) {
return array.toArray(nodes).filter(function (node) {
return isVisible(node);
}).filter(function (node) {
return notHiddenInput(node);
});
};
var getTabbableNodes = function getTabbableNodes(topNodes, withGuards) {
return tabOrder.orderByTabIndex(filterFocusable(tabUtils.getFocusables(topNodes, withGuards)), true, withGuards);
};
var getAllTabbableNodes = function getAllTabbableNodes(topNodes) {
return tabOrder.orderByTabIndex(filterFocusable(tabUtils.getFocusables(topNodes)), false);
};
var parentAutofocusables = function parentAutofocusables(topNode) {
return filterFocusable(tabUtils.getParentAutofocusables(topNode));
};
exports.filterFocusable = filterFocusable;
exports.getAllTabbableNodes = getAllTabbableNodes;
exports.getCommonParent = getCommonParent;
exports.getTabbableNodes = getTabbableNodes;
exports.isVisible = isVisible;
exports.notHiddenInput = notHiddenInput;
exports.parentAutofocusables = parentAutofocusables;