Created
October 1, 2013 01:53
-
-
Save sorvell/6772909 to your computer and use it in GitHub Desktop.
Binding to style using polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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