- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import { FOCUS_DISABLED, FOCUS_GROUP } from '../constants';
|
|
import { asArray, toArray } from './array';
|
|
/**
|
|
* in case of multiple nodes nested inside each other
|
|
* keeps only top ones
|
|
* this is O(nlogn)
|
|
* @param nodes
|
|
* @returns {*}
|
|
*/
|
|
var filterNested = function (nodes) {
|
|
var contained = new Set();
|
|
var l = nodes.length;
|
|
for (var i = 0; i < l; i += 1) {
|
|
for (var j = i + 1; j < l; j += 1) {
|
|
var position = nodes[i].compareDocumentPosition(nodes[j]);
|
|
/* eslint-disable no-bitwise */
|
|
if ((position & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0) {
|
|
contained.add(j);
|
|
}
|
|
if ((position & Node.DOCUMENT_POSITION_CONTAINS) > 0) {
|
|
contained.add(i);
|
|
}
|
|
/* eslint-enable */
|
|
}
|
|
}
|
|
return nodes.filter(function (_, index) { return !contained.has(index); });
|
|
};
|
|
/**
|
|
* finds top most parent for a node
|
|
* @param node
|
|
* @returns {*}
|
|
*/
|
|
var getTopParent = function (node) {
|
|
return node.parentNode ? getTopParent(node.parentNode) : node;
|
|
};
|
|
/**
|
|
* returns all "focus containers" inside a given node
|
|
* @param node - node or nodes to look inside
|
|
* @returns Element[]
|
|
*/
|
|
export var getAllAffectedNodes = function (node) {
|
|
var nodes = asArray(node);
|
|
return nodes.filter(Boolean).reduce(function (acc, currentNode) {
|
|
var group = currentNode.getAttribute(FOCUS_GROUP);
|
|
acc.push.apply(acc, (group
|
|
? filterNested(toArray(getTopParent(currentNode).querySelectorAll("[".concat(FOCUS_GROUP, "=\"").concat(group, "\"]:not([").concat(FOCUS_DISABLED, "=\"disabled\"])"))))
|
|
: [currentNode]));
|
|
return acc;
|
|
}, []);
|
|
};
|