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

Unified Diff: pkg/mdv/lib/src/bindings.dart

Issue 18117012: [package:mdv] Support binding to HTMLSelectElement.selectedIndex (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix merge issue Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/mdv/lib/mdv.dart ('k') | pkg/mdv/lib/src/input_element.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mdv/lib/src/bindings.dart
diff --git a/pkg/mdv/lib/src/bindings.dart b/pkg/mdv/lib/src/bindings.dart
index f2aa0ea09a3cb8b4a3c2ed8256bcffcc5dbbb624..8fdc1933ac513160cf7c5763efa21b4389366fe9 100644
--- a/pkg/mdv/lib/src/bindings.dart
+++ b/pkg/mdv/lib/src/bindings.dart
@@ -11,7 +11,8 @@ part of mdv;
typedef void _ChangeHandler(value);
abstract class _InputBinding {
- final InputElement element;
+ // InputElement or SelectElement
+ final element;
PathObserver binding;
StreamSubscription _pathSub;
StreamSubscription _eventSub;
@@ -51,7 +52,7 @@ abstract class _InputBinding {
return fired.length == 1 ? Element.changeEvent : fired.first;
}();
- static Stream<Event> _getStreamForInputType(InputElement element) {
+ static Stream<Event> _getStreamForInputType(element) {
switch (element.type) {
case 'checkbox':
return _checkboxEventType.forTarget(element);
@@ -65,76 +66,6 @@ abstract class _InputBinding {
}
}
-class _ValueBinding extends _InputBinding {
- _ValueBinding(element, model, path) : super(element, model, path);
-
- void valueChanged(value) {
- element.value = value == null ? '' : '$value';
- }
-
- void updateBinding(e) {
- binding.value = element.value;
- }
-}
-
-class _CheckedBinding extends _InputBinding {
- _CheckedBinding(element, model, path) : super(element, model, path);
-
- void valueChanged(value) {
- element.checked = _toBoolean(value);
- }
-
- void updateBinding(e) {
- binding.value = element.checked;
-
- // Only the radio button that is getting checked gets an event. We
- // therefore find all the associated radio buttons and update their
- // CheckedBinding manually.
- if (element is InputElement && element.type == 'radio') {
- for (var r in _getAssociatedRadioButtons(element)) {
- var checkedBinding = _mdv(r)._checkedBinding;
- if (checkedBinding != null) {
- // Set the value directly to avoid an infinite call stack.
- checkedBinding.binding.value = false;
- }
- }
- }
- }
-
- // |element| is assumed to be an HTMLInputElement with |type| == 'radio'.
- // Returns an array containing all radio buttons other than |element| that
- // have the same |name|, either in the form that |element| belongs to or,
- // if no form, in the document tree to which |element| belongs.
- //
- // This implementation is based upon the HTML spec definition of a
- // "radio button group":
- // http://www.whatwg.org/specs/web-apps/current-work/multipage/number-state.html#radio-button-group
- //
- static Iterable _getAssociatedRadioButtons(element) {
- if (!_isNodeInDocument(element)) return [];
- if (element.form != null) {
- return element.form.nodes.where((el) {
- return el != element &&
- el is InputElement &&
- el.type == 'radio' &&
- el.name == element.name;
- });
- } else {
- var radios = element.document.queryAll(
- 'input[type="radio"][name="${element.name}"]');
- return radios.where((el) => el != element && el.form == null);
- }
- }
-
- // TODO(jmesserly): polyfill document.contains API instead of doing it here
- static bool _isNodeInDocument(Node node) {
- // On non-IE this works:
- // return node.document.contains(node);
- var document = node.document;
- if (node == document || node.parentNode == document) return true;
- return document.documentElement.contains(node);
- }
-}
// TODO(jmesserly): not sure what kind of boolean conversion rules to
// apply for template data-binding. HTML attributes are true if they're
« no previous file with comments | « pkg/mdv/lib/mdv.dart ('k') | pkg/mdv/lib/src/input_element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698