mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
31 lines
890 B
JavaScript
31 lines
890 B
JavaScript
// element-closest | CC0-1.0 | github.com/jonathantneal/closest
|
|
|
|
if (typeof Element.prototype.matches !== 'function') {
|
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.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 Element.prototype.closest !== 'function') {
|
|
Element.prototype.closest = function closest(selector) {
|
|
var element = this;
|
|
|
|
while (element && element.nodeType === 1) {
|
|
if (element.matches(selector)) {
|
|
return element;
|
|
}
|
|
|
|
element = element.parentNode;
|
|
}
|
|
|
|
return null;
|
|
};
|
|
}
|