mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-29 04:10:09 +08:00
736d7118b0
Still work to be done but a good start in standardisation.
22 lines
721 B
JavaScript
22 lines
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;
|
|
};
|
|
} |