@preset-sdk/embedded
Version:
Frontend SDK for embedding Preset data analytics into your own application
39 lines (32 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.applyReplaceChildrenPolyfill = applyReplaceChildrenPolyfill;
function applyReplaceChildrenPolyfill() {
(function (prototype) {
// If the prototype already has a replaceChildren method, skip it
if (prototype.hasOwnProperty('replaceChildren')) {
return;
} // Otherwise, define a new replaceChildren method on the prototype
Object.defineProperty(prototype, 'replaceChildren', {
configurable: true,
enumerable: true,
// The replaceChildren method takes any number of arguments
value: function () {
// Remove all existing child nodes
while (this.firstChild) {
this.removeChild(this.firstChild);
} // Add the new child nodes
for (var _len = arguments.length, nodes = new Array(_len), _key = 0; _key < _len; _key++) {
nodes[_key] = arguments[_key];
}
nodes.forEach(node => {
// If the node is a string, create a new text node
// Otherwise, assume it's a DOM element and use it directly
this.appendChild(typeof node === 'string' ? document.createTextNode(node) : node);
});
}
});
})(Element.prototype);
}