Skip to content

Instantly share code, notes, and snippets.

@ipetropolsky
Created April 23, 2014 16:18
Show Gist options
  • Save ipetropolsky/11221972 to your computer and use it in GitHub Desktop.
Save ipetropolsky/11221972 to your computer and use it in GitHub Desktop.
Web Components

Web Components

Define a declarative "API" using insertion points:

<element name="my-tabs" constructor="TabsController">
  <template>
    <style>...</style>
    <content select="hgroup:first-child"></content>
  </template>
  <script>
    TabsController.prototype = {
      doSomething: function() { ... }
    };
  </script>
</element>

Include and use it:

<my-tabs>
  <hgroup>
    <h2>Title</h2>
    ...
  </hgroup>
</my-tabs>

Declared constructor goes on global scope:

<script>
  var tabs = new TabsController();
  tabs.addEventListener('click', function(e) {
    e.target.doSomething();
  });
  document.body.appendChild(tabs);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment