49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.ariaHidden = ariaHidden;
|
|
exports.hideSiblings = hideSiblings;
|
|
exports.showSiblings = showSiblings;
|
|
// weak
|
|
|
|
var BLACKLIST = ['template', 'script', 'style'];
|
|
|
|
var isHidable = function isHidable(_ref) {
|
|
var nodeType = _ref.nodeType,
|
|
tagName = _ref.tagName;
|
|
return nodeType === 1 && BLACKLIST.indexOf(tagName.toLowerCase()) === -1;
|
|
};
|
|
|
|
var siblings = function siblings(container, mount, cb) {
|
|
mount = [].concat(mount); // eslint-disable-line no-param-reassign
|
|
[].forEach.call(container.children, function (node) {
|
|
if (mount.indexOf(node) === -1 && isHidable(node)) {
|
|
cb(node);
|
|
}
|
|
});
|
|
};
|
|
|
|
function ariaHidden(show, node) {
|
|
if (!node) {
|
|
return;
|
|
}
|
|
if (show) {
|
|
node.setAttribute('aria-hidden', 'true');
|
|
} else {
|
|
node.removeAttribute('aria-hidden');
|
|
}
|
|
}
|
|
|
|
function hideSiblings(container, mountNode) {
|
|
siblings(container, mountNode, function (node) {
|
|
return ariaHidden(true, node);
|
|
});
|
|
}
|
|
|
|
function showSiblings(container, mountNode) {
|
|
siblings(container, mountNode, function (node) {
|
|
return ariaHidden(false, node);
|
|
});
|
|
} |