Skip to content

Instantly share code, notes, and snippets.

@arv
Forked from sorvell/gist:6527156
Created September 11, 2013 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arv/6528418 to your computer and use it in GitHub Desktop.
Save arv/6528418 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="../polymer/polymer.js"></script>
</head>
<body>
<template id="host-template">
<div>host shadowRoot</div>
<content></content>
</template>
<template id="inner-host-template">
<div>inner-host shadowRoot</div>
</template>
<x-host>
<x-inner-host></x-inner-host>
</x-host>
<script>
var xHostProto = Object.create(HTMLElement.prototype);
xHostProto.createdCallback = function() {
this.createShadowRoot();
this.shadowRoot.appendChild(document.querySelector('#host-template').createInstance());
// no problem without template
// this.shadowRoot.innerHTML = '<div>host shadowRoot</div><content></content>';
}
var xInnerHostProto = Object.create(HTMLElement.prototype);
xInnerHostProto.createdCallback = function() {
this.createShadowRoot();
this.shadowRoot.appendChild(document.querySelector('#inner-host-template').createInstance());
// no problem without template
// this.shadowRoot.innerHTML = '<div>inner-host shadowRoot</div>';
}
// no problem without custom elements
// document.register('x-host', {prototype: xHostProto});
// document.register('x-inner-host', {prototype: xInnerHostProto});
xHostProto.createdCallback.call(document.querySelector('x-host'));
xInnerHostProto.createdCallback.call(document.querySelector('x-inner-host'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment