wp-polyfill-node-contains.js 643 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Node.prototype.contains
  2. (function() {
  3. function contains(node) {
  4. if (!(0 in arguments)) {
  5. throw new TypeError('1 argument is required');
  6. }
  7. do {
  8. if (this === node) {
  9. return true;
  10. }
  11. // eslint-disable-next-line no-cond-assign
  12. } while (node = node && node.parentNode);
  13. return false;
  14. }
  15. // IE
  16. if ('HTMLElement' in self && 'contains' in HTMLElement.prototype) {
  17. try {
  18. delete HTMLElement.prototype.contains;
  19. // eslint-disable-next-line no-empty
  20. } catch (e) {}
  21. }
  22. if ('Node' in self) {
  23. Node.prototype.contains = contains;
  24. } else {
  25. document.contains = Element.prototype.contains = contains;
  26. }
  27. }());