Skip to content

Instantly share code, notes, and snippets.

@phlco
Created July 7, 2016 01:50
Show Gist options
  • Save phlco/b8c19f0c32f84db72087c02b92052799 to your computer and use it in GitHub Desktop.
Save phlco/b8c19f0c32f84db72087c02b92052799 to your computer and use it in GitHub Desktop.
custom element template
<template>
<style>
</style>
</template>
<script>
var doc = document.currentScript.ownerDocument;
var ElementPrototype = Object.create(HTMLElement.prototype);
ElementPrototype.createdCallback = function() {
var shadow = this.createShadowRoot();
var template = doc.querySelector('template');
var clone = template.content.cloneNode(true);
shadow.appendChild(clone);
};
var Element = document.registerElement('custom-element', {
prototype: ElementPrototype
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment