| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of template_binding; | 5 part of template_binding; |
| 6 | 6 |
| 7 /** Extensions to [Element]s that behave as templates. */ | 7 /** Extensions to [Element]s that behave as templates. */ |
| 8 class TemplateBindExtension extends _ElementExtension { | 8 class TemplateBindExtension extends _ElementExtension { |
| 9 var _model; | 9 var _model; |
| 10 BindingDelegate _bindingDelegate; | 10 BindingDelegate _bindingDelegate; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 DocumentFragment createInstance([model, BindingDelegate delegate, | 109 DocumentFragment createInstance([model, BindingDelegate delegate, |
| 110 List<NodeBinding> bound]) { | 110 List<NodeBinding> bound]) { |
| 111 var ref = templateBind(this.ref); | 111 var ref = templateBind(this.ref); |
| 112 var content = ref.content; | 112 var content = ref.content; |
| 113 // Dart note: we store _bindingMap on the TemplateBindExtension instead of | 113 // Dart note: we store _bindingMap on the TemplateBindExtension instead of |
| 114 // the "content" because we already have an expando for it. | 114 // the "content" because we already have an expando for it. |
| 115 var map = ref._bindingMap; | 115 var map = ref._bindingMap; |
| 116 if (map == null) { | 116 if (map == null) { |
| 117 // TODO(rafaelw): Setup a MutationObserver on content to detect | 117 // TODO(rafaelw): Setup a MutationObserver on content to detect |
| 118 // when the instanceMap is invalid. | 118 // when the instanceMap is invalid. |
| 119 map = new _InstanceBindingMap(content, delegate); | 119 map = _createInstanceBindingMap(content, delegate); |
| 120 ref._bindingMap = map; | 120 ref._bindingMap = map; |
| 121 } | 121 } |
| 122 | 122 |
| 123 var staging = _getTemplateStagingDocument(); | 123 var staging = _getTemplateStagingDocument(); |
| 124 var instance = _deepCloneIgnoreTemplateContent(content, staging); | 124 var instance = _deepCloneIgnoreTemplateContent(content, staging); |
| 125 | 125 |
| 126 _addMapBindings(instance, map, model, delegate, bound); | 126 _addMapBindings(instance, map, model, delegate, bound); |
| 127 // TODO(rafaelw): We can do this more lazily, but setting a sentinel | 127 // TODO(rafaelw): We can do this more lazily, but setting a sentinel |
| 128 // in the parent of the template element, and creating it when it's | 128 // in the parent of the template element, and creating it when it's |
| 129 // asked for by walking back to find the iterating template. | 129 // asked for by walking back to find the iterating template. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 node = node.parentNode; | 440 node = node.parentNode; |
| 441 } | 441 } |
| 442 | 442 |
| 443 // Note: JS code tests that getElementById is present. We can't do that | 443 // Note: JS code tests that getElementById is present. We can't do that |
| 444 // easily, so instead check for the types known to implement it. | 444 // easily, so instead check for the types known to implement it. |
| 445 if (node is Document || node is ShadowRoot || node is SvgSvgElement) { | 445 if (node is Document || node is ShadowRoot || node is SvgSvgElement) { |
| 446 return node; | 446 return node; |
| 447 } | 447 } |
| 448 return null; | 448 return null; |
| 449 } | 449 } |
| OLD | NEW |