diff --git a/src/js/i18n.js b/src/js/i18n.js index d237d20..0ab0a08 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -1,5 +1,7 @@ 'use strict'; +require('./polyfills'); + var _locales = ['en', 'pt-BR', 'zh-CN', 'tr']; var _defs = { en: { diff --git a/src/js/polyfills.js b/src/js/polyfills.js new file mode 100644 index 0000000..b522cc4 --- /dev/null +++ b/src/js/polyfills.js @@ -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; + } + } + } +} diff --git a/src/js/util.js b/src/js/util.js index fa415a4..a0f2847 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -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