kollapsminoriteten/wp-includes/js/dist/vendor/wp-polyfill-node-contains.js

35 lines
643 B
JavaScript
Raw Normal View History

2021-07-23 11:58:50 +02:00
// Node.prototype.contains
2019-11-02 10:38:58 +01:00
(function() {
function contains(node) {
if (!(0 in arguments)) {
throw new TypeError('1 argument is required');
}
do {
if (this === node) {
return true;
}
2021-07-23 11:58:50 +02:00
// eslint-disable-next-line no-cond-assign
2019-11-02 10:38:58 +01:00
} while (node = node && node.parentNode);
return false;
}
// IE
2021-07-23 11:58:50 +02:00
if ('HTMLElement' in self && 'contains' in HTMLElement.prototype) {
2019-11-02 10:38:58 +01:00
try {
delete HTMLElement.prototype.contains;
2021-07-23 11:58:50 +02:00
// eslint-disable-next-line no-empty
2019-11-02 10:38:58 +01:00
} catch (e) {}
}
2021-07-23 11:58:50 +02:00
if ('Node' in self) {
2019-11-02 10:38:58 +01:00
Node.prototype.contains = contains;
} else {
document.contains = Element.prototype.contains = contains;
}
}());