From efad7270b7eebf97522200eab38457495ea7245a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 3 Apr 2020 16:56:46 +0100 Subject: [PATCH] Add polyfills for IE11 --- Gruntfile.js | 1 + .../editor-client/src/js/polyfills.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 packages/node_modules/@node-red/editor-client/src/js/polyfills.js diff --git a/Gruntfile.js b/Gruntfile.js index b2da4a514..b6474182a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -125,6 +125,7 @@ module.exports = function(grunt) { src: [ // Ensure editor source files are concatenated in // the right order + "packages/node_modules/@node-red/editor-client/src/js/polyfills.js", "packages/node_modules/@node-red/editor-client/src/js/jquery-addons.js", "packages/node_modules/@node-red/editor-client/src/js/red.js", "packages/node_modules/@node-red/editor-client/src/js/events.js", diff --git a/packages/node_modules/@node-red/editor-client/src/js/polyfills.js b/packages/node_modules/@node-red/editor-client/src/js/polyfills.js new file mode 100644 index 000000000..1a7caf121 --- /dev/null +++ b/packages/node_modules/@node-red/editor-client/src/js/polyfills.js @@ -0,0 +1,34 @@ +(function() { + var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; + + if (isIE11) { + // IE11 does not provide classList on SVGElements + if (! ("classList" in SVGElement.prototype)) { + Object.defineProperty(SVGElement.prototype, 'classList', Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'classList')); + } + + // IE11 does not provide children on SVGElements + if (! ("children" in SVGElement.prototype)) { + Object.defineProperty(SVGElement.prototype, 'children', Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'children')); + } + + if (!Array.from) { + // JSONata provides an Array.from polyfill that doesn't handle iterables. + // So in IE11 we expect Array.from to exist already, it just needs some + // changes to support iterables. + throw new Error("Missing Array.from base polyfill"); + } + Array._from = Array.from; + Array.from = function() { + var arrayLike = arguments[0] + if (arrayLike.forEach) { + var result = []; + arrayLike.forEach(function(i) { + result.push(i); + }) + return result; + } + return Array._from.apply(null,arguments); + } + } +})();