Created
March 21, 2014 16:39
-
-
Save laat/9690328 to your computer and use it in GitHub Desktop.
Creating a custom element and polyfill css with Polymer platform.js
This file contains hidden or 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
| <script src="//cdnjs.cloudflare.com/ajax/libs/polymer/0.2.1/platform.js"></script> | |
| <x-foo red></x-foo> | |
| <template id="foo"> | |
| <style> | |
| :host[red] {background-color: red;} | |
| </style> | |
| foo | |
| </template> | |
| <script> | |
| var XFoo = function(){ | |
| var template = document.querySelector("#foo"); | |
| this.createShadowRoot(); | |
| this.shadowRoot.appendChild(template.content.cloneNode(true)); | |
| } | |
| XFoo.prototype = Object.create(HTMLElement.prototype); | |
| XFoo.prototype.createdCallback = XFoo | |
| XFoo = document.registerElement('x-foo', XFoo); | |
| if(Platform.ShadowCSS) { | |
| var frag = document.querySelector("#foo").content.cloneNode(true); | |
| Platform.ShadowCSS.shimStyling(frag, "x-foo", ""); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment