2017-08-27 09:31:34 -04:00
|
|
|
/**
|
|
|
|
* Polyfills for DOM API's
|
|
|
|
*/
|
|
|
|
|
2018-04-01 08:21:11 -04:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
|
2017-08-27 09:31:34 -04:00
|
|
|
if (!Element.prototype.matches) {
|
|
|
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
|
|
}
|
|
|
|
|
2018-04-01 08:21:11 -04:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
2017-08-27 09:31:34 -04:00
|
|
|
if (!Element.prototype.closest) {
|
|
|
|
Element.prototype.closest = function (s) {
|
|
|
|
var el = this;
|
|
|
|
var ancestor = this;
|
|
|
|
if (!document.documentElement.contains(el)) return null;
|
|
|
|
do {
|
|
|
|
if (ancestor.matches(s)) return ancestor;
|
|
|
|
ancestor = ancestor.parentElement;
|
|
|
|
} while (ancestor !== null);
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
}
|