Added a million IE11 polyfills...
This commit is contained in:
parent
011442bd7d
commit
8d66a79444
|
@ -1,7 +1,7 @@
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Deflates' the HTML contained in the given parent node.
|
* 'Deflates' the HTML contained in the given parent node.
|
||||||
* Deflation will completely drop empty text nodes, and replace
|
* Deflation will completely drop empty text nodes, and replace
|
||||||
* multiple spaces, tabs, newlines with a single space. This way,
|
* multiple spaces, tabs, newlines with a single space. This way,
|
||||||
* character offsets in the markup will more closely represent
|
* character offsets in the markup will more closely represent
|
||||||
|
@ -22,7 +22,7 @@ const deflateNodeList = parents => {
|
||||||
// Text node - trim
|
// Text node - trim
|
||||||
const trimmed = node.textContent.replace(/\s\s+/g, ' ');
|
const trimmed = node.textContent.replace(/\s\s+/g, ' ');
|
||||||
return [...compacted, document.createTextNode(trimmed)];
|
return [...compacted, document.createTextNode(trimmed)];
|
||||||
} else {
|
} else {
|
||||||
// Empty text node - discard
|
// Empty text node - discard
|
||||||
return compacted;
|
return compacted;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ const deflateNodeList = parents => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace original children with deflated
|
// Replace original children with deflated
|
||||||
parents.forEach(parent => {
|
parents.forEach(parent => {
|
||||||
const deflatedChildren = deflateOne(parent);
|
const deflatedChildren = deflateOne(parent);
|
||||||
parent.innerHTML = '';
|
parent.innerHTML = '';
|
||||||
deflatedChildren.forEach(node => parent.appendChild(node));
|
deflatedChildren.forEach(node => parent.appendChild(node));
|
||||||
|
@ -72,6 +72,27 @@ export const addPolyfills = () => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!String.prototype.startsWith) {
|
||||||
|
Object.defineProperty(String.prototype, 'startsWith', {
|
||||||
|
value: function(search, rawPos) {
|
||||||
|
var pos = rawPos > 0 ? rawPos|0 : 0;
|
||||||
|
return this.substring(pos, pos + search.length) === search;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.prototype.includes) {
|
||||||
|
String.prototype.includes = function(search, start) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (search instanceof RegExp) {
|
||||||
|
throw TypeError('first argument must not be a RegExp');
|
||||||
|
}
|
||||||
|
if (start === undefined) { start = 0; }
|
||||||
|
return this.indexOf(search, start) !== -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!Array.prototype.find) {
|
if (!Array.prototype.find) {
|
||||||
Object.defineProperty(Array.prototype, 'find', {
|
Object.defineProperty(Array.prototype, 'find', {
|
||||||
value: function(predicate) {
|
value: function(predicate) {
|
||||||
|
@ -79,23 +100,23 @@ export const addPolyfills = () => {
|
||||||
if (this == null) {
|
if (this == null) {
|
||||||
throw TypeError('"this" is null or not defined');
|
throw TypeError('"this" is null or not defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
var o = Object(this);
|
var o = Object(this);
|
||||||
|
|
||||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||||
var len = o.length >>> 0;
|
var len = o.length >>> 0;
|
||||||
|
|
||||||
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||||
if (typeof predicate !== 'function') {
|
if (typeof predicate !== 'function') {
|
||||||
throw TypeError('predicate must be a function');
|
throw TypeError('predicate must be a function');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
var thisArg = arguments[1];
|
var thisArg = arguments[1];
|
||||||
|
|
||||||
// 5. Let k be 0.
|
// 5. Let k be 0.
|
||||||
var k = 0;
|
var k = 0;
|
||||||
|
|
||||||
// 6. Repeat, while k < len
|
// 6. Repeat, while k < len
|
||||||
while (k < len) {
|
while (k < len) {
|
||||||
// a. Let Pk be ! ToString(k).
|
// a. Let Pk be ! ToString(k).
|
||||||
|
@ -109,14 +130,44 @@ export const addPolyfills = () => {
|
||||||
// e. Increase k by 1.
|
// e. Increase k by 1.
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return undefined.
|
// 7. Return undefined.
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: true
|
writable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof Object.assign !== 'function') {
|
||||||
|
// Must be writable: true, enumerable: false, configurable: true
|
||||||
|
Object.defineProperty(Object, "assign", {
|
||||||
|
value: function assign(target, varArgs) { // .length of function is 2
|
||||||
|
'use strict';
|
||||||
|
if (target === null || target === undefined) {
|
||||||
|
throw new TypeError('Cannot convert undefined or null to object');
|
||||||
|
}
|
||||||
|
|
||||||
|
var to = Object(target);
|
||||||
|
|
||||||
|
for (var index = 1; index < arguments.length; index++) {
|
||||||
|
var nextSource = arguments[index];
|
||||||
|
|
||||||
|
if (nextSource !== null && nextSource !== undefined) {
|
||||||
|
for (var nextKey in nextSource) {
|
||||||
|
// Avoid bugs when hasOwnProperty is shadowed
|
||||||
|
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
||||||
|
to[nextKey] = nextSource[nextKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return to;
|
||||||
|
},
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -135,4 +186,4 @@ export const setLocale = locale => {
|
||||||
console.warn(`Unsupported locale '${l}'. Falling back to default en.`);
|
console.warn(`Unsupported locale '${l}'. Falling back to default en.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue