| 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 mdv; | 5 part of mdv; |
| 6 | 6 |
| 7 /** Extensions to the [InputElement] API. */ | 7 /** Extensions to the [InputElement] API. */ |
| 8 class _InputElementExtension extends _ElementExtension { | 8 class _InputElementExtension extends _ElementExtension { |
| 9 _ValueBinding _valueBinding; | |
| 10 _CheckedBinding _checkedBinding; | |
| 11 | |
| 12 _InputElementExtension(InputElement node) : super(node); | 9 _InputElementExtension(InputElement node) : super(node); |
| 13 | 10 |
| 14 InputElement get node => super.node; | 11 InputElement get node => super.node; |
| 15 | 12 |
| 16 void bind(String name, model, String path) { | 13 NodeBinding createBinding(String name, model, String path) { |
| 17 switch (name.toLowerCase()) { | 14 if (name == 'value') { |
| 18 case 'value': | 15 // TODO(rafaelw): Maybe template should remove all binding instructions. |
| 19 unbind('value'); | 16 node.attributes.remove(name); |
| 20 node.attributes.remove('value'); | 17 return new _ValueBinding(node, model, path); |
| 21 _valueBinding = new _ValueBinding(node, model, path); | |
| 22 break; | |
| 23 case 'checked': | |
| 24 unbind('checked'); | |
| 25 node.attributes.remove('checked'); | |
| 26 _checkedBinding = new _CheckedBinding(node, model, path); | |
| 27 break; | |
| 28 default: | |
| 29 super.bind(name, model, path); | |
| 30 break; | |
| 31 } | 18 } |
| 32 } | 19 if (name == 'checked') { |
| 33 | 20 node.attributes.remove(name); |
| 34 void unbind(String name) { | 21 return new _CheckedBinding(node, model, path); |
| 35 switch (name.toLowerCase()) { | |
| 36 case 'value': | |
| 37 if (_valueBinding != null) { | |
| 38 _valueBinding.unbind(); | |
| 39 _valueBinding = null; | |
| 40 } | |
| 41 break; | |
| 42 case 'checked': | |
| 43 if (_checkedBinding != null) { | |
| 44 _checkedBinding.unbind(); | |
| 45 _checkedBinding = null; | |
| 46 } | |
| 47 break; | |
| 48 default: | |
| 49 super.unbind(name); | |
| 50 break; | |
| 51 } | 22 } |
| 52 } | 23 return super.createBinding(name, model, path); |
| 53 | |
| 54 void unbindAll() { | |
| 55 unbind('value'); | |
| 56 unbind('checked'); | |
| 57 super.unbindAll(); | |
| 58 } | 24 } |
| 59 } | 25 } |
| OLD | NEW |