Fix missing polyfill on IE11

This commit is contained in:
jos 2019-03-14 21:21:19 +01:00
parent 92fbe410a3
commit a01ff4a892
3 changed files with 48 additions and 45 deletions

View File

@ -1,5 +1,7 @@
'use strict';
require('./polyfills');
var _locales = ['en', 'pt-BR', 'zh-CN', 'tr'];
var _defs = {
en: {

45
src/js/polyfills.js Normal file
View File

@ -0,0 +1,45 @@
if (typeof Element !== 'undefined') {
// Polyfill for array remove
(function () {
function polyfill (item) {
if (item.hasOwnProperty('remove')) {
return;
}
Object.defineProperty(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
if (this.parentNode != null)
this.parentNode.removeChild(this);
}
});
}
if (typeof Element !== 'undefined') { polyfill(Element.prototype); }
if (typeof CharacterData !== 'undefined') { polyfill(CharacterData.prototype); }
if (typeof DocumentType !== 'undefined') { polyfill(DocumentType.prototype); }
})();
}
// Polyfill for startsWith
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
// Polyfill for Array.find
if (!Array.prototype.find) {
Array.prototype.find = function(callback) {
for (var i = 0; i < this.length; i++) {
var element = this[i];
if ( callback.call(this, element, i, this) ) {
return element;
}
}
}
}

View File

@ -1,5 +1,6 @@
'use strict';
require('./polyfills');
var jsonlint = require('./assets/jsonlint/jsonlint');
var jsonMap = require('json-source-map');
var translate = require('./i18n').translate;
@ -1063,51 +1064,6 @@ exports.isValidColor = function (color) {
return !!exports.getColorCSS(color);
}
if (typeof Element !== 'undefined') {
// Polyfill for array remove
(function () {
function polyfill (item) {
if (item.hasOwnProperty('remove')) {
return;
}
Object.defineProperty(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
if (this.parentNode != null)
this.parentNode.removeChild(this);
}
});
}
if (typeof Element !== 'undefined') { polyfill(Element.prototype); }
if (typeof CharacterData !== 'undefined') { polyfill(CharacterData.prototype); }
if (typeof DocumentType !== 'undefined') { polyfill(DocumentType.prototype); }
})();
}
// Polyfill for startsWith
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
// Polyfill for Array.find
if (!Array.prototype.find) {
Array.prototype.find = function(callback) {
for (var i = 0; i < this.length; i++) {
var element = this[i];
if ( callback.call(this, element, i, this) ) {
return element;
}
}
}
}
/**
* Make a tooltip for a field based on the field's schema.
* @param {object} schema JSON schema