Presentation about Web Components used during the DOT 2014. You can find information about Templates, Custom Elements, Shadow DOM and HTML imports the technologies behind the Web Components.
una <template>.</div> <_script_>alert('Grazie!')</_script_> </template> function useIt() { var t = document.querySelector('#my-template'); var clone = document.importNode(t.content, true); document.querySelector('#container').appendChild(clone); }
provengo da una <template>.</p> </template> var proto = Object.create(HTMLElement.prototype, { createdCallback: { value: function() { var t = document.querySelector('#my-template'); var clone = document.importNode(t.content, true); this.appendChild(clone); } } }); document.registerElement('my-tag', { prototype: proto });
<my-tag>Nicola</my-tag> <template id="my-template"> <p>Ciao <content></content>. Sono nello Shadow DOM di <my-tag> e provengo da una & </template> var proto = Object.create(HTMLElement.prototype, { createdCallback: { value: function() { var t = document.querySelector('#my-template'); var clone = document.importNode(t.content, true); this.createShadowRoot().appendChild(clone); } } }); document.registerElement('my-tag', { prototype: proto }); p { color: orange; }
<my-tag> e provengo da una & </template> var importDoc = document.currentScript.ownerDocument; var proto = Object.create(HTMLElement.prototype, { createdCallback: { value: function() { var t = importDoc.querySelector('#my-template'); var clone = document.importNode(t.content, true); this.createShadowRoot().appendChild(clone); } } }); document.registerElement('my-tag', { prototype: proto }); <head> <link rel="import" href="shadow-dom-for-import.html"> </head> <body> <my-tag>Nicola</my-tag> </body>