2017-08-27 15:31:34 +02:00
|
|
|
/**
|
|
|
|
* Polyfills for DOM API's
|
|
|
|
*/
|
|
|
|
|
2018-04-01 14:21:11 +02:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
|
2017-08-27 15:31:34 +02:00
|
|
|
if (!Element.prototype.matches) {
|
|
|
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
|
|
}
|
|
|
|
|
2018-04-01 14:21:11 +02:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
2017-08-27 15:31:34 +02: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;
|
|
|
|
};
|
|
|
|
}
|