| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of mdv; | |
| 6 | |
| 7 /** Extensions to the [Element] API. */ | |
| 8 class _ElementExtension extends _NodeExtension { | |
| 9 _ElementExtension(Element node) : super(node); | |
| 10 | |
| 11 // TODO(jmesserly): should path be optional, and default to empty path? | |
| 12 // It is used that way in at least one path in JS TemplateElement tests | |
| 13 // (see "BindImperative" test in original JS code). | |
| 14 NodeBinding createBinding(String name, model, String path) => | |
| 15 new _AttributeBinding(node, name, model, path); | |
| 16 | |
| 17 // Normally we issue this error in Element._ensureTemplate, but we | |
| 18 // avoid calling that from the model getter, so issue the error here. | |
| 19 get model => throw new UnsupportedError('$node is not a template.'); | |
| 20 } | |
| 21 | |
| 22 class _AttributeBinding extends NodeBinding { | |
| 23 final bool conditional; | |
| 24 | |
| 25 _AttributeBinding._(node, name, model, path, this.conditional) | |
| 26 : super(node, name, model, path); | |
| 27 | |
| 28 factory _AttributeBinding(Element node, name, model, path) { | |
| 29 bool conditional = name.endsWith('?'); | |
| 30 if (conditional) { | |
| 31 node.xtag.attributes.remove(name); | |
| 32 name = name.substring(0, name.length - 1); | |
| 33 } | |
| 34 return new _AttributeBinding._(node, name, model, path, conditional); | |
| 35 } | |
| 36 | |
| 37 Element get node => super.node; | |
| 38 | |
| 39 void boundValueChanged(value) { | |
| 40 if (conditional) { | |
| 41 if (_toBoolean(value)) { | |
| 42 node.xtag.attributes[property] = ''; | |
| 43 } else { | |
| 44 node.xtag.attributes.remove(property); | |
| 45 } | |
| 46 } else { | |
| 47 // TODO(jmesserly): escape value if needed to protect against XSS. | |
| 48 // See https://github.com/polymer-project/mdv/issues/58 | |
| 49 node.xtag.attributes[property] = sanitizeBoundValue(value); | |
| 50 } | |
| 51 } | |
| 52 } | |
| OLD | NEW |