Shadow DOM
HTML
<music-player>
<span class="song">Rockstar Anthem</span>
<span class="artist">Hillary Argyle</span>
</music-player>
<music-player>
<span class="song">What's up</span>
<span class="artist">Zack Argyle</span>
</music-player>
<template id="musicPlayerTemplate">
<style>
.outer {
width: 350px;
font-family: Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.info {
background: #545454;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#545454), color-stop(100%,#212121));
background: -webkit-linear-gradient(top, #545454 0%,#212121 100%);
background: linear-gradient(to bottom, #545454 0%,#212121 100%);
padding: 1.5em;
text-align: center;
}
.song {
color: #FFFFFF;
font-size: 1.5em;
}
.artist {
margin-top: 0.5em;
color: #BABABA;
font-size: 0.9em;
}
.controls {
padding: 1em;
text-align: center;
background: #f7f7f7;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#e6e6e6));
background: -webkit-linear-gradient(top, #f7f7f7 0%,#e6e6e6 100%);
background: linear-gradient(to bottom, #f7f7f7 0%,#e6e6e6 100%);
}
button {
background: #f9f9f9;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f9f9f9), color-stop(100%,#d9d9d9));
background: -webkit-linear-gradient(top, #f9f9f9 0%,#d9d9d9 100%);
background: linear-gradient(to bottom, #f9f9f9 0%,#d9d9d9 100%);
border: 1px solid #BABABA;
border-radius: 3px;
font-size: 0.8em;
padding: 0.3em 0.6em;
cursor: pointer;
}
</style>
<div class="outer">
<div class="info">
<div class="song">
<content select=".song"></content>
</div>
<div class="artist">
...
JavaScript
var MPlayerProto = Object.create(HTMLElement.prototype);
MPlayerProto.createdCallback = function() {
var template = document.getElementById('musicPlayerTemplate');
var clone = document.importNode(template.content, true);
this.ceateShadowRoot().appendChild(clone);
};
document.registerElement('music-player', {prototype: MPlayerProto});