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

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

Issue 34453003: Rename mdv -> template_binding, remove experiemntal apis from dart:html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 mdv; 5 part of template_binding;
6 6
7 abstract class _InputBinding extends NodeBinding { 7 abstract class _InputBinding extends NodeBinding {
8 StreamSubscription _eventSub; 8 StreamSubscription _eventSub;
9 9
10 _InputBinding(node, name, model, path): super(node, name, model, path) { 10 _InputBinding(node, name, model, path): super(node, name, model, path) {
11 _eventSub = _getStreamForInputType(node).listen(nodeValueChanged); 11 _eventSub = _getStreamForInputType(node).listen(nodeValueChanged);
12 } 12 }
13 13
14 void boundValueChanged(newValue); 14 void boundValueChanged(newValue);
15 15
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 void nodeValueChanged(e) { 81 void nodeValueChanged(e) {
82 value = node.checked; 82 value = node.checked;
83 83
84 // Only the radio button that is getting checked gets an event. We 84 // Only the radio button that is getting checked gets an event. We
85 // therefore find all the associated radio buttons and update their 85 // therefore find all the associated radio buttons and update their
86 // CheckedBinding manually. 86 // CheckedBinding manually.
87 if (node is InputElement && node.type == 'radio') { 87 if (node is InputElement && node.type == 'radio') {
88 for (var r in _getAssociatedRadioButtons(node)) { 88 for (var r in _getAssociatedRadioButtons(node)) {
89 var checkedBinding = r.bindings['checked']; 89 var checkedBinding = nodeBind(r).bindings['checked'];
90 if (checkedBinding != null) { 90 if (checkedBinding != null) {
91 // Set the value directly to avoid an infinite call stack. 91 // Set the value directly to avoid an infinite call stack.
92 checkedBinding.value = false; 92 checkedBinding.value = false;
93 } 93 }
94 } 94 }
95 } 95 }
96 } 96 }
97 97
98 // |element| is assumed to be an HTMLInputElement with |type| == 'radio'. 98 // |element| is assumed to be an HTMLInputElement with |type| == 'radio'.
99 // Returns an array containing all radio buttons other than |element| that 99 // Returns an array containing all radio buttons other than |element| that
(...skipping 17 matching lines...) Expand all
117 var radios = element.ownerDocument.queryAll( 117 var radios = element.ownerDocument.queryAll(
118 'input[type="radio"][name="${element.name}"]'); 118 'input[type="radio"][name="${element.name}"]');
119 return radios.where((el) => el != element && el.form == null); 119 return radios.where((el) => el != element && el.form == null);
120 } 120 }
121 } 121 }
122 122
123 // TODO(jmesserly): polyfill document.contains API instead of doing it here 123 // TODO(jmesserly): polyfill document.contains API instead of doing it here
124 static bool _isNodeInDocument(Node node) { 124 static bool _isNodeInDocument(Node node) {
125 // On non-IE this works: 125 // On non-IE this works:
126 // return node.ownerDocument.contains(node); 126 // return node.ownerDocument.contains(node);
127 var document = node.document; 127 var document = node.ownerDocument;
128 if (node == document || node.parentNode == document) return true; 128 if (node == document || node.parentNode == document) return true;
129 return document.documentElement.contains(node); 129 return document.documentElement.contains(node);
130 } 130 }
131 } 131 }
132 132
133 class _SelectedIndexBinding extends _InputBinding { 133 class _SelectedIndexBinding extends _InputBinding {
134 _SelectedIndexBinding(node, model, path) 134 _SelectedIndexBinding(node, model, path)
135 : super(node, 'selectedIndex', model, path); 135 : super(node, 'selectedIndex', model, path);
136 136
137 SelectElement get node => super.node; 137 SelectElement get node => super.node;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from 178 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from
179 // one type to another (e.g. value-as-number) and whether it is useful to 179 // one type to another (e.g. value-as-number) and whether it is useful to
180 // have something like a int/num binding converter (either as a base class or 180 // have something like a int/num binding converter (either as a base class or
181 // a wrapper). 181 // a wrapper).
182 static int _toInt(value) { 182 static int _toInt(value) {
183 if (value is String) return int.parse(value, onError: (_) => null); 183 if (value is String) return int.parse(value, onError: (_) => null);
184 return value is int ? value : null; 184 return value is int ? value : null;
185 } 185 }
186 } 186 }
OLDNEW
« no previous file with comments | « pkg/template_binding/lib/src/element.dart ('k') | pkg/template_binding/lib/src/input_element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698