/
polyfill.js
79 lines (70 loc) · 2.34 KB
/
polyfill.js
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
71
72
73
74
75
76
77
78
79
/**
* @fileoverview Polyfills included for Emojityper on non-module browsers.
*/
import '../../node_modules/core-js/modules/es6.string.starts-with';
import '../../node_modules/core-js/modules/es6.string.from-code-point';
import '../../node_modules/core-js/modules/es6.array.from';
import '../../node_modules/core-js/modules/es6.promise';
import '../../node_modules/core-js/modules/es6.symbol';
// IE11 CustomEvent
if (typeof window.CustomEvent !== 'function') {
function CustomEvent(name, params) {
params = params || {bubbles: false, cancelable: false, detail: undefined};
const event = document.createEvent('CustomEvent');
event.initCustomEvent(name, params.bubbles, params.cancelable, params.detail);
return event;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
}
// IE11 Element.remove
if (!Element.prototype.hasOwnProperty('remove')) {
Object.defineProperty(Element.prototype, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
this.parentNode && this.parentNode.removeChild(this);
},
});
}
// IE11 classList.toggle 2nd arg
const testEl = document.createElement('div');
testEl.classList.toggle('testClass', false);
if (testEl.classList.contains('testClass')) {
const original = DOMTokenList.prototype.toggle;
DOMTokenList.prototype.toggle = function(name, force) {
if (force === undefined) {
return original.call(this, name);
} else if (force) {
this.add(name);
} else {
this.remove(name);
}
return this.contains(name);
};
}
// IE11 Element.matches / Element.closest
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
let el = this;
if (!document.documentElement.contains(el)) {
return null;
}
do {
if (el.matches(s)) { return el; }
el = el.parentElement || el.parentNode;
} while (el && el.nodeType === 1);
return null;
};
}
// non-polyfill for window.fetch
if (!window.fetch) {
window.fetch = () => Promise.reject('unsupported');
}
// for async/await magic
// nb. this puts regeneratorRuntime into the top-level scope
import '../../node_modules/regenerator-runtime/runtime.js';