Skip to content

Commit d8d0a4d

Browse files
author
Scott J. Miles
committed
support stamping template into lightDOM instead of ShadowDOM when polymer-element has lightdom attribute (ref #222)
1 parent 02ec2fd commit d8d0a4d

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/instance/base.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
this.takeAttributes();
3737
// add event listeners
3838
this.addHostListeners();
39-
// guarantees that while preparing, any sub-elements will also be prepared
39+
// guarantees that while preparing, any
40+
// sub-elements are also prepared
4041
preparingElements++;
4142
// process declarative resources
4243
this.parseDeclarations(this.__proto__);
44+
// decrement semaphore
4345
preparingElements--;
4446
// user entry point
4547
this.ready();
@@ -88,7 +90,14 @@
8890
},
8991
// parse input <element> as needed, override for custom behavior
9092
parseDeclaration: function(elementElement) {
91-
this.shadowFromTemplate(this.fetchTemplate(elementElement));
93+
var template = this.fetchTemplate(elementElement);
94+
if (template) {
95+
if (this.element.hasAttribute('lightdom')) {
96+
this.lightFromTemplate(template);
97+
} else {
98+
this.shadowFromTemplate(template);
99+
}
100+
}
92101
},
93102
// return a shadow-root template (if desired), override for custom behavior
94103
fetchTemplate: function(elementElement) {
@@ -117,6 +126,22 @@
117126
return root;
118127
}
119128
},
129+
// utility function that stamps a <template> into light-dom
130+
lightFromTemplate: function(template) {
131+
if (template) {
132+
// stamp template
133+
// which includes parsing and applying MDV bindings before being
134+
// inserted (to avoid {{}} in attribute values)
135+
// e.g. to prevent <img src="images/{{icon}}"> from generating a 404.
136+
var dom = this.instanceTemplate(template);
137+
// append to shadow dom
138+
this.appendChild(dom);
139+
// perform post-construction initialization tasks on ahem, light root
140+
this.shadowRootReady(this, template);
141+
// return the created shadow root
142+
return dom;
143+
}
144+
},
120145
shadowRootReady: function(root, template) {
121146
// locate nodes with id and store references to them in this.$ hash
122147
this.marshalNodeReferences(root);

0 commit comments

Comments
 (0)