SlideShare a Scribd company logo
© 2014 Orchard Harvest Redmond – WA - 2014
Future of Widgets?
Web Components, Polymer and Orchard
Steve Taylor - Avastec
© 2014 Orchard Harvest Redmond – WA - 2014
Ch 14: Adding Behaviors and HTML Components
© 2014 Orchard Harvest Redmond – WA - 2014
“Element behaviors are one of the most
significant new capabilities in Microsoft
Internet Explorer 5.5.
They provide the capability to define custom
elements, which can be used in the same way
as normal HTML elements in a Web page. “
source: MDSN - About Element Behaviors
© 2014 Orchard Harvest Redmond – WA - 2014
HTML Components Example
<public:component tagname="checkers">
<public:property name="boardWidth" />
<public:method name="newGame()" />
<public:attach event="onmouseover" onevent="mouseover()" />
</public:component>
<script language="Javascript">
function newGame() {
// insert code to initialize a new game here
}
function mouseover() {
// insert code to handle mouseover events
}
</script>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
ASP.NET Server Controls
<asp:button runat="server" id="Button1" />
ASP.NET
<input type="button" id="Button1" />
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
AngularJS Directives
<script>
var app = angular.module('myapp', []);
app.directive('helloWorld', function () {
return {
restrict: 'E',
replace: 'true',
template: '<h3>Hello World!</h3>'
};
});
</script>
JavaScript
<hello-world /> HTML
<h3>Hello World!</h3> HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Web Components
© 2014 Orchard Harvest Redmond – WA - 2014
“Web Components comprises of a set of
emerging standards which are aimed at
making encapsulated and reusable HTML
widgets or components.”
© 2014 Orchard Harvest Redmond – WA - 2014
In a nutshell...
<awesome-button text="Pure Awesome!"></awesome-button>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Bootstrap Carousel
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
...
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="..." alt="...">
<div class="carousel-caption">
...
</div>
</div>
...
</div>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Custom Carousel Element
<my-carousel indicators="true">
<my-slide>...</my-slide>
<my-slide>...</my-slide>
<my-slide>...</my-slide>
</my-carousel>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Web Components consist of:
Custom Elements, which let authors define their own elements,
with new tag names and new script interfaces.
HTML Templates, which define chunks of markup that are inert
but can be activated for use later.
Shadow DOM, which encapsulates a DOM subtree for more
reliable composition of user interface elements.
HTML Imports, which defines how templates and custom
elements are packaged and loaded as a resource.
© 2014 Orchard Harvest Redmond – WA - 2014
Custom Elements
© 2014 Orchard Harvest Redmond – WA - 2014
Creating Custom Elements
var awesomeButton = document.registerElement('awesome-button');
// Registered elements become a HTMLElement instead of a HTMLUnknownElement
JavaScript
<element name="awesome-button" constructor="awesomeButton">
...
</element>
HTML
<awesome-button></awesome-button>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Extending Existing Elements
var awesomeButton = document.registerElement('awesome-button', {
prototype: Object.create(HTMLButtonElement.prototype)
});
JavaScript
<element name="awesome-button" extends="button" constructor="awesomeButton">
...
</element>
HTML
<button is="awesome-button"></button>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Lifecycle Event Callbacks
createdCallback
attachedCallback
detachedCallback
attributeChangedCallback(attrName, oldVal, newVal)
© 2014 Orchard Harvest Redmond – WA - 2014
HTML Templates
© 2014 Orchard Harvest Redmond – WA - 2014
Declaring a Template
<template>
<button>Pure Awesome!</button>
</template>
HTML
Parsed but not rendered
Scripts not executed
Media not loaded or played
Hidden from main document
© 2014 Orchard Harvest Redmond – WA - 2014
Using a Template
<element name="awesome-button">
<template>
<button>Pure Awesome!</button>
</template>
<script>...</script>
</element>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Shadow DOM
© 2014 Orchard Harvest Redmond – WA - 2014
Using Shadow DOM
<awesome-button>
#document-fragment
<button>Pure Awesome!</button>
</awesome-button>
Composed Element
<awesome-button>...</awesome-button>
<script>
var shadow = document.querySelector('awesome-button').createShadowRoot();
shadow.innerHTML = '<button>Pure Awesome!</button>';
</script>
Custom Element
© 2014 Orchard Harvest Redmond – WA - 2014
Shadow DOM is All Around Us
© 2014 Orchard Harvest Redmond – WA - 2014
Using Shadow DOM with Templates
<element name="awesome-button">
<template>
<style>
:host {
background-color: red;
}
</style>
<button>Pure Awesome!</button>
</template>
<script>
var template = document.querySelector('template');
this.register({ prototype: {
createdCallback: function() {
this.createShadowRoot().appendChild(template.content.cloneNode(true));
}
}});
</script>
</element>
Custom Element
© 2014 Orchard Harvest Redmond – WA - 2014
HTML Imports
© 2014 Orchard Harvest Redmond – WA - 2014
Using HTML Imports
<!DOCTYPE html>
<html>
<head>
<link rel="import" href="awesome-button.html" />
</head>
<body>
<awesome-button text="Pure Awesome!"></awesome-button>
</body>
</html>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
Importing Inside Your Element
<link rel="import" href="awesome-tooltip.html" />
<element name="awesome-button">
<template>
<button id="my-button">Pure Awesome!</button>
<awesome-tooltip target="my-button">
<span>Press the button to see some awesomeness</span>
</awesome-tooltip>
</template>
...
</element>
awesome-button.html
© 2014 Orchard Harvest Redmond – WA - 2014
Current Browser Support
© 2014 Orchard Harvest Redmond – WA - 2014
© 2014 Orchard Harvest Redmond – WA - 2014
Layers of Polymer
© 2014 Orchard Harvest Redmond – WA - 2014
Layers of Polymer
Native
The current browser landscape
© 2014 Orchard Harvest Redmond – WA - 2014
Layers of Polymer
Native
The current browser landscape
Platform
Web Components polyfills for all
Modern browsers
© 2014 Orchard Harvest Redmond – WA - 2014
Layers of Polymer
Native
The current browser landscape
Platform
Web Components polyfills for all
Modern browsers
Polymer
An opinionated way to work with Web
Components
© 2014 Orchard Harvest Redmond – WA - 2014
Layers of Polymer
Native
The current browser landscape
Platform
Web Components polyfills for all
Modern browsers
Polymer
An opinionated way to work with Web
Components
Elements
Reusable custom elements (in progress)
© 2014 Orchard Harvest Redmond – WA - 2014
Why use Polymer?
Less boilerplate code
Simple element registration
Declarative databinding
Declarative event mapping
Published attributes
Change watchers
Automatic node finding
© 2014 Orchard Harvest Redmond – WA - 2014
Polymer Example
<link rel="import" href="polymer.html" />
<polymer-element name="awesome-button">
<template>
...
</template>
</polymer-element>
awesome-button.html
<script src="platform.min.js"></script>
<link rel="import" href="awesome-button.html" />
<awesome-button></awesome-button>
HTML
© 2014 Orchard Harvest Redmond – WA - 2014
DEMO
© 2014 Orchard Harvest Redmond – WA - 2014
Special thanks to…
Eric Bidelman, Rob Dodson, Addy Osmani, Matthew McNulty
….and the rest of the Polymer team
© 2014 Orchard Harvest Redmond – WA - 2014
Thanks!
Twitter: @stevetayloruk
LinkedIn: linkedin.com/in/stevetayloruk
Github: github.com/stevetayloruk

More Related Content

PDF
Web Components & Polymer 1.0 (Webinale Berlin)
Hendrik Ebbers
 
PDF
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
PDF
Unlock the next era of UI design with Polymer
Rob Dodson
 
PDF
AtlasCamp 2015: Web technologies you should be using now
Atlassian
 
PDF
AtlasCamp 2015: Connect everywhere - Cloud and Server
Atlassian
 
PDF
Course CodeSchool - Shaping up with Angular.js
Vinícius de Moraes
 
PDF
243329387 angular-docs
Abhi166803
 
PDF
Polymer & the web components revolution 6:25:14
mattsmcnulty
 
Web Components & Polymer 1.0 (Webinale Berlin)
Hendrik Ebbers
 
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
Unlock the next era of UI design with Polymer
Rob Dodson
 
AtlasCamp 2015: Web technologies you should be using now
Atlassian
 
AtlasCamp 2015: Connect everywhere - Cloud and Server
Atlassian
 
Course CodeSchool - Shaping up with Angular.js
Vinícius de Moraes
 
243329387 angular-docs
Abhi166803
 
Polymer & the web components revolution 6:25:14
mattsmcnulty
 

What's hot (20)

PDF
The Road to Native Web Components
Mike North
 
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PDF
Intro to html 5
Ian Jasper Mangampo
 
PPTX
Google Polymer Introduction
David Price
 
PDF
Experience Manager 6 Developer Features - Highlights
Cédric Hüsler
 
PDF
Polymer, A Web Component Polyfill Library
naohito maeda
 
PPTX
Learn html and css from scratch
Mohd Manzoor Ahmed
 
DOCX
Adding a view
Nhan Do
 
PDF
Chrome enchanted 2015
Chang W. Doh
 
PDF
Web Components Everywhere
Ilia Idakiev
 
PPTX
Apex & jQuery Mobile
Christian Rokitta
 
PPTX
Angular Js Get Started - Complete Course
EPAM Systems
 
PDF
Why you should be using Web Components. And How - DevWeek 2015
Phil Leggetter
 
PDF
Polytechnic 1.0 Granada
Israel Blancas
 
PDF
Building Progressive Web Apps for Android and iOS
FITC
 
PPTX
Angular js PPT
Imtiyaz Ahmad Khan
 
PPTX
Intro to AngularJs
SolTech, Inc.
 
PDF
Web Components + Backbone: a Game-Changing Combination
Andrew Rota
 
PDF
AngularJS: an introduction
Luigi De Russis
 
PPTX
Angular JS
John Temoty Roca
 
The Road to Native Web Components
Mike North
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
Intro to html 5
Ian Jasper Mangampo
 
Google Polymer Introduction
David Price
 
Experience Manager 6 Developer Features - Highlights
Cédric Hüsler
 
Polymer, A Web Component Polyfill Library
naohito maeda
 
Learn html and css from scratch
Mohd Manzoor Ahmed
 
Adding a view
Nhan Do
 
Chrome enchanted 2015
Chang W. Doh
 
Web Components Everywhere
Ilia Idakiev
 
Apex & jQuery Mobile
Christian Rokitta
 
Angular Js Get Started - Complete Course
EPAM Systems
 
Why you should be using Web Components. And How - DevWeek 2015
Phil Leggetter
 
Polytechnic 1.0 Granada
Israel Blancas
 
Building Progressive Web Apps for Android and iOS
FITC
 
Angular js PPT
Imtiyaz Ahmad Khan
 
Intro to AngularJs
SolTech, Inc.
 
Web Components + Backbone: a Game-Changing Combination
Andrew Rota
 
AngularJS: an introduction
Luigi De Russis
 
Angular JS
John Temoty Roca
 
Ad

Viewers also liked (20)

PDF
Square Pitch Deck
Vishal Kumar
 
PDF
500’s Demo Day Batch 16 >> Podozi
500 Startups
 
PPTX
AdPushup Fundraising Deck - First Pitch
adpushup
 
PDF
AppVirality.com - Investor Pitch Deck
Laxman Papineni
 
PDF
SteadyBudget's Seed Funding Pitch Deck
Shape Integrated Software
 
PDF
How Wealthsimple raised $2M in 2 weeks
Wealthsimple
 
PDF
Zenpayroll Pitch Deck Template
Joseph Hsieh
 
PPT
The 10 most interesting slides that helped our SaaS company raise 9 million
GoCanvas
 
PDF
The deck we used to raise $270k for our startup Castle
entercastle
 
PDF
Swipes pitch deck for Beta Pitch 2013 Finals in Berlin
Swipes App
 
PPTX
The Deck We Used to Raise $1M Seed Round
Ben Lang
 
PDF
Manpacks
500 Startups
 
PDF
Dwolla Startup Pitch Deck
Joseph Hsieh
 
PDF
The investor presentation we used to raise 2 million dollars
Mikael Cho
 
PDF
Linkedin Series B Pitch Deck
Joseph Hsieh
 
PPTX
Foursquare's 1st Pitch Deck
Rami Al-Karmi
 
PDF
Fittr Pitch Deck
nolanperk
 
PDF
Sequoia Capital Pitch Deck Template
Malcolm Lewis
 
PDF
Mint.com Pre-Launch Pitch Deck
Hiten Shah
 
PDF
Mixpanel - Our pitch deck that we used to raise $65M
Suhail Doshi
 
Square Pitch Deck
Vishal Kumar
 
500’s Demo Day Batch 16 >> Podozi
500 Startups
 
AdPushup Fundraising Deck - First Pitch
adpushup
 
AppVirality.com - Investor Pitch Deck
Laxman Papineni
 
SteadyBudget's Seed Funding Pitch Deck
Shape Integrated Software
 
How Wealthsimple raised $2M in 2 weeks
Wealthsimple
 
Zenpayroll Pitch Deck Template
Joseph Hsieh
 
The 10 most interesting slides that helped our SaaS company raise 9 million
GoCanvas
 
The deck we used to raise $270k for our startup Castle
entercastle
 
Swipes pitch deck for Beta Pitch 2013 Finals in Berlin
Swipes App
 
The Deck We Used to Raise $1M Seed Round
Ben Lang
 
Manpacks
500 Startups
 
Dwolla Startup Pitch Deck
Joseph Hsieh
 
The investor presentation we used to raise 2 million dollars
Mikael Cho
 
Linkedin Series B Pitch Deck
Joseph Hsieh
 
Foursquare's 1st Pitch Deck
Rami Al-Karmi
 
Fittr Pitch Deck
nolanperk
 
Sequoia Capital Pitch Deck Template
Malcolm Lewis
 
Mint.com Pre-Launch Pitch Deck
Hiten Shah
 
Mixpanel - Our pitch deck that we used to raise $65M
Suhail Doshi
 
Ad

Similar to Orchard Harvest 2014 - The Future of Widgets? (20)

PDF
Polymer
jskvara
 
PDF
Web Components for Java Developers
Joonas Lehtinen
 
PPTX
Web Components: back to the future
DA-14
 
PDF
Polymer Code Lab in Dart - DevFest Kraków 2014
jskvara
 
PDF
Polymer - pleasant client-side programming with web components
psstoev
 
PDF
Web Components and Modular CSS
Andrew Rota
 
PDF
Web components - An Introduction
cherukumilli2
 
PPTX
Web Components: Web back to future.
GlobalLogic Ukraine
 
PDF
Александр Кашеверов - Polymer
DataArt
 
PPTX
Polymer and web component
Imam Raza
 
PDF
The Complementarity of React and Web Components
Andrew Rota
 
PDF
A brave new web - A talk about Web Components
Michiel De Mey
 
PDF
Devoxx 2014-webComponents
Cyril Balit
 
PDF
Michael North "The Road to Native Web Components"
Fwdays
 
PPTX
Polymer
LearningTech
 
PDF
Angular JS2 Training Session #2
Paras Mendiratta
 
PDF
Web Components: The future of Web Application Development
Jermaine Oppong
 
PPSX
Introduction to Html5
www.netgains.org
 
PDF
Web Components
Nikolaus Graf
 
PDF
Desbravando Web Components
Mateus Ortiz
 
Polymer
jskvara
 
Web Components for Java Developers
Joonas Lehtinen
 
Web Components: back to the future
DA-14
 
Polymer Code Lab in Dart - DevFest Kraków 2014
jskvara
 
Polymer - pleasant client-side programming with web components
psstoev
 
Web Components and Modular CSS
Andrew Rota
 
Web components - An Introduction
cherukumilli2
 
Web Components: Web back to future.
GlobalLogic Ukraine
 
Александр Кашеверов - Polymer
DataArt
 
Polymer and web component
Imam Raza
 
The Complementarity of React and Web Components
Andrew Rota
 
A brave new web - A talk about Web Components
Michiel De Mey
 
Devoxx 2014-webComponents
Cyril Balit
 
Michael North "The Road to Native Web Components"
Fwdays
 
Polymer
LearningTech
 
Angular JS2 Training Session #2
Paras Mendiratta
 
Web Components: The future of Web Application Development
Jermaine Oppong
 
Introduction to Html5
www.netgains.org
 
Web Components
Nikolaus Graf
 
Desbravando Web Components
Mateus Ortiz
 

Recently uploaded (20)

PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Software Development Methodologies in 2025
KodekX
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 

Orchard Harvest 2014 - The Future of Widgets?

  • 1. © 2014 Orchard Harvest Redmond – WA - 2014 Future of Widgets? Web Components, Polymer and Orchard Steve Taylor - Avastec
  • 2. © 2014 Orchard Harvest Redmond – WA - 2014 Ch 14: Adding Behaviors and HTML Components
  • 3. © 2014 Orchard Harvest Redmond – WA - 2014 “Element behaviors are one of the most significant new capabilities in Microsoft Internet Explorer 5.5. They provide the capability to define custom elements, which can be used in the same way as normal HTML elements in a Web page. “ source: MDSN - About Element Behaviors
  • 4. © 2014 Orchard Harvest Redmond – WA - 2014 HTML Components Example <public:component tagname="checkers"> <public:property name="boardWidth" /> <public:method name="newGame()" /> <public:attach event="onmouseover" onevent="mouseover()" /> </public:component> <script language="Javascript"> function newGame() { // insert code to initialize a new game here } function mouseover() { // insert code to handle mouseover events } </script> HTML
  • 5. © 2014 Orchard Harvest Redmond – WA - 2014 ASP.NET Server Controls <asp:button runat="server" id="Button1" /> ASP.NET <input type="button" id="Button1" /> HTML
  • 6. © 2014 Orchard Harvest Redmond – WA - 2014 AngularJS Directives <script> var app = angular.module('myapp', []); app.directive('helloWorld', function () { return { restrict: 'E', replace: 'true', template: '<h3>Hello World!</h3>' }; }); </script> JavaScript <hello-world /> HTML <h3>Hello World!</h3> HTML
  • 7. © 2014 Orchard Harvest Redmond – WA - 2014 Web Components
  • 8. © 2014 Orchard Harvest Redmond – WA - 2014 “Web Components comprises of a set of emerging standards which are aimed at making encapsulated and reusable HTML widgets or components.”
  • 9. © 2014 Orchard Harvest Redmond – WA - 2014 In a nutshell... <awesome-button text="Pure Awesome!"></awesome-button> HTML
  • 10. © 2014 Orchard Harvest Redmond – WA - 2014 Bootstrap Carousel <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> ... </ol> <div class="carousel-inner"> <div class="item active"> <img src="..." alt="..."> <div class="carousel-caption"> ... </div> </div> ... </div> <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="right carousel-control" href="#carousel-example-generic" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> HTML
  • 11. © 2014 Orchard Harvest Redmond – WA - 2014 Custom Carousel Element <my-carousel indicators="true"> <my-slide>...</my-slide> <my-slide>...</my-slide> <my-slide>...</my-slide> </my-carousel> HTML
  • 12. © 2014 Orchard Harvest Redmond – WA - 2014 Web Components consist of: Custom Elements, which let authors define their own elements, with new tag names and new script interfaces. HTML Templates, which define chunks of markup that are inert but can be activated for use later. Shadow DOM, which encapsulates a DOM subtree for more reliable composition of user interface elements. HTML Imports, which defines how templates and custom elements are packaged and loaded as a resource.
  • 13. © 2014 Orchard Harvest Redmond – WA - 2014 Custom Elements
  • 14. © 2014 Orchard Harvest Redmond – WA - 2014 Creating Custom Elements var awesomeButton = document.registerElement('awesome-button'); // Registered elements become a HTMLElement instead of a HTMLUnknownElement JavaScript <element name="awesome-button" constructor="awesomeButton"> ... </element> HTML <awesome-button></awesome-button> HTML
  • 15. © 2014 Orchard Harvest Redmond – WA - 2014 Extending Existing Elements var awesomeButton = document.registerElement('awesome-button', { prototype: Object.create(HTMLButtonElement.prototype) }); JavaScript <element name="awesome-button" extends="button" constructor="awesomeButton"> ... </element> HTML <button is="awesome-button"></button> HTML
  • 16. © 2014 Orchard Harvest Redmond – WA - 2014 Lifecycle Event Callbacks createdCallback attachedCallback detachedCallback attributeChangedCallback(attrName, oldVal, newVal)
  • 17. © 2014 Orchard Harvest Redmond – WA - 2014 HTML Templates
  • 18. © 2014 Orchard Harvest Redmond – WA - 2014 Declaring a Template <template> <button>Pure Awesome!</button> </template> HTML Parsed but not rendered Scripts not executed Media not loaded or played Hidden from main document
  • 19. © 2014 Orchard Harvest Redmond – WA - 2014 Using a Template <element name="awesome-button"> <template> <button>Pure Awesome!</button> </template> <script>...</script> </element> HTML
  • 20. © 2014 Orchard Harvest Redmond – WA - 2014 Shadow DOM
  • 21. © 2014 Orchard Harvest Redmond – WA - 2014 Using Shadow DOM <awesome-button> #document-fragment <button>Pure Awesome!</button> </awesome-button> Composed Element <awesome-button>...</awesome-button> <script> var shadow = document.querySelector('awesome-button').createShadowRoot(); shadow.innerHTML = '<button>Pure Awesome!</button>'; </script> Custom Element
  • 22. © 2014 Orchard Harvest Redmond – WA - 2014 Shadow DOM is All Around Us
  • 23. © 2014 Orchard Harvest Redmond – WA - 2014 Using Shadow DOM with Templates <element name="awesome-button"> <template> <style> :host { background-color: red; } </style> <button>Pure Awesome!</button> </template> <script> var template = document.querySelector('template'); this.register({ prototype: { createdCallback: function() { this.createShadowRoot().appendChild(template.content.cloneNode(true)); } }}); </script> </element> Custom Element
  • 24. © 2014 Orchard Harvest Redmond – WA - 2014 HTML Imports
  • 25. © 2014 Orchard Harvest Redmond – WA - 2014 Using HTML Imports <!DOCTYPE html> <html> <head> <link rel="import" href="awesome-button.html" /> </head> <body> <awesome-button text="Pure Awesome!"></awesome-button> </body> </html> HTML
  • 26. © 2014 Orchard Harvest Redmond – WA - 2014 Importing Inside Your Element <link rel="import" href="awesome-tooltip.html" /> <element name="awesome-button"> <template> <button id="my-button">Pure Awesome!</button> <awesome-tooltip target="my-button"> <span>Press the button to see some awesomeness</span> </awesome-tooltip> </template> ... </element> awesome-button.html
  • 27. © 2014 Orchard Harvest Redmond – WA - 2014 Current Browser Support
  • 28. © 2014 Orchard Harvest Redmond – WA - 2014
  • 29. © 2014 Orchard Harvest Redmond – WA - 2014 Layers of Polymer
  • 30. © 2014 Orchard Harvest Redmond – WA - 2014 Layers of Polymer Native The current browser landscape
  • 31. © 2014 Orchard Harvest Redmond – WA - 2014 Layers of Polymer Native The current browser landscape Platform Web Components polyfills for all Modern browsers
  • 32. © 2014 Orchard Harvest Redmond – WA - 2014 Layers of Polymer Native The current browser landscape Platform Web Components polyfills for all Modern browsers Polymer An opinionated way to work with Web Components
  • 33. © 2014 Orchard Harvest Redmond – WA - 2014 Layers of Polymer Native The current browser landscape Platform Web Components polyfills for all Modern browsers Polymer An opinionated way to work with Web Components Elements Reusable custom elements (in progress)
  • 34. © 2014 Orchard Harvest Redmond – WA - 2014 Why use Polymer? Less boilerplate code Simple element registration Declarative databinding Declarative event mapping Published attributes Change watchers Automatic node finding
  • 35. © 2014 Orchard Harvest Redmond – WA - 2014 Polymer Example <link rel="import" href="polymer.html" /> <polymer-element name="awesome-button"> <template> ... </template> </polymer-element> awesome-button.html <script src="platform.min.js"></script> <link rel="import" href="awesome-button.html" /> <awesome-button></awesome-button> HTML
  • 36. © 2014 Orchard Harvest Redmond – WA - 2014 DEMO
  • 37. © 2014 Orchard Harvest Redmond – WA - 2014 Special thanks to… Eric Bidelman, Rob Dodson, Addy Osmani, Matthew McNulty ….and the rest of the Polymer team
  • 38. © 2014 Orchard Harvest Redmond – WA - 2014 Thanks! Twitter: @stevetayloruk LinkedIn: linkedin.com/in/stevetayloruk Github: github.com/stevetayloruk