1
// element-closest | CC0-1.0 | github.com/jonathantneal/closest
3
(function (ElementProto) {
4
if (typeof ElementProto.matches !== 'function') {
5
ElementProto.matches = ElementProto.msMatchesSelector || ElementProto.mozMatchesSelector || ElementProto.webkitMatchesSelector || function matches(selector) {
7
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
10
while (elements[index] && elements[index] !== element) {
14
return Boolean(elements[index]);
18
if (typeof ElementProto.closest !== 'function') {
19
ElementProto.closest = function closest(selector) {
22
while (element && element.nodeType === 1) {
23
if (element.matches(selector)) {
27
element = element.parentNode;
33
})(window.Element.prototype);