Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebComponents LT at AQ

WebComponents LT at AQ

Yoshihiro Iwanaga

August 29, 2013
Tweet

More Decks by Yoshihiro Iwanaga

Other Decks in Programming

Transcript

  1. What is WebComponents? Provides mechanism for the declaration of markup

    prototype. (W3C Working Draft) Makes reusing and composing HTML components much easier J
  2. The component model for the WebComponents 1. Templates 2. Decorators

    3. Custom Elements 4. Shadow DOM 5. Imports
  3. insert template to DOM var t = document.getElementById('t'); var clone

    = t.content.cloneNode(true); clone.querySelector('h2').textContent = 'テキスト'; clone.querySelector('img').src = 'image.png'; clone.querySelector('figcaption').textContent = 'キャプション'; document.body.appendChild(clone); <template id="t"> <div> <h2>デフォルトテキスト</h2> <figure> <img alt="image"> <figcaption>キャプション</figcaption> <button>イイネ!</button> </figure> </div> </template>
  4. Shadow DOM <div id="target"></div> <script> document.addEventListener("DOMContentLoaded", function(){ /* not supported

    */ //var shadow = document.getElementById("target”) .createShadowRoot(); /* deprecated. Webkit Only */ //var shadow = new WebKitShadowRoot( document.getElementById("target")); /* Webkit Only */ var shadow = document.getElementById("target") .webkitCreateShadowRoot(); shadow.innerHTML = '<h2>this is shadow tree</h2>' + '<img src="image.jpg">'; }, false); </script>
  5. <script> document.addEventListener("DOMContentLoaded", function(){ /* not supported */ //var shadow =

    document.getElementById("target”) .createShadowRoot(); /* Webkit Only */ var shadow = document.getElementById("target") .webkitCreateShadowRoot(); /* resetStyleInheritance */ shadow.resetStyleInheritance = true; shadow.innerHTML = '<h2>this is shadow tree</h2>' + '<img src="image.jpg">'; }, false); </script> Preventing the CSS inheritance