| OLD | NEW |
| 1 /// The Dart HTML library. | 1 /// The Dart HTML library. |
| 2 library dart.dom.html; | 2 library dart.dom.html; |
| 3 | 3 |
| 4 import 'dart:async'; | 4 import 'dart:async'; |
| 5 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import 'dart:_collection-dev' hide Symbol; | 6 import 'dart:_collection-dev' hide Symbol; |
| 7 import 'dart:html_common'; | 7 import 'dart:html_common'; |
| 8 import 'dart:indexed_db'; | 8 import 'dart:indexed_db'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:json' as json; | 10 import 'dart:json' as json; |
| (...skipping 7368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7379 return e is Element && !(e is UnknownElement); | 7379 return e is Element && !(e is UnknownElement); |
| 7380 } | 7380 } |
| 7381 | 7381 |
| 7382 /** | 7382 /** |
| 7383 * Called by the DOM when this element has been instantiated. | 7383 * Called by the DOM when this element has been instantiated. |
| 7384 */ | 7384 */ |
| 7385 @Experimental | 7385 @Experimental |
| 7386 void onCreated() {} | 7386 void onCreated() {} |
| 7387 | 7387 |
| 7388 // Hooks to support custom WebComponents. | 7388 // Hooks to support custom WebComponents. |
| 7389 |
| 7390 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 7391 Element _xtag; |
| 7392 |
| 7389 /** | 7393 /** |
| 7390 * Experimental support for [web components][wc]. This field stores a | 7394 * Experimental support for [web components][wc]. This field stores a |
| 7391 * reference to the component implementation. It was inspired by Mozilla's | 7395 * reference to the component implementation. It was inspired by Mozilla's |
| 7392 * [x-tags][] project. Please note: in the future it may be possible to | 7396 * [x-tags][] project. Please note: in the future it may be possible to |
| 7393 * `extend Element` from your class, in which case this field will be | 7397 * `extend Element` from your class, in which case this field will be |
| 7394 * deprecated and will simply return this [Element] object. | 7398 * deprecated. |
| 7399 * |
| 7400 * If xtag has not been set, it will simply return `this` [Element]. |
| 7395 * | 7401 * |
| 7396 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html | 7402 * [wc]: http://dvcs.w3.org/hg/webcomponents/raw-file/tip/explainer/index.html |
| 7397 * [x-tags]: http://x-tags.org/ | 7403 * [x-tags]: http://x-tags.org/ |
| 7398 */ | 7404 */ |
| 7399 @Creates('Null') // Set from Dart code; does not instantiate a native type. | 7405 Element get xtag => _xtag != null ? _xtag : this; |
| 7400 var xtag; | 7406 |
| 7407 void set xtag(Element value) { |
| 7408 _xtag = value; |
| 7409 } |
| 7401 | 7410 |
| 7402 /** | 7411 /** |
| 7403 * Scrolls this element into view. | 7412 * Scrolls this element into view. |
| 7404 * | 7413 * |
| 7405 * Only one of of the alignment options may be specified at a time. | 7414 * Only one of of the alignment options may be specified at a time. |
| 7406 * | 7415 * |
| 7407 * If no options are specified then this will attempt to scroll the minimum | 7416 * If no options are specified then this will attempt to scroll the minimum |
| 7408 * amount needed to bring the element into view. | 7417 * amount needed to bring the element into view. |
| 7409 * | 7418 * |
| 7410 * Note that alignCenter is currently only supported on WebKit platforms. If | 7419 * Note that alignCenter is currently only supported on WebKit platforms. If |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7614 | 7623 |
| 7615 // TODO(jmesserly): this is static to work around http://dartbug.com/10166 | 7624 // TODO(jmesserly): this is static to work around http://dartbug.com/10166 |
| 7616 // Similar issue for unbind/unbindAll below. | 7625 // Similar issue for unbind/unbindAll below. |
| 7617 static void _bindElement(Element self, String name, model, String path) { | 7626 static void _bindElement(Element self, String name, model, String path) { |
| 7618 if (self._bindTemplate(name, model, path)) return; | 7627 if (self._bindTemplate(name, model, path)) return; |
| 7619 | 7628 |
| 7620 if (self._attributeBindings == null) { | 7629 if (self._attributeBindings == null) { |
| 7621 self._attributeBindings = new Map<String, StreamSubscription>(); | 7630 self._attributeBindings = new Map<String, StreamSubscription>(); |
| 7622 } | 7631 } |
| 7623 | 7632 |
| 7624 self.attributes.remove(name); | 7633 self.xtag.attributes.remove(name); |
| 7625 | 7634 |
| 7626 var changed; | 7635 var changed; |
| 7627 if (name.endsWith('?')) { | 7636 if (name.endsWith('?')) { |
| 7628 name = name.substring(0, name.length - 1); | 7637 name = name.substring(0, name.length - 1); |
| 7629 | 7638 |
| 7630 changed = (value) { | 7639 changed = (value) { |
| 7631 if (_templateBooleanConversion(value)) { | 7640 if (_templateBooleanConversion(value)) { |
| 7632 self.attributes[name] = ''; | 7641 self.xtag.attributes[name] = ''; |
| 7633 } else { | 7642 } else { |
| 7634 self.attributes.remove(name); | 7643 self.xtag.attributes.remove(name); |
| 7635 } | 7644 } |
| 7636 }; | 7645 }; |
| 7637 } else { | 7646 } else { |
| 7638 changed = (value) { | 7647 changed = (value) { |
| 7639 // TODO(jmesserly): escape value if needed to protect against XSS. | 7648 // TODO(jmesserly): escape value if needed to protect against XSS. |
| 7640 // See https://github.com/toolkitchen/mdv/issues/58 | 7649 // See https://github.com/toolkitchen/mdv/issues/58 |
| 7641 self.attributes[name] = value == null ? '' : '$value'; | 7650 self.xtag.attributes[name] = value == null ? '' : '$value'; |
| 7642 }; | 7651 }; |
| 7643 } | 7652 } |
| 7644 | 7653 |
| 7645 self.unbind(name); | 7654 self.unbind(name); |
| 7646 | 7655 |
| 7647 self._attributeBindings[name] = | 7656 self._attributeBindings[name] = |
| 7648 new PathObserver(model, path).bindSync(changed); | 7657 new PathObserver(model, path).bindSync(changed); |
| 7649 } | 7658 } |
| 7650 | 7659 |
| 7651 @Experimental | 7660 @Experimental |
| (...skipping 18820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 26472 var value = values[i]; | 26481 var value = values[i]; |
| 26473 if (value != null) { | 26482 if (value != null) { |
| 26474 newValue.write(value); | 26483 newValue.write(value); |
| 26475 } | 26484 } |
| 26476 } | 26485 } |
| 26477 } | 26486 } |
| 26478 | 26487 |
| 26479 return newValue.toString(); | 26488 return newValue.toString(); |
| 26480 }; | 26489 }; |
| 26481 | 26490 |
| 26482 node.bind(name, replacementBinding, 'value'); | 26491 _nodeOrCustom(node).bind(name, replacementBinding, 'value'); |
| 26483 } | 26492 } |
| 26484 | 26493 |
| 26485 void _bindOrDelegate(node, name, model, String path, | 26494 void _bindOrDelegate(node, name, model, String path, |
| 26486 CustomBindingSyntax syntax) { | 26495 CustomBindingSyntax syntax) { |
| 26487 | 26496 |
| 26488 if (syntax != null) { | 26497 if (syntax != null) { |
| 26489 var delegateBinding = syntax.getBinding(model, path, name, node); | 26498 var delegateBinding = syntax.getBinding(model, path, name, node); |
| 26490 if (delegateBinding != null) { | 26499 if (delegateBinding != null) { |
| 26491 model = delegateBinding; | 26500 model = delegateBinding; |
| 26492 path = 'value'; | 26501 path = 'value'; |
| 26493 } | 26502 } |
| 26494 } | 26503 } |
| 26495 | 26504 |
| 26496 node.bind(name, model, path); | 26505 _nodeOrCustom(node).bind(name, model, path); |
| 26497 } | 26506 } |
| 26498 | 26507 |
| 26508 /** |
| 26509 * Gets the [node]'s custom [Element.xtag] if present, otherwise returns |
| 26510 * the node. This is used so nodes can override [Node.bind], [Node.unbind], |
| 26511 * and [Node.unbindAll] like InputElement does. |
| 26512 */ |
| 26513 // TODO(jmesserly): remove this when we can extend Element for real. |
| 26514 _nodeOrCustom(node) => node is Element ? node.xtag : node; |
| 26515 |
| 26499 class _BindingToken { | 26516 class _BindingToken { |
| 26500 final String value; | 26517 final String value; |
| 26501 final bool isBinding; | 26518 final bool isBinding; |
| 26502 | 26519 |
| 26503 _BindingToken(this.value, {this.isBinding: false}); | 26520 _BindingToken(this.value, {this.isBinding: false}); |
| 26504 | 26521 |
| 26505 bool get isText => !isBinding; | 26522 bool get isText => !isBinding; |
| 26506 } | 26523 } |
| 26507 | 26524 |
| 26508 List<_BindingToken> _parseMustacheTokens(String s) { | 26525 List<_BindingToken> _parseMustacheTokens(String s) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 26548 fragment.$dom_firstChild, fragment.$dom_lastChild, model); | 26565 fragment.$dom_firstChild, fragment.$dom_lastChild, model); |
| 26549 | 26566 |
| 26550 var node = instanceRecord.firstNode; | 26567 var node = instanceRecord.firstNode; |
| 26551 while (node != null) { | 26568 while (node != null) { |
| 26552 node._templateInstance = instanceRecord; | 26569 node._templateInstance = instanceRecord; |
| 26553 node = node.nextNode; | 26570 node = node.nextNode; |
| 26554 } | 26571 } |
| 26555 } | 26572 } |
| 26556 | 26573 |
| 26557 void _removeAllBindingsRecursively(Node node) { | 26574 void _removeAllBindingsRecursively(Node node) { |
| 26558 node.unbindAll(); | 26575 _nodeOrCustom(node).unbindAll(); |
| 26559 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 26576 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 26560 _removeAllBindingsRecursively(c); | 26577 _removeAllBindingsRecursively(c); |
| 26561 } | 26578 } |
| 26562 } | 26579 } |
| 26563 | 26580 |
| 26564 void _removeTemplateChild(Node parent, Node child) { | 26581 void _removeTemplateChild(Node parent, Node child) { |
| 26565 child._templateInstance = null; | 26582 child._templateInstance = null; |
| 26566 if (child is Element && child.isTemplate) { | 26583 if (child is Element && child.isTemplate) { |
| 26567 // Make sure we stop observing when we remove an element. | 26584 // Make sure we stop observing when we remove an element. |
| 26568 var templateIterator = child._templateIterator; | 26585 var templateIterator = child._templateIterator; |
| (...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 27951 _position = nextPosition; | 27968 _position = nextPosition; |
| 27952 return true; | 27969 return true; |
| 27953 } | 27970 } |
| 27954 _current = null; | 27971 _current = null; |
| 27955 _position = _array.length; | 27972 _position = _array.length; |
| 27956 return false; | 27973 return false; |
| 27957 } | 27974 } |
| 27958 | 27975 |
| 27959 T get current => _current; | 27976 T get current => _current; |
| 27960 } | 27977 } |
| OLD | NEW |