-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpolyfills.js
More file actions
70 lines (63 loc) · 2.26 KB
/
polyfills.js
File metadata and controls
70 lines (63 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Polyfills for older browsers, most notably IE11.
//
// Use polyfills-loader.js before the Patternslib bundle to conditionally load
// the polyfills for Internet Explorer:
//
// <script src="polyfills-loader.js" type="text/javascript"></script>
// Core JS features
// You can also import individual core-js features:
// import "core-js/stable/object/assign";
// But we're importing them all:
import "core-js/stable";
// Web APIs
import "intersection-observer";
import "promise-polyfill/src/polyfill";
import "url-polyfill";
import "whatwg-fetch";
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
import "./core/polyfills";
if ("ResizeObserver" in window === false) {
window.ResizeObserver = ResizeObserverPolyfill;
}
// Node.closest polyfill
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#polyfill
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function (s) {
var el = this;
do {
if (Element.prototype.matches.call(el, s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}
// END Node.closest polyfill
if (!document.currentScript) {
var scripts = document.getElementsByTagName("script");
document.currentScript = scripts.length && scripts[scripts.length - 1];
}
// Node.remove polyfill
// From: https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove#polyfill
// From: https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
arr.forEach(function (item) {
// eslint-disable-next-line no-prototype-builtins
if (item.hasOwnProperty("remove")) {
return;
}
Object.defineProperty(item, "remove", {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
this.parentNode.removeChild(this);
},
});
});
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
// END Node.remove polyfill
// input.labels polyfill