Julián Duque
Developer and Educator
Julián David Duque
Developer by Passion
var MyElement = document.registerElement('my-element');
// or document.createElement
<my-element></my-element>
http://w3c.github.io/webcomponents/spec/custom/<link rel="import" href="my-widget.html">
<my-widget></my-widget>
http://w3c.github.io/webcomponents/spec/imports/<template>
<div>
Template content
</div>
</template>
http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting.html#the-template-element<style>
my-element {
display: block;
}
my-element > div {
border: solid 1px #ccc;
}
</style>
<my-element>
<div>Box with border</div>
</my-element>
var shadow = el.createShadowRoot();
shadow.innerHTML = "<style> span { color: orange }</style>"
+ "<span>Hello :)</span>";
http://w3c.github.io/webcomponents/spec/shadow/<!-- Polyfill for older browsers -->
<script src="bower_components/platform/platform.js"></script>
<!-- HTML Import component -->
<link rel="import" href="bower_components/google-map/google-map.html">
<!-- Use Component -->
<google-map latitude="6.2670502" longitude="-75.5839547" zoom="15"></google-map>
<polymer-element name="hello-world" attributes="who">
<template>
<p>Hello <strong>{{who}}</strong></p>
</template>
<script>
Polymer('hello-world', {
who: 'World'
});
</script>
</polymer-element>
<polymer-element name="my-counter" attributes="counter">
<template>
<style> /*...*/ </style>
<div id="label"><content></content></div>
Value: <span id="counterVal">{{counter}}</span><br>
<button on-tap="{{increment}}">Increment</button>
</template>
<script>
Polymer({
counter: 0, // Default value
counterChanged: function() {
this.$.counterVal.classList.add('highlight');
},
increment: function() {
this.counter++;
}
});
</script>
</polymer-element>
http://www.polymer-project.org/docs/elements/
http://www.polymer-project.org/docs/elements/paper-elements.html
By Julián Duque