polyfill-service
Version:
A polyfill combinator
27 lines (23 loc) • 892 B
JavaScript
Document.prototype.before = Element.prototype.before = function before() {
if (this.parentNode) {
var args = Array.prototype.slice.call(arguments),
viablePreviousSibling = this.previousSibling,
idx = viablePreviousSibling ? args.indexOf(viablePreviousSibling) : -1;
while (idx !== -1) {
viablePreviousSibling = viablePreviousSibling.previousSibling;
if (!viablePreviousSibling) {
break;
}
idx = args.indexOf(viablePreviousSibling);
}
this.parentNode.insertBefore(
_mutation(arguments),
viablePreviousSibling ? viablePreviousSibling.nextSibling : this.parentNode.firstChild
);
}
};
// Not all UAs support the Text constructor. Polyfill on the Text constructor only where it exists
// TODO: Add a polyfill for the Text constructor, and make it a dependency of this polyfill.
if ("Text" in this) {
Text.prototype.before = Element.prototype.before;
}