wp/wp-includes/js/dist/vendor/wp-polyfill-element-closest.js
changeset 21 48c4eec2b7e6
parent 9 177826044cd9
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 // element-closest | CC0-1.0 | github.com/jonathantneal/closest
     1 !function(e){var t=e.Element.prototype;"function"!=typeof t.matches&&(t.matches=t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),o=0;t[o]&&t[o]!==this;)++o;return Boolean(t[o])}),"function"!=typeof t.closest&&(t.closest=function(e){for(var t=this;t&&1===t.nodeType;){if(t.matches(e))return t;t=t.parentNode}return null})}(window);
     2 
       
     3 (function (ElementProto) {
       
     4 	if (typeof ElementProto.matches !== 'function') {
       
     5 		ElementProto.matches = ElementProto.msMatchesSelector || ElementProto.mozMatchesSelector || ElementProto.webkitMatchesSelector || function matches(selector) {
       
     6 			var element = this;
       
     7 			var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
       
     8 			var index = 0;
       
     9 
       
    10 			while (elements[index] && elements[index] !== element) {
       
    11 				++index;
       
    12 			}
       
    13 
       
    14 			return Boolean(elements[index]);
       
    15 		};
       
    16 	}
       
    17 
       
    18 	if (typeof ElementProto.closest !== 'function') {
       
    19 		ElementProto.closest = function closest(selector) {
       
    20 			var element = this;
       
    21 
       
    22 			while (element && element.nodeType === 1) {
       
    23 				if (element.matches(selector)) {
       
    24 					return element;
       
    25 				}
       
    26 
       
    27 				element = element.parentNode;
       
    28 			}
       
    29 
       
    30 			return null;
       
    31 		};
       
    32 	}
       
    33 })(window.Element.prototype);