mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Refactored js file structure to be standard throughout app
Still work to be done but a good start in standardisation.
This commit is contained in:
22
resources/assets/js/services/dom-polyfills.js
Normal file
22
resources/assets/js/services/dom-polyfills.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user