Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created June 9, 2014 01:43
Show Gist options
  • Save shadowmint/6a403e153eda41f368a9 to your computer and use it in GitHub Desktop.
Save shadowmint/6a403e153eda41f368a9 to your computer and use it in GitHub Desktop.
component
<!-- hello-flomp component -->
<link rel="import" href="hello-gallery.html"/> <!-- Oo, we're using a subcomponent -->
<template id="hello_flomp"> <!-- Look a designer friendly template -->
<style> <!-- With encapsulated styles.... -->
hello-flomp > div {
border : 2px solid #000;
}
</style>
<div>
<span>
This is a FLOMP
</span>
<hello-gallery></hello-gallery>
</div>
</template>
<script> <!-- And the script to run it~ -->
(function() {
var component_id = 'hello_flomp';
var component_name = 'hello-flomp';
console.log('Loading component: ' + component_name);
var owner = document._currentScript.ownerDocument;
var tmpl = owner.getElementById(component_id);
var prototype = Object.create(HTMLElement.prototype);
prototype.createdCallback = function () {
var root = this.createShadowRoot();
var clone = document.importNode(tmpl.content, true)
root.appendChild(clone);
};
document.registerElement(component_name, {
prototype: prototype
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment