OLD | NEW |
1 /** | 1 /** |
2 * A simple tree API that results from parsing html. Intended to be compatible | 2 * A simple tree API that results from parsing html. Intended to be compatible |
3 * with dart:html, but right now it resembles the classic JS DOM. | 3 * with dart:html, but right now it resembles the classic JS DOM. |
4 */ | 4 */ |
5 library dom; | 5 library dom; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'package:source_maps/span.dart' show FileSpan; | 8 import 'package:source_maps/span.dart' show FileSpan; |
9 | 9 |
10 import 'src/constants.dart'; | 10 import 'src/constants.dart'; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return str.toString(); | 174 return str.toString(); |
175 } | 175 } |
176 | 176 |
177 set innerHtml(String value) { | 177 set innerHtml(String value) { |
178 nodes.clear(); | 178 nodes.clear(); |
179 // TODO(jmesserly): should be able to get the same effect by adding the | 179 // TODO(jmesserly): should be able to get the same effect by adding the |
180 // fragment directly. | 180 // fragment directly. |
181 nodes.addAll(parseFragment(value, container: tagName).nodes); | 181 nodes.addAll(parseFragment(value, container: tagName).nodes); |
182 } | 182 } |
183 | 183 |
| 184 Node get firstChild => nodes.isNotEmpty ? nodes[0] : null; |
| 185 |
184 void _addOuterHtml(StringBuffer str); | 186 void _addOuterHtml(StringBuffer str); |
185 | 187 |
186 void _addInnerHtml(StringBuffer str) { | 188 void _addInnerHtml(StringBuffer str) { |
187 for (Node child in nodes) child._addOuterHtml(str); | 189 for (Node child in nodes) child._addOuterHtml(str); |
188 } | 190 } |
189 | 191 |
190 String toString() => tagName; | 192 String toString() => tagName; |
191 | 193 |
192 Node remove() { | 194 Node remove() { |
193 // TODO(jmesserly): is parent == null an error? | 195 // TODO(jmesserly): is parent == null an error? |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 if (start == null) start = length - 1; | 864 if (start == null) start = length - 1; |
863 return _filtered.lastIndexOf(element, start); | 865 return _filtered.lastIndexOf(element, start); |
864 } | 866 } |
865 | 867 |
866 Element get first => _filtered.first; | 868 Element get first => _filtered.first; |
867 | 869 |
868 Element get last => _filtered.last; | 870 Element get last => _filtered.last; |
869 | 871 |
870 Element get single => _filtered.single; | 872 Element get single => _filtered.single; |
871 } | 873 } |
OLD | NEW |