polyfill-service
Version:
A polyfill combinator
24 lines (20 loc) • 776 B
JavaScript
Document.prototype.after = Element.prototype.after = function after() {
if (this.parentNode) {
var args = Array.prototype.slice.call(arguments),
viableNextSibling = this.nextSibling,
idx = viableNextSibling ? args.indexOf(viableNextSibling) : -1;
while (idx !== -1) {
viableNextSibling = viableNextSibling.nextSibling;
if (!viableNextSibling) {
break;
}
idx = args.indexOf(viableNextSibling);
}
this.parentNode.insertBefore(_mutation(arguments), viableNextSibling);
}
};
// 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.after = Element.prototype.after;
}