]> BookStack Code Mirror - bookstack/blob - resources/assets/js/services/dom-polyfills.js
Add "register" to nav.
[bookstack] / resources / assets / js / services / dom-polyfills.js
1 /**
2  * Polyfills for DOM API's
3  */
4
5 // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
6 if (!Element.prototype.matches) {
7     Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
8 }
9
10 // https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
11 if (!Element.prototype.closest) {
12     Element.prototype.closest = function (s) {
13         var el = this;
14         var ancestor = this;
15         if (!document.documentElement.contains(el)) return null;
16         do {
17             if (ancestor.matches(s)) return ancestor;
18             ancestor = ancestor.parentElement;
19         } while (ancestor !== null);
20         return null;
21     };
22 }