Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: pkg/template_binding/lib/src/element.dart

Issue 335943003: merge to trunk all changes from 36817 until 37378 under the packages: polymer, (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of template_binding; 5 part of template_binding;
6 6
7 /** Extensions to the [Element] API. */ 7 /** Extensions to the [Element] API. */
8 class _ElementExtension extends NodeBindExtension { 8 class _ElementExtension extends NodeBindExtension {
9 _ElementExtension(Element node) : super._(node); 9 _ElementExtension(Element node) : super._(node);
10 10
11 bind(String name, value, {bool oneTime: false}) { 11 bind(String name, value, {bool oneTime: false}) {
12 _self.unbind(name);
13
14 Element node = _node; 12 Element node = _node;
15 13
16 if (node is OptionElement && name == 'value') { 14 if (node is OptionElement && name == 'value') {
17 // Note: because <option> can be a semantic template, <option> will be 15 // Note: because <option> can be a semantic template, <option> will be
18 // a TemplateBindExtension sometimes. So we need to handle it here. 16 // a TemplateBindExtension sometimes. So we need to handle it here.
19 node.attributes.remove(name); 17 node.attributes.remove(name);
20 18
21 if (oneTime) return _updateOption(value); 19 if (oneTime) return _updateOption(value);
22 _open(value, _updateOption); 20 _open(value, _updateOption);
23 } else { 21 } else {
24 bool conditional = name.endsWith('?'); 22 bool conditional = name.endsWith('?');
25 if (conditional) { 23 if (conditional) {
26 node.attributes.remove(name); 24 node.attributes.remove(name);
27 name = name.substring(0, name.length - 1); 25 name = name.substring(0, name.length - 1);
28 } 26 }
29 27
30 if (oneTime) return _updateAttribute(_node, name, conditional, value); 28 if (oneTime) return _updateAttribute(_node, name, conditional, value);
31 29
32 _open(value, (x) => _updateAttribute(_node, name, conditional, x)); 30 _open(value, (x) => _updateAttribute(_node, name, conditional, x));
33 } 31 }
34 return bindings[name] = value; 32 return _maybeUpdateBindings(name, value);
35 } 33 }
36 34
37 void _updateOption(newValue) { 35 void _updateOption(newValue) {
38 OptionElement node = _node; 36 OptionElement node = _node;
39 var oldValue = null; 37 var oldValue = null;
40 var selectBinding = null; 38 var selectBinding = null;
41 var select = node.parentNode; 39 var select = node.parentNode;
42 if (select is SelectElement) { 40 if (select is SelectElement) {
43 var valueBinding = nodeBind(select).bindings['value']; 41 var bindings = nodeBind(select).bindings;
44 if (valueBinding is _InputBinding) { 42 if (bindings != null) {
45 selectBinding = valueBinding; 43 var valueBinding = bindings['value'];
46 oldValue = select.value; 44 if (valueBinding is _InputBinding) {
45 selectBinding = valueBinding;
46 oldValue = select.value;
47 }
47 } 48 }
48 } 49 }
49 50
50 node.value = _sanitizeValue(newValue); 51 node.value = _sanitizeValue(newValue);
51 52
52 if (selectBinding != null && select.value != oldValue) { 53 if (selectBinding != null && select.value != oldValue) {
53 selectBinding.value = select.value; 54 selectBinding.value = select.value;
54 } 55 }
55 } 56 }
56 } 57 }
57 58
58 void _updateAttribute(Element node, String name, bool conditional, value) { 59 void _updateAttribute(Element node, String name, bool conditional, value) {
59 if (conditional) { 60 if (conditional) {
60 if (_toBoolean(value)) { 61 if (_toBoolean(value)) {
61 node.attributes[name] = ''; 62 node.attributes[name] = '';
62 } else { 63 } else {
63 node.attributes.remove(name); 64 node.attributes.remove(name);
64 } 65 }
65 } else { 66 } else {
66 // TODO(jmesserly): escape value if needed to protect against XSS. 67 // TODO(jmesserly): escape value if needed to protect against XSS.
67 // See https://github.com/polymer-project/mdv/issues/58 68 // See https://github.com/polymer-project/mdv/issues/58
68 node.attributes[name] = _sanitizeValue(value); 69 node.attributes[name] = _sanitizeValue(value);
69 } 70 }
70 } 71 }
OLDNEW
« no previous file with comments | « pkg/template_binding/lib/src/binding_delegate.dart ('k') | pkg/template_binding/lib/src/input_bindings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698