Skip to content

Commit

Permalink
support stamping template into lightDOM instead of ShadowDOM when pol…
Browse files Browse the repository at this point in the history
…ymer-element has `lightdom` attribute (ref #222)
  • Loading branch information
Scott J. Miles committed Oct 3, 2013
1 parent 02ec2fd commit d8d0a4d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/instance/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
this.takeAttributes();
// add event listeners
this.addHostListeners();
// guarantees that while preparing, any sub-elements will also be prepared
// guarantees that while preparing, any
// sub-elements are also prepared
preparingElements++;
// process declarative resources
this.parseDeclarations(this.__proto__);
// decrement semaphore
preparingElements--;
// user entry point
this.ready();
Expand Down Expand Up @@ -88,7 +90,14 @@
},
// parse input <element> as needed, override for custom behavior
parseDeclaration: function(elementElement) {
this.shadowFromTemplate(this.fetchTemplate(elementElement));
var template = this.fetchTemplate(elementElement);
if (template) {
if (this.element.hasAttribute('lightdom')) {
this.lightFromTemplate(template);
} else {
this.shadowFromTemplate(template);
}
}
},
// return a shadow-root template (if desired), override for custom behavior
fetchTemplate: function(elementElement) {
Expand Down Expand Up @@ -117,6 +126,22 @@
return root;
}
},
// utility function that stamps a <template> into light-dom
lightFromTemplate: function(template) {
if (template) {
// stamp template
// which includes parsing and applying MDV bindings before being
// inserted (to avoid {{}} in attribute values)
// e.g. to prevent <img src="images/{{icon}}"> from generating a 404.
var dom = this.instanceTemplate(template);
// append to shadow dom
this.appendChild(dom);
// perform post-construction initialization tasks on ahem, light root
this.shadowRootReady(this, template);
// return the created shadow root
return dom;
}
},
shadowRootReady: function(root, template) {
// locate nodes with id and store references to them in this.$ hash
this.marshalNodeReferences(root);
Expand Down

0 comments on commit d8d0a4d

Please sign in to comment.