Polymers are large molecules, created of many subunits, and together they can compose larger elements that are fundamental to biological structure and function.
This is exactly the idea behind Polymer. To create custom HTML elements, as encapsulated, reusable components that work across desktop and mobile. To achieve this, Polymer uses the latest web technologies, such as Web Components, Shadow DOM, HTML templates and imports.
14. new HTML/DOM elements
declarative, readable, meaningful HTML
common way to extend -> reusable
@paylogic
custom elements
PyGrunn | July 08, 2014
14
15. @paylogic PyGrunn | July 08, 2014
w/o custom elements
15
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap") ,mapProp);
}
!
google.maps.event.addDomListener(window, 'load', initialize);
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
16. @paylogic PyGrunn | July 08, 2014
w/ custom elements
16
<google-map> and <google-map-marker> are custom elements available at
http://googlewebcomponents.github.io/
<google-map lat="51.508742" lng="-0.120850"></google-map>
!
!
<google-map>
<google-mam-marker
lat="51.508742"
lng="-0.120850"
title="work"
draggable="true">
</google-map-marker>
</google-mam>
maintainable
meaningful
17. UI and Non-UI (utility) elements
@paylogic PyGrunn | July 08, 2014
custom elements
17
<core-ajax></core-ajax>
!
!
<polymer-ui-card></polymer-ui-card>
18. DOM -> Integrated interoperability
accessibilitydevtools support
PyGrunn | July 08, 2014@paylogic
18
19. – Dimitri Glazkov
“Custom elements is a bedrock
API. We should be able to build
all HTML elements with it.”
@paylogic PyGrunn | July 08, 2014
19
20. @paylogic PyGrunn | July 08, 2014
templates
PyGrunn | July 08, 2014@paylogic
21. templates
used to be…
hacky, pushing around strings, XSS vulnerable
now :)
template tag, use DOM (not strings)
content is inert, parsed, not rendered
#document-fragment (not part of the page)
@paylogic PyGrunn | July 08, 2014
21
22. templates
Polymer implements data-binding to make
template more powerful
@paylogic PyGrunn | July 08, 2014
22
<template>
<input type="text" value="{{name}}">
<input type="submit" value="submit">
</template>
23. @paylogic PyGrunn | July 08, 2014
shadow DOM
PyGrunn | July 08, 2014@paylogic
24. shadow DOM
DOM/CSS composability and scoping
design apps in small chunks
guarantees that things are protected
@paylogic PyGrunn | July 08, 2014
24
25. shadow DOM
@paylogic PyGrunn | July 08, 2014
25
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/
Bob will appear in <content>
<div id="nameTag">Bob</div>
!
<template id="nameTagTemplate">
<style>
/* ... */
</style>
<div class="outer">
<div class="boilerplate">
Hi! My name is
</div>
<div class="name">
<content></content>
</div>
</div>
</template>
!
<script>
var shadow = document.querySelector('#nameTag').createShadowRoot();
var template = document.querySelector('#nameTagTemplate');
shadow.appendChild(template.content.cloneNode());
</script>
26. @paylogic PyGrunn | July 08, 2014
html imports
PyGrunn | July 08, 2014@paylogic
27. html imports
loading and dependency management
find existing elements that solve your problem
import it, and just use it
example (bundle HTML/CSS/JS)
<script> does not block main page
supports async attribute
@paylogic PyGrunn | July 08, 2014
27
28. html imports
@paylogic PyGrunn | July 08, 2014
28
<!-- Use bootstrap.html that includes all the related files. -->
<head>
<link rel="import" href="bootstrap.html">
</head>
!
!
<!-- bootstrap.html -->
<link rel="stylesheet" href="bootstrap.css">
<link rel="stylesheet" href="fonts.css">
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
<script src="bootstrap-tooltip.js"></script>
<script src="bootstrap-dropdown.js"></script>
<!-- ... -->
!
<!-- scaffolding markup -->
<template>
<!-- ... -->
</template>
http://www.html5rocks.com/en/tutorials/webcomponents/imports/
35. polymer
foundation (platform.js polyfills)
building blocks (APIs eventually become native in
browsers)
support of web components for all modern
browsers
core (polymer.js, helpers)
elements
UI and non-UI components built on core
@paylogic PyGrunn | July 08, 2014
35
47. material design.
use Polymer to create building blocks which work
with a new design language.
polymer-project.org/tools/designer/
@paylogic PyGrunn | July 08, 2014
47
48. who uses it
@paylogic PyGrunn | July 08, 2014
Rietveld restyle (by Google)
polymer-project.org
chromestatus.com
polymer-designer
github (<local-time>)
48
50. A library that leverages web components and enables
developers to create reusable elements for a scalable,
interoperable, and composable future of the web platform.
So, what is Polymer?
“