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'; |
| 28 import 'src/node_binding.dart'; |
27 import 'src/list_diff.dart' show calculateSplices, ListChangeDelta; | 29 import 'src/list_diff.dart' show calculateSplices, ListChangeDelta; |
28 | 30 |
| 31 export 'src/binding_delegate.dart'; |
| 32 export 'src/node_binding.dart' show NodeBinding; |
| 33 |
29 part 'src/element.dart'; | 34 part 'src/element.dart'; |
30 part 'src/input_bindings.dart'; | 35 part 'src/input_bindings.dart'; |
31 part 'src/input_element.dart'; | 36 part 'src/input_element.dart'; |
| 37 part 'src/instance_binding_map.dart'; |
32 part 'src/node.dart'; | 38 part 'src/node.dart'; |
33 part 'src/select_element.dart'; | 39 part 'src/select_element.dart'; |
34 part 'src/template.dart'; | 40 part 'src/template.dart'; |
35 part 'src/template_iterator.dart'; | 41 part 'src/template_iterator.dart'; |
36 part 'src/text.dart'; | 42 part 'src/text.dart'; |
37 part 'src/text_area_element.dart'; | 43 part 'src/text_area_element.dart'; |
38 | 44 |
39 // TODO(jmesserly): ideally we would split TemplateBinding and Node.bind into | 45 // TODO(jmesserly): ideally we would split TemplateBinding and Node.bind into |
40 // two packages, but this is not easy when we are faking extension methods. | 46 // two packages, but this is not easy when we are faking extension methods. |
41 // Since TemplateElement needs to override Node.bind, it seems like the | 47 // Since TemplateElement needs to override Node.bind, it seems like the |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 /** | 140 /** |
135 * Returns true if this node is semantically a template. | 141 * Returns true if this node is semantically a template. |
136 * | 142 * |
137 * A node is a template if [tagName] is TEMPLATE, or the node has the | 143 * A node is a template if [tagName] is TEMPLATE, or the node has the |
138 * 'template' attribute and this tag supports attribute form for backwards | 144 * 'template' attribute and this tag supports attribute form for backwards |
139 * compatibility with existing HTML parsers. The nodes that can use attribute | 145 * compatibility with existing HTML parsers. The nodes that can use attribute |
140 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP | 146 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP |
141 * and COL), OPTION, and OPTGROUP. | 147 * and COL), OPTION, and OPTGROUP. |
142 */ | 148 */ |
143 bool isSemanticTemplate(Node n) => n is Element && | 149 bool isSemanticTemplate(Node n) => n is Element && |
144 ((n as Element).localName == 'template' || _isAttributeTemplate(n)); | 150 (n.localName == 'template' || _isAttributeTemplate(n)); |
145 | 151 |
146 // TODO(jmesserly): const set would be better | 152 // TODO(jmesserly): const set would be better |
147 const _SEMANTIC_TEMPLATE_TAGS = const { | 153 const _SEMANTIC_TEMPLATE_TAGS = const { |
148 'caption': null, | 154 'caption': null, |
149 'col': null, | 155 'col': null, |
150 'colgroup': null, | 156 'colgroup': null, |
151 'option': null, | 157 'option': null, |
152 'optgroup': null, | 158 'optgroup': null, |
153 'tbody': null, | 159 'tbody': null, |
154 'td': null, | 160 'td': null, |
155 'tfoot': null, | 161 'tfoot': null, |
156 'th': null, | 162 'th': null, |
157 'thead': null, | 163 'thead': null, |
158 'tr': null, | 164 'tr': null, |
159 }; | 165 }; |
160 | 166 |
161 | 167 |
162 // TODO(jmesserly): investigate if expandos give us enough performance. | 168 // TODO(jmesserly): investigate if expandos give us enough performance. |
163 | 169 |
164 // The expando for storing our MDV extensions. | 170 // The expando for storing our MDV extensions. |
165 // | 171 // |
166 // In general, we need state associated with the nodes. Rather than having a | 172 // In general, we need state associated with the nodes. Rather than having a |
167 // bunch of individual expandos, we keep one per node. | 173 // bunch of individual expandos, we keep one per node. |
168 // | 174 // |
169 // Aside from the potentially helping performance, it also keeps things simpler | 175 // Aside from the potentially helping performance, it also keeps things simpler |
170 // if we decide to integrate MDV into the DOM later, and means less code needs | 176 // if we decide to integrate MDV into the DOM later, and means less code needs |
171 // to worry about expandos. | 177 // to worry about expandos. |
172 final Expando _expando = new Expando('template_binding'); | 178 final Expando _expando = new Expando('template_binding'); |
OLD | NEW |