Carsten Sandtner (@casarock) - Frontend Rhein-Main 06/2014
Carsten Sandtner // @casarock
Head of Development at //mediaman GmbH
Mozilla rep
<script type="text/x-template">
<div>Mycontent!</div>
</script>
or
<div style="display:none">
Here be content
</div>
<template>
<div><p>whoop whoop</p></div>
</template>
<template id="my-template">
<div>Awesome Template Text</div>
</template>
var t = document.getElementById('my-template');
document.body.appendChild(t.content.cloneNode());
var myElement = document.registerElement('awesome-element');
// or document.createElement(..)
<awesome-element></awesome-element>
Because everything is an element!
Wouldn't it be cool if...
<my-carousel id="myid">
<div>Slide 1</div>
<div>Slide 2</div>
...
</my-carousel>
Indeed - But logic??
var myAwesomeCarousel = Object.create(HTMLElement.prototype);
myAwesomeCarousel.next = function() {
// Code...
};
myAwesomeCarousel.previous = function() {
// Code...
};
// Register carousel element with its default prototype
var MyCarousel = document.registerElement('my-carousel', {
prototype: myAwesomeCarousel
});
// Instantiate a carousel and add to dom.
var myCarousel = document.createElement('my-carousel');
document.body.appendChild(myCarousel);
We want to reuse our Custom Elements (and more...), right?
<link rel="import" href="plugin.html">
var link = document.querySelector('link[rel="import"]');
var content = link.import;
var el = content.querySelector('.someclass');
document.body.appendChild(el.cloneNode(true));
“Brick is a bundle of reusable UI components created to enable rapid development of cross-browser and mobile-friendly HTML5 web applications.”
And could be extended by own components
<x-calendar></x-calendar>
<x-flipbox id="flipbox-custom">
<img width="208" height="303" src="images/Card_back.png">
<img width="208" height="303" src="images/Card_front.png">
</x-flipbox>
myflipBox.addEventListener("click", function(){
flipBox.toggle();
});
<x-layout>
<x-appbar><h2>Super awesome headline!</h2></x-appbar>
<x-deck selected-index="0">
<x-card id="card1">
I'm Card 1!
</x-card>
<x-card id="card2">
I'm Card 2!
</x-card>
</x-deck>
<x-tabbar>
<x-tabbar-tab target-selector="#card1">1</x-tabbar-tab>
<x-tabbar-tab target-selector="#card2">2</x-tabbar-tab>
</x-tabbar>
</x-layout>
.. Bricks!
Later!
Download Brick: https://github.com/mozilla/brick/
Add CSS and JS to your project
...
<link rel="stylesheet" href="../lib/css/brick.min.css">
...
...
<script src="../lib/js/brick.min.js"></script>
...
Step 1: Register your Brick
(function() {
xtag.register('my-brick', {
lifecycle: {
created: function() {
this.innerHTML = 'I am a brick';
}
}
});
})();
Step 2: Add events and methods to your Brick
(function() {
xtag.register('my-brick', {
// ...
events: {
'tap': function(e) {
this.style.backgroundColor =
'#' + Math.round(0xFFFFFF * Math.random())
.toString(16);
}
},
methods: {
colorful: function() {
this.style.backgroundColor =
'#' + Math.round(0xFFFFFF * Math.random())
.toString(16);
}
}
});
})();
Your very own brick!
The result
A collection of templates to kickstart app development
Go, stack your App. Now! ;)
Mozilla delivers the bricks ... ... and mortar
Carsten Sandtner
@casarock