Added a million IE11 polyfills...
This commit is contained in:
parent
011442bd7d
commit
8d66a79444
|
@ -1,7 +1,7 @@
|
|||
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
|
||||
* multiple spaces, tabs, newlines with a single space. This way,
|
||||
* character offsets in the markup will more closely represent
|
||||
|
@ -22,7 +22,7 @@ const deflateNodeList = parents => {
|
|||
// Text node - trim
|
||||
const trimmed = node.textContent.replace(/\s\s+/g, ' ');
|
||||
return [...compacted, document.createTextNode(trimmed)];
|
||||
} else {
|
||||
} else {
|
||||
// Empty text node - discard
|
||||
return compacted;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ const deflateNodeList = parents => {
|
|||
}
|
||||
|
||||
// Replace original children with deflated
|
||||
parents.forEach(parent => {
|
||||
parents.forEach(parent => {
|
||||
const deflatedChildren = deflateOne(parent);
|
||||
parent.innerHTML = '';
|
||||
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) {
|
||||
Object.defineProperty(Array.prototype, 'find', {
|
||||
value: function(predicate) {
|
||||
|
@ -79,23 +100,23 @@ export const addPolyfills = () => {
|
|||
if (this == null) {
|
||||
throw TypeError('"this" is null or not defined');
|
||||
}
|
||||
|
||||
|
||||
var o = Object(this);
|
||||
|
||||
|
||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||
var len = o.length >>> 0;
|
||||
|
||||
|
||||
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||
if (typeof predicate !== 'function') {
|
||||
throw TypeError('predicate must be a function');
|
||||
}
|
||||
|
||||
|
||||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
var thisArg = arguments[1];
|
||||
|
||||
|
||||
// 5. Let k be 0.
|
||||
var k = 0;
|
||||
|
||||
|
||||
// 6. Repeat, while k < len
|
||||
while (k < len) {
|
||||
// a. Let Pk be ! ToString(k).
|
||||
|
@ -109,14 +130,44 @@ export const addPolyfills = () => {
|
|||
// e. Increase k by 1.
|
||||
k++;
|
||||
}
|
||||
|
||||
|
||||
// 7. Return undefined.
|
||||
return undefined;
|
||||
},
|
||||
configurable: 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.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue