39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.elementContains = void 0;
|
||
|
var getParent_1 = require("./getParent");
|
||
|
/**
|
||
|
* Determines whether or not a parent element contains a given child element.
|
||
|
* If `allowVirtualParents` is true, this method may return `true` if the child
|
||
|
* has the parent in its virtual element hierarchy.
|
||
|
*
|
||
|
* @public
|
||
|
*/
|
||
|
function elementContains(parent, child, allowVirtualParents) {
|
||
|
if (allowVirtualParents === void 0) { allowVirtualParents = true; }
|
||
|
var isContained = false;
|
||
|
if (parent && child) {
|
||
|
if (allowVirtualParents) {
|
||
|
if (parent === child) {
|
||
|
isContained = true;
|
||
|
}
|
||
|
else {
|
||
|
isContained = false;
|
||
|
while (child) {
|
||
|
var nextParent = (0, getParent_1.getParent)(child);
|
||
|
if (nextParent === parent) {
|
||
|
isContained = true;
|
||
|
break;
|
||
|
}
|
||
|
child = nextParent;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (parent.contains) {
|
||
|
isContained = parent.contains(child);
|
||
|
}
|
||
|
}
|
||
|
return isContained;
|
||
|
}
|
||
|
exports.elementContains = elementContains;
|
||
|
//# sourceMappingURL=elementContains.js.map
|