Skip to content

Instantly share code, notes, and snippets.

@tuespetre
Created October 21, 2016 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuespetre/ed3f314bf0c8959fe560d14931b81624 to your computer and use it in GitHub Desktop.
Save tuespetre/ed3f314bf0c8959fe560d14931b81624 to your computer and use it in GitHub Desktop.
Allows you to use templates for custom elements in IE11. Wrote this to be able to use webcomponents/shadycss
(function (document) {
if ('content' in document.createElement('template')) {
return;
}
Object.defineProperty(HTMLUnknownElement.prototype, 'content', {
enumerable: false,
configurable: true,
get: function() {
if (this.localName !== 'template') {
return;
}
if (!this._content) {
this._content = document.createDocumentFragment();
for (var i = 0; i < this.childNodes.length; i++) {
this._content.appendChild(this.childNodes[i].cloneNode(true));
}
}
return this._content;
}
});
})(window.document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment