| OLD | NEW |
| 1 /// The Dart HTML library. | 1 /// The Dart HTML library. |
| 2 /// | 2 /// |
| 3 /// For examples, see | 3 /// For examples, see |
| 4 /// [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples) | 4 /// [Dart HTML5 Samples](https://github.com/dart-lang/dart-html5-samples) |
| 5 /// on Github. | 5 /// on Github. |
| 6 library dart.dom.html; | 6 library dart.dom.html; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:_collection-dev' hide Symbol; | 10 import 'dart:_collection-dev' hide Symbol; |
| (...skipping 8270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8281 | 8281 |
| 8282 @Creates('Null') // Set from Dart code; does not instantiate a native type. | 8282 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 8283 Element _templateInstanceRef; | 8283 Element _templateInstanceRef; |
| 8284 | 8284 |
| 8285 // Note: only used if `this is! TemplateElement` | 8285 // Note: only used if `this is! TemplateElement` |
| 8286 @Creates('Null') // Set from Dart code; does not instantiate a native type. | 8286 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 8287 DocumentFragment _templateContent; | 8287 DocumentFragment _templateContent; |
| 8288 | 8288 |
| 8289 bool _templateIsDecorated; | 8289 bool _templateIsDecorated; |
| 8290 | 8290 |
| 8291 |
| 8291 /** | 8292 /** |
| 8292 * Gets the template this node refers to. | 8293 * Gets the template this node refers to. |
| 8293 * This is only supported if [isTemplate] is true. | 8294 * This is only supported if [isTemplate] is true. |
| 8294 */ | 8295 */ |
| 8295 @Experimental | 8296 @Experimental |
| 8296 Element get ref { | 8297 Element get ref { |
| 8297 _ensureTemplate(); | 8298 _ensureTemplate(); |
| 8298 | 8299 |
| 8299 Element ref = null; | 8300 Element ref = null; |
| 8300 var refId = attributes['ref']; | 8301 var refId = attributes['ref']; |
| 8301 if (refId != null) { | 8302 if (refId != null) { |
| 8302 ref = document.getElementById(refId); | 8303 var treeScope = this; |
| 8304 while (treeScope.parentNode != null) { |
| 8305 treeScope = treeScope.parentNode; |
| 8306 } |
| 8307 |
| 8308 // Note: JS code tests that getElementById is present. We can't do that |
| 8309 // easily, so instead check for the types known to implement it. |
| 8310 if (treeScope is Document || |
| 8311 treeScope is ShadowRoot || |
| 8312 treeScope is svg.SvgSvgElement) { |
| 8313 |
| 8314 ref = treeScope.getElementById(refId); |
| 8315 } |
| 8303 } | 8316 } |
| 8304 | 8317 |
| 8305 return ref != null ? ref : _templateInstanceRef; | 8318 return ref != null ? ref : _templateInstanceRef; |
| 8306 } | 8319 } |
| 8307 | 8320 |
| 8308 /** | 8321 /** |
| 8309 * Gets the content of this template. | 8322 * Gets the content of this template. |
| 8310 * This is only supported if [isTemplate] is true. | 8323 * This is only supported if [isTemplate] is true. |
| 8311 */ | 8324 */ |
| 8312 @Experimental | 8325 @Experimental |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8345 'colgroup': null, | 8358 'colgroup': null, |
| 8346 'tbody': null, | 8359 'tbody': null, |
| 8347 'td': null, | 8360 'td': null, |
| 8348 'tfoot': null, | 8361 'tfoot': null, |
| 8349 'th': null, | 8362 'th': null, |
| 8350 'thead': null, | 8363 'thead': null, |
| 8351 'tr': null, | 8364 'tr': null, |
| 8352 }; | 8365 }; |
| 8353 | 8366 |
| 8354 bool get _isAttributeTemplate => attributes.containsKey('template') && | 8367 bool get _isAttributeTemplate => attributes.containsKey('template') && |
| 8355 (localName == 'option' || _TABLE_TAGS.containsKey(localName)); | 8368 (localName == 'option' || localName == 'optgroup' || |
| 8369 _TABLE_TAGS.containsKey(localName)); |
| 8356 | 8370 |
| 8357 /** | 8371 /** |
| 8358 * Returns true if this node is a template. | 8372 * Returns true if this node is a template. |
| 8359 * | 8373 * |
| 8360 * A node is a template if [tagName] is TEMPLATE, or the node has the | 8374 * A node is a template if [tagName] is TEMPLATE, or the node has the |
| 8361 * 'template' attribute and this tag supports attribute form for backwards | 8375 * 'template' attribute and this tag supports attribute form for backwards |
| 8362 * compatibility with existing HTML parsers. The nodes that can use attribute | 8376 * compatibility with existing HTML parsers. The nodes that can use attribute |
| 8363 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP | 8377 * form are table elments (THEAD, TBODY, TFOOT, TH, TR, TD, CAPTION, COLGROUP |
| 8364 * and COL) and OPTION. | 8378 * and COL), OPTION, and OPTGROUP. |
| 8365 */ | 8379 */ |
| 8366 // TODO(jmesserly): this is not a public MDV API, but it seems like a useful | 8380 // TODO(jmesserly): this is not a public MDV API, but it seems like a useful |
| 8367 // place to document which tags our polyfill considers to be templates. | 8381 // place to document which tags our polyfill considers to be templates. |
| 8368 // Otherwise I'd be repeating it in several other places. | 8382 // Otherwise I'd be repeating it in several other places. |
| 8369 // See if we can replace this with a TemplateMixin. | 8383 // See if we can replace this with a TemplateMixin. |
| 8370 @Experimental | 8384 @Experimental |
| 8371 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate; | 8385 bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate; |
| 8372 | 8386 |
| 8373 void _ensureTemplate() { | 8387 void _ensureTemplate() { |
| 8374 if (!isTemplate) { | 8388 if (!isTemplate) { |
| (...skipping 12746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21121 // template. | 21135 // template. |
| 21122 // TODO(jmesserly): content is DocumentFragment or Element | 21136 // TODO(jmesserly): content is DocumentFragment or Element |
| 21123 var descendents = (content as dynamic).queryAll(_allTemplatesSelectors); | 21137 var descendents = (content as dynamic).queryAll(_allTemplatesSelectors); |
| 21124 if (content is Element && (content as Element).isTemplate) { | 21138 if (content is Element && (content as Element).isTemplate) { |
| 21125 _bootstrap(content); | 21139 _bootstrap(content); |
| 21126 } | 21140 } |
| 21127 | 21141 |
| 21128 descendents.forEach(_bootstrap); | 21142 descendents.forEach(_bootstrap); |
| 21129 } | 21143 } |
| 21130 | 21144 |
| 21131 static final String _allTemplatesSelectors = 'template, option[template], ' + | 21145 static final String _allTemplatesSelectors = |
| 21146 'template, option[template], optgroup[template], ' + |
| 21132 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); | 21147 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); |
| 21133 | 21148 |
| 21134 static bool _initStyles; | 21149 static bool _initStyles; |
| 21135 | 21150 |
| 21136 static void _injectStylesheet() { | 21151 static void _injectStylesheet() { |
| 21137 if (_initStyles == true) return; | 21152 if (_initStyles == true) return; |
| 21138 _initStyles = true; | 21153 _initStyles = true; |
| 21139 | 21154 |
| 21140 var style = new StyleElement(); | 21155 var style = new StyleElement(); |
| 21141 style.text = r''' | 21156 style.text = r''' |
| (...skipping 7634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 28776 _position = nextPosition; | 28791 _position = nextPosition; |
| 28777 return true; | 28792 return true; |
| 28778 } | 28793 } |
| 28779 _current = null; | 28794 _current = null; |
| 28780 _position = _array.length; | 28795 _position = _array.length; |
| 28781 return false; | 28796 return false; |
| 28782 } | 28797 } |
| 28783 | 28798 |
| 28784 T get current => _current; | 28799 T get current => _current; |
| 28785 } | 28800 } |
| OLD | NEW |