2016-10-17 13:14:46 -04:00
|
|
|
/* global Element */
|
2016-11-25 09:21:50 -05:00
|
|
|
/* eslint-disable consistent-return, max-len, no-empty, no-plusplus, func-names */
|
2016-10-17 13:14:46 -04:00
|
|
|
|
2016-11-23 09:56:28 -05:00
|
|
|
Element.prototype.closest = Element.prototype.closest || function closest(selector, selectedElement = this) {
|
2016-10-20 17:18:39 -04:00
|
|
|
if (!selectedElement) return;
|
|
|
|
return selectedElement.matches(selector) ? selectedElement : Element.prototype.closest(selector, selectedElement.parentElement);
|
|
|
|
};
|
2016-11-25 07:13:12 -05:00
|
|
|
|
|
|
|
if (!Element.prototype.matches) {
|
|
|
|
Element.prototype.matches =
|
|
|
|
Element.prototype.matchesSelector ||
|
|
|
|
Element.prototype.mozMatchesSelector ||
|
|
|
|
Element.prototype.msMatchesSelector ||
|
|
|
|
Element.prototype.oMatchesSelector ||
|
|
|
|
Element.prototype.webkitMatchesSelector ||
|
|
|
|
function (s) {
|
2016-11-25 09:21:50 -05:00
|
|
|
const matches = (this.document || this.ownerDocument).querySelectorAll(s);
|
|
|
|
let i = matches.length;
|
2016-11-25 07:13:12 -05:00
|
|
|
while (--i >= 0 && matches.item(i) !== this) {}
|
|
|
|
return i > -1;
|
|
|
|
};
|
|
|
|
}
|