My goal is to learn to wire up events in a custom element to members of the custom template.
This builds the custom element as part of the index.html file.
After much frustration I finally got it to work under Chrome and node-webkit.
The I tried to cut and paste the code into a separate file and use link-import to
load that file. Well it does not work.
I have tried many many ways to get a clone of the template so that the clone can be added to the shadowRoot.
The failure is occurring in the createdCallback routine that was attached the modified prototype that was
passed to the document.registerEvent call.
It is in the createdCallback routine that I also attempt to link the listeners to the buttons. It never
get that far.
Consequently none of the elements appear in the main document (other than unresolved).
here is the script I pasted into the import dataset:
----------------------------------------------------------------------------------
<template id='column-item'>
<style scoped>
.ci-empty
{
font-family: courier;
font-style: normal;
font-weight: normal;
color: black;
background-color: white;
padding: 5px;
border: 0px;
}
.ci-selected
{
font-family: courier;
font-style: normal;
font-weight: normal;
color: black;
background-color: yellow;
padding: 5px;
border: 0px;
}
</style>
<input id='col_data' type="text" class="ci-empty" placeholder='yes'></input>
<input id='my_btn' type='button' value='click it'></input>
</template>
<script>
var p = Object.create(HTMLElement.prototype);
var showInDom = function()
{
var shadow = this.createShadowRoot();
this._root = shadow;
var template = document.querySelector('column-item');
var clone = template.content.cloneNode(true);
shadow.appendChild(clone);
// initial_listeners(shadow);
};
p.createdCallback = showInDom;
p.attachedCallback = function()
{
};
p.detachedCallback = function()
{
};
document.registerElement('column-item',{prototype: p});
</script>
--------------------------------------------------------------------------------------------------------------
I am using node-webkit for this debugging. It is quicker than chrome inspect.
(I have tried document.$.<element_name>. This does not work!)
The link-import works - I have removed "console.log" lines that I use for debugging.
I can see their messages in the develop
Any help is appreciated.