On Github Abrissirba / WebComponentsDemo
var shadow = document.querySelector('#nameTag').createShadowRoot(); var template = document.querySelector('#nameTagTemplate'); document.querySelector('#nameTag').textContent = 'Bob'; var clone = document.importNode(template.content, true); shadow.appendChild(clone);
var NameTagPrototype = Object.create(HTMLElement.prototype); NameTagPrototype.attributeChangedCallback = function (attributeName, oldVal, newVal) { if (attributeName == "name") { this.shadowRoot.querySelector(".name").textContent = newVal; } }; NameTagPrototype.createdCallback = function () { var t = document.querySelector('#nameTagTemplate'); var clone = document.importNode(t.content, true); clone.querySelector(".name").textContent = this.getAttribute("name") || ""; this.createShadowRoot().appendChild(clone); }; var NameTagPrototype = document.registerElement('name-tag', { prototype: NameTagPrototype });
Imports external resources such as custom elements and templates
Polyfill libraries exists that makes it available in other browsers
e.g. Polymer and X-tags