Skip to content

Commit

Permalink
fix(FEC-8530: element prepend is not supported on IE11 (#154)
Browse files Browse the repository at this point in the history
Add prepend polyfill.
  • Loading branch information
Dan Ziv committed Sep 12, 2018
1 parent 5cf4bf9 commit ec8dea2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/polyfills/all.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './performance-now';
import './prepend';
37 changes: 37 additions & 0 deletions src/common/polyfills/prepend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @flow
import PolyfillManager from './polyfill-manager';
import getLogger from '../utils/logger';

export default class PrependPolyfill {
static id: string = 'prepend';
static _logger: any = getLogger('PrependPolyfill');

static install(): void {
[Element.prototype, Document.prototype, DocumentFragment.prototype].forEach(function(item) {
if (item.hasOwnProperty('prepend')) {
PrependPolyfill._logger.debug('No need to install polyfill on item', item);
return;
}
PrependPolyfill._logger.debug('Installing polyfill on item', item);
// $FlowFixMe
Object.defineProperty(item, 'prepend', {
configurable: true,
enumerable: true,
writable: true,
value: function prepend() {
var argArr = Array.prototype.slice.call(arguments),
docFrag = document.createDocumentFragment();

argArr.forEach(function(argItem) {
var isNode = argItem instanceof Node;
docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
});

this.insertBefore(docFrag, this.firstChild);
}
});
});
}
}

PolyfillManager.register(PrependPolyfill);

0 comments on commit ec8dea2

Please sign in to comment.