Skip to content

Instantly share code, notes, and snippets.

@vogtm
Created July 17, 2014 14:37
Show Gist options
  • Save vogtm/bee227189e8d5d3383b2 to your computer and use it in GitHub Desktop.
Save vogtm/bee227189e8d5d3383b2 to your computer and use it in GitHub Desktop.
Playing around with web components
<!DOCTYPE html>
<html>
<head>
<title>web components</title>
<style type="text/css">
html{
font-family:"Courier New", Courier, monospace;
color: blue;
}
</style>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<template id="template">
<p>I'm in Shadow DOM</p>
</template>
<script type="text/javascript">
var proto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
var t = document.querySelector('#template');
var clone = document.importNode(t.content, true);
this.createShadowRoot().appendChild(clone);
}
}
});
document.registerElement('x-myownBlock', {prototype: proto});
</script>
<x-myownBlock></x-myownBlock>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment