From 3c39b3149fc51bb7637a27b192d6f244467fcf0f Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Mon, 28 Jan 2019 16:21:21 -0500 Subject: [PATCH] replace prepend() calls since they aren't supported in IE11 --- src/components/modebar/modebar.js | 2 +- src/lib/index.js | 13 +++++++++++++ test/jasmine/assets/unpolyfill.js | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/modebar/modebar.js b/src/components/modebar/modebar.js index b351a2946aa..3b12931a19d 100644 --- a/src/components/modebar/modebar.js +++ b/src/components/modebar/modebar.js @@ -88,7 +88,7 @@ proto.update = function(graphInfo, buttons) { } if(fullLayout.modebar.orientation === 'v') { - this.element.prepend(logoGroup); + Lib.prependElement(this.element, logoGroup); } else { this.element.appendChild(logoGroup); } diff --git a/src/lib/index.js b/src/lib/index.js index a28a4a31a4f..64e9d80517b 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -689,6 +689,19 @@ lib.removeElement = function(el) { if(elParent) elParent.removeChild(el); }; +lib.prependElement = function(el) { + var argArr = Array.prototype.slice.call(arguments); + argArr.splice(0, 1); + var docFrag = document.createDocumentFragment(); + + argArr.forEach(function(argItem) { + var isNode = argItem instanceof Node; + docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); + }); + + el.insertBefore(docFrag, el.firstChild); +}; + /** * for dynamically adding style rules * makes one stylesheet that contains all rules added diff --git a/test/jasmine/assets/unpolyfill.js b/test/jasmine/assets/unpolyfill.js index 821a732ce5a..15bf14ff3a8 100644 --- a/test/jasmine/assets/unpolyfill.js +++ b/test/jasmine/assets/unpolyfill.js @@ -18,5 +18,17 @@ ].join(' ')); } }); + + Object.defineProperty(item, 'prepend', { + configurable: true, + enumerable: true, + writable: true, + value: function remove() { + throw Error([ + 'test/jasmine/assets/unpolyfill.js error: calling ChildNode.prepend()', + 'which is not available in IE.' + ].join(' ')); + } + }); }); })([Element.prototype, CharacterData.prototype, DocumentType.prototype]);