Skip to content

Commit

Permalink
replace prepend() calls since they aren't supported in IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Jan 28, 2019
1 parent e94ee3d commit 3c39b31
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/jasmine/assets/unpolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

0 comments on commit 3c39b31

Please sign in to comment.