Skip to content

Instantly share code, notes, and snippets.

@sorvell
Created October 1, 2013 01:53
Show Gist options
  • Save sorvell/6772909 to your computer and use it in GitHub Desktop.
Save sorvell/6772909 to your computer and use it in GitHub Desktop.
Binding to style using polyfill
<!doctype html>
<html>
<head>
<title>bind simple</title>
<script src="../../../polymer/polymer.js"></script>
</head>
<body>
<x-foo width="100"></x-foo>
<x-foo width="200"></x-foo>
<polymer-element name="x-foo" attributes="width">
<template>
<style>
div {
border: 1px solid black;
width: {{width}}px;
}
/* polyfill specific rule */
/* @polyfill-rule
@host[id={{id}}] div {
border: 1px solid black;
width: {{width}}px;
}
*/
</style>
<div>{{width}}</div>
</template>
<script>
(function() {
var id = 0;
Polymer('x-foo', {
width: '',
ready: function() {
// use an id to scope styling to this instance
this.id = this.localName + ++id;
},
registerCallback: function(declaration) {
// add shimmedStyles to this instance
if (window.ShadowDOMPolyfill) {
var content = declaration.templateContent();
content.insertBefore(content.shimmedStyle, content.firstChild);
}
}
});
})();
</script>
</polymer-element>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment