|
36 | 36 | this.takeAttributes();
|
37 | 37 | // add event listeners
|
38 | 38 | 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 |
40 | 41 | preparingElements++;
|
41 | 42 | // process declarative resources
|
42 | 43 | this.parseDeclarations(this.__proto__);
|
| 44 | + // decrement semaphore |
43 | 45 | preparingElements--;
|
44 | 46 | // user entry point
|
45 | 47 | this.ready();
|
|
88 | 90 | },
|
89 | 91 | // parse input <element> as needed, override for custom behavior
|
90 | 92 | 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 | + } |
92 | 101 | },
|
93 | 102 | // return a shadow-root template (if desired), override for custom behavior
|
94 | 103 | fetchTemplate: function(elementElement) {
|
|
117 | 126 | return root;
|
118 | 127 | }
|
119 | 128 | },
|
| 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 | + }, |
120 | 145 | shadowRootReady: function(root, template) {
|
121 | 146 | // locate nodes with id and store references to them in this.$ hash
|
122 | 147 | this.marshalNodeReferences(root);
|
|
0 commit comments