Skip to content

Instantly share code, notes, and snippets.

@laat
Created March 21, 2014 16:39
Show Gist options
  • Select an option

  • Save laat/9690328 to your computer and use it in GitHub Desktop.

Select an option

Save laat/9690328 to your computer and use it in GitHub Desktop.
Creating a custom element and polyfill css with Polymer platform.js
<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