736d7118b0
Still work to be done but a good start in standardisation.
22 lines
No EOL
721 B
JavaScript
22 lines
No EOL
721 B
JavaScript
/**
|
|
* Polyfills for DOM API's
|
|
*/
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
|
|
if (!Element.prototype.matches) {
|
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
}
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
|
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;
|
|
};
|
|
} |