diff --git a/HISTORY.md b/HISTORY.md index 8f464d6..91e8562 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,8 @@ https://github.com/josdejong/jsoneditor in `text` and `code` mode. - Implemented repairing JSON objects containing special white space characters like non-breaking space. +- Fixed #481: A polyfill required `DocumentType` which is not defined + in all environments. ## 2017-09-16, version 5.9.6 diff --git a/src/js/util.js b/src/js/util.js index 90b4d27..ed7e42a 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -872,8 +872,8 @@ exports.getInputSelection = function(el) { if (typeof Element !== 'undefined') { // Polyfill for array remove - (function (arr) { - arr.forEach(function (item) { + (function () { + function polyfill (item) { if (item.hasOwnProperty('remove')) { return; } @@ -886,8 +886,12 @@ if (typeof Element !== 'undefined') { this.parentNode.removeChild(this); } }); - }); - })([Element.prototype, CharacterData.prototype, DocumentType.prototype]); + } + + if (typeof Element !== 'undefined') { polyfill(Element.prototype); } + if (typeof CharacterData !== 'undefined') { polyfill(CharacterData.prototype); } + if (typeof DocumentType !== 'undefined') { polyfill(DocumentType.prototype); } + })(); }