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 /** | 5 /** |
6 * This library provides access to the Polymer project's | 6 * This library provides access to the Polymer project's |
7 * [Data Binding](http://www.polymer-project.org/docs/polymer/databinding.html) | 7 * [Data Binding](http://www.polymer-project.org/docs/polymer/databinding.html) |
8 * Find more information at the | 8 * Find more information at the |
9 * [Polymer.dart homepage](https://www.dartlang.org/polymer-dart/). | 9 * [Polymer.dart homepage](https://www.dartlang.org/polymer-dart/). |
10 * | 10 * |
11 * Extends the capabilities of the HTML Template Element by enabling it to | 11 * Extends the capabilities of the HTML Template Element by enabling it to |
12 * create, manage, and remove instances of content bound to data defined in | 12 * create, manage, and remove instances of content bound to data defined in |
13 * Dart. | 13 * Dart. |
14 * | 14 * |
15 * Node.bind() is a new method added to all DOM nodes which instructs them to | 15 * Node.bind() is a new method added to all DOM nodes which instructs them to |
16 * bind the named property to the data provided. These allows applications to | 16 * bind the named property to the data provided. These allows applications to |
17 * create a data model in Dart or JavaScript that DOM reacts to. | 17 * create a data model in Dart or JavaScript that DOM reacts to. |
18 */ | 18 */ |
19 library template_binding; | 19 library template_binding; |
20 | 20 |
21 import 'dart:async'; | 21 import 'dart:async'; |
22 import 'dart:collection'; | 22 import 'dart:collection'; |
23 import 'dart:html'; | 23 import 'dart:html'; |
24 import 'dart:svg' show SvgSvgElement; | 24 import 'dart:svg' show SvgSvgElement; |
25 import 'package:observe/observe.dart'; | 25 import 'package:observe/observe.dart'; |
26 | 26 |
27 import 'src/binding_delegate.dart'; | 27 import 'src/binding_delegate.dart'; |
28 import 'src/node_binding.dart'; | |
29 | 28 |
30 export 'src/binding_delegate.dart'; | 29 export 'src/binding_delegate.dart'; |
31 export 'src/node_binding.dart' show NodeBinding; | |
32 | 30 |
33 part 'src/element.dart'; | 31 part 'src/element.dart'; |
34 part 'src/input_bindings.dart'; | 32 part 'src/input_bindings.dart'; |
35 part 'src/input_element.dart'; | 33 part 'src/input_element.dart'; |
36 part 'src/instance_binding_map.dart'; | 34 part 'src/instance_binding_map.dart'; |
37 part 'src/node.dart'; | 35 part 'src/node.dart'; |
38 part 'src/select_element.dart'; | 36 part 'src/select_element.dart'; |
39 part 'src/template.dart'; | 37 part 'src/template.dart'; |
40 part 'src/template_iterator.dart'; | 38 part 'src/template_iterator.dart'; |
41 part 'src/text.dart'; | 39 part 'src/text.dart'; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 127 } |
130 | 128 |
131 _expando[node] = extension; | 129 _expando[node] = extension; |
132 return extension; | 130 return extension; |
133 } | 131 } |
134 | 132 |
135 | 133 |
136 bool _isAttributeTemplate(Element n) => n.attributes.containsKey('template') && | 134 bool _isAttributeTemplate(Element n) => n.attributes.containsKey('template') && |
137 _SEMANTIC_TEMPLATE_TAGS.containsKey(n.localName); | 135 _SEMANTIC_TEMPLATE_TAGS.containsKey(n.localName); |
138 | 136 |
| 137 bool _isSvgTemplate(Element el) => el.tagName == 'template' && |
| 138 el.namespaceUri == 'http://www.w3.org/2000/svg'; |
| 139 |
| 140 bool _isHtmlTemplate(Element el) => el.tagName == 'TEMPLATE' && |
| 141 el.namespaceUri == 'http://www.w3.org/1999/xhtml'; |
| 142 |
139 /** | 143 /** |
140 * Returns true if this node is semantically a template. | 144 * Returns true if this node is semantically a template. |
141 * | 145 * |
142 * A node is a template if [tagName] is TEMPLATE, or the node has the | 146 * A node is a template if [tagName] is TEMPLATE, or the node has the |
143 * 'template' attribute and this tag supports attribute form for backwards | 147 * 'template' attribute and this tag supports attribute form for backwards |
144 * compatibility with existing HTML parsers. The nodes that can use attribute | 148 * compatibility with existing HTML parsers. The nodes that can use attribute |
145 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP | 149 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP |
146 * and COL), OPTION, and OPTGROUP. | 150 * and COL), OPTION, and OPTGROUP. |
147 */ | 151 */ |
148 bool isSemanticTemplate(Node n) => n is Element && | 152 bool isSemanticTemplate(Node n) => n is Element && |
149 (n.localName == 'template' || _isAttributeTemplate(n)); | 153 (_isHtmlTemplate(n) || _isAttributeTemplate(n) || _isSvgTemplate(n)); |
150 | 154 |
151 // TODO(jmesserly): const set would be better | 155 // TODO(jmesserly): const set would be better |
152 const _SEMANTIC_TEMPLATE_TAGS = const { | 156 const _SEMANTIC_TEMPLATE_TAGS = const { |
153 'caption': null, | 157 'caption': null, |
154 'col': null, | 158 'col': null, |
155 'colgroup': null, | 159 'colgroup': null, |
156 'option': null, | 160 'option': null, |
157 'optgroup': null, | 161 'optgroup': null, |
158 'tbody': null, | 162 'tbody': null, |
159 'td': null, | 163 'td': null, |
160 'tfoot': null, | 164 'tfoot': null, |
161 'th': null, | 165 'th': null, |
162 'thead': null, | 166 'thead': null, |
163 'tr': null, | 167 'tr': null, |
164 }; | 168 }; |
165 | 169 |
166 | 170 |
167 // TODO(jmesserly): investigate if expandos give us enough performance. | 171 // TODO(jmesserly): investigate if expandos give us enough performance. |
168 | 172 |
169 // The expando for storing our MDV extensions. | 173 // The expando for storing our MDV extensions. |
170 // | 174 // |
171 // In general, we need state associated with the nodes. Rather than having a | 175 // In general, we need state associated with the nodes. Rather than having a |
172 // bunch of individual expandos, we keep one per node. | 176 // bunch of individual expandos, we keep one per node. |
173 // | 177 // |
174 // Aside from the potentially helping performance, it also keeps things simpler | 178 // Aside from the potentially helping performance, it also keeps things simpler |
175 // if we decide to integrate MDV into the DOM later, and means less code needs | 179 // if we decide to integrate MDV into the DOM later, and means less code needs |
176 // to worry about expandos. | 180 // to worry about expandos. |
177 final Expando _expando = new Expando('template_binding'); | 181 final Expando _expando = new Expando('template_binding'); |
OLD | NEW |