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

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

Issue 19593006: [mdv] Implement two-way binding to HTMLTextArea.value (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
Index: pkg/mdv/lib/src/input_element.dart
diff --git a/pkg/mdv/lib/src/input_element.dart b/pkg/mdv/lib/src/input_element.dart
index 69ca7e046da6a52eeb63330257ad4c1ea6f8436f..3876ddb437f0624abdaed155761c0bb8f7e3ed98 100644
--- a/pkg/mdv/lib/src/input_element.dart
+++ b/pkg/mdv/lib/src/input_element.dart
@@ -6,16 +6,15 @@ part of mdv;
/** Extensions to the [InputElement] API. */
class _InputElementExtension extends _ElementExtension {
+ _ValueBinding _valueBinding;
+ _CheckedBinding _checkedBinding;
+
_InputElementExtension(InputElement node) : super(node);
InputElement get node => super.node;
- _ValueBinding _valueBinding;
-
- _CheckedBinding _checkedBinding;
-
void bind(String name, model, String path) {
- switch (name) {
+ switch (name.toLowerCase()) {
case 'value':
unbind('value');
node.attributes.remove('value');
@@ -33,7 +32,7 @@ class _InputElementExtension extends _ElementExtension {
}
void unbind(String name) {
- switch (name) {
+ switch (name.toLowerCase()) {
case 'value':
if (_valueBinding != null) {
_valueBinding.unbind();
@@ -58,78 +57,3 @@ class _InputElementExtension extends _ElementExtension {
super.unbindAll();
}
}
-
-class _ValueBinding extends _InputBinding {
- _ValueBinding(element, model, path) : super(element, model, path);
-
- InputElement get element => super.element;
-
- 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);
-
- InputElement get element => super.element;
-
- 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);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698