OLD | NEW |
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 | 7 |
8 // Note: the JavaScript version monkeypatches(!!) the close method of the passed | 8 // Note: the JavaScript version monkeypatches(!!) the close method of the passed |
9 // in Bindable. We use a wrapper instead. | 9 // in Bindable. We use a wrapper instead. |
10 class _InputBinding extends Bindable { | 10 class _InputBinding extends Bindable { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 static Stream<Event> _getStreamForInputType(element) { | 101 static Stream<Event> _getStreamForInputType(element) { |
102 if (element is OptionElement) return element.onInput; | 102 if (element is OptionElement) return element.onInput; |
103 switch (element.type) { | 103 switch (element.type) { |
104 case 'checkbox': | 104 case 'checkbox': |
105 return _checkboxEventType.forTarget(element); | 105 return _checkboxEventType.forTarget(element); |
106 case 'radio': | 106 case 'radio': |
107 case 'select-multiple': | 107 case 'select-multiple': |
108 case 'select-one': | 108 case 'select-one': |
109 return element.onChange; | 109 return element.onChange; |
110 default: | 110 case 'range': |
111 return element.onInput; | 111 if (window.navigator.userAgent.contains(new RegExp('Trident|MSIE'))) { |
| 112 return element.onChange; |
| 113 } |
112 } | 114 } |
| 115 return element.onInput; |
113 } | 116 } |
114 | 117 |
115 // |element| is assumed to be an HTMLInputElement with |type| == 'radio'. | 118 // |element| is assumed to be an HTMLInputElement with |type| == 'radio'. |
116 // Returns an array containing all radio buttons other than |element| that | 119 // Returns an array containing all radio buttons other than |element| that |
117 // have the same |name|, either in the form that |element| belongs to or, | 120 // have the same |name|, either in the form that |element| belongs to or, |
118 // if no form, in the document tree to which |element| belongs. | 121 // if no form, in the document tree to which |element| belongs. |
119 // | 122 // |
120 // This implementation is based upon the HTML spec definition of a | 123 // This implementation is based upon the HTML spec definition of a |
121 // "radio button group": | 124 // "radio button group": |
122 // http://www.whatwg.org/specs/web-apps/current-work/multipage/number-state.
html#radio-button-group | 125 // http://www.whatwg.org/specs/web-apps/current-work/multipage/number-state.
html#radio-button-group |
(...skipping 18 matching lines...) Expand all Loading... |
141 | 144 |
142 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from | 145 // TODO(jmesserly,sigmund): I wonder how many bindings typically convert from |
143 // one type to another (e.g. value-as-number) and whether it is useful to | 146 // one type to another (e.g. value-as-number) and whether it is useful to |
144 // have something like a int/num binding converter (either as a base class or | 147 // have something like a int/num binding converter (either as a base class or |
145 // a wrapper). | 148 // a wrapper). |
146 static int _toInt(value) { | 149 static int _toInt(value) { |
147 if (value is String) return int.parse(value, onError: (_) => 0); | 150 if (value is String) return int.parse(value, onError: (_) => 0); |
148 return value is int ? value : 0; | 151 return value is int ? value : 0; |
149 } | 152 } |
150 } | 153 } |
| 154 |
| 155 _getTreeScope(Node node) { |
| 156 Node parent; |
| 157 while ((parent = node.parentNode) != null ) { |
| 158 node = parent; |
| 159 } |
| 160 |
| 161 return _hasGetElementById(node) ? node : null; |
| 162 } |
| 163 |
| 164 // Note: JS code tests that getElementById is present. We can't do that |
| 165 // easily, so instead check for the types known to implement it. |
| 166 bool _hasGetElementById(Node node) => |
| 167 node is Document || node is ShadowRoot || node is SvgSvgElement; |
OLD | NEW |