No Description

polyfills.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * File polyfills.js.
  3. *
  4. * Polyfills for IE11.
  5. */
  6. /**
  7. * Polyfill for Element.closest() because we need to support IE11.
  8. *
  9. * @since Twenty Twenty-One 1.0
  10. *
  11. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
  12. */
  13. if ( ! Element.prototype.matches ) {
  14. Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
  15. }
  16. if ( ! Element.prototype.closest ) {
  17. Element.prototype.closest = function( s ) {
  18. var el = this;
  19. do {
  20. if ( Element.prototype.matches.call( el, s ) ) {
  21. return el;
  22. }
  23. el = el.parentElement || el.parentNode;
  24. } while ( el !== null && el.nodeType === 1 );
  25. return null;
  26. };
  27. }
  28. /**
  29. * Polyfill for NodeList.foreach() because we need to support IE11.
  30. *
  31. * @since Twenty Twenty-One 1.0
  32. *
  33. * @see https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
  34. */
  35. if ( window.NodeList && ! NodeList.prototype.forEach ) {
  36. NodeList.prototype.forEach = function( callback, thisArg ) {
  37. var i;
  38. thisArg = thisArg || window;
  39. for ( i = 0; i < this.length; i++ ) {
  40. callback.call( thisArg, this[i], i, this );
  41. }
  42. };
  43. }