CoreFiles by mySites.guru
wp-polyfill-element-closest.js33 lines, 895 bytes, from wordpress-5.2.21.zip
Raw History Compare with 5.2.20
md5
3c6accf0039920bf3c59748c23f4261d
sha1
90d5caa3086177bc10698f537ce35165d5376041
sha256
7dd43f45444adc7aadbea30d33596cf6d4a85b13a8df5e5a4b4141b93d0ca866
// element-closest | CC0-1.0 | github.com/jonathantneal/closest

(function (ElementProto) {
	if (typeof ElementProto.matches !== 'function') {
		ElementProto.matches = ElementProto.msMatchesSelector || ElementProto.mozMatchesSelector || ElementProto.webkitMatchesSelector || function matches(selector) {
			var element = this;
			var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
			var index = 0;

			while (elements[index] && elements[index] !== element) {
				++index;
			}

			return Boolean(elements[index]);
		};
	}

	if (typeof ElementProto.closest !== 'function') {
		ElementProto.closest = function closest(selector) {
			var element = this;

			while (element && element.nodeType === 1) {
				if (element.matches(selector)) {
					return element;
				}

				element = element.parentNode;
			}

			return null;
		};
	}
})(window.Element.prototype);

The same content is in 421 releases, WordPress 5.0-beta1 to 6.1.17. See them all, or every version of this file.