jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
64 lines (51 loc) • 2.18 kB
JavaScript
import { toArray } from './array.js';
import { orderByTabIndex } from './tabOrder.js';
import { getFocusables, getParentAutofocusables } from './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 toArray(nodes).filter(function (node) {
return isVisible(node);
}).filter(function (node) {
return notHiddenInput(node);
});
};
var getTabbableNodes = function getTabbableNodes(topNodes, withGuards) {
return orderByTabIndex(filterFocusable(getFocusables(topNodes, withGuards)), true, withGuards);
};
var getAllTabbableNodes = function getAllTabbableNodes(topNodes) {
return orderByTabIndex(filterFocusable(getFocusables(topNodes)), false);
};
var parentAutofocusables = function parentAutofocusables(topNode) {
return filterFocusable(getParentAutofocusables(topNode));
};
export { filterFocusable, getAllTabbableNodes, getCommonParent, getTabbableNodes, isVisible, notHiddenInput, parentAutofocusables };