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

Side by Side Diff: pkg/template_binding/lib/src/element.dart

Issue 34453003: Rename mdv -> template_binding, remove experiemntal apis from dart:html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 template_binding;
6 6
7 /** Extensions to the [Element] API. */ 7 /** Extensions to the [Element] API. */
8 class _ElementExtension extends _NodeExtension { 8 class _ElementExtension extends NodeBindExtension {
9 _ElementExtension(Element node) : super(node); 9 _ElementExtension(Element node) : super._(node);
10 10
11 // TODO(jmesserly): should path be optional, and default to empty path? 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 12 // It is used that way in at least one path in JS TemplateElement tests
13 // (see "BindImperative" test in original JS code). 13 // (see "BindImperative" test in original JS code).
14 NodeBinding createBinding(String name, model, String path) => 14 NodeBinding createBinding(String name, model, String path) =>
15 new _AttributeBinding(node, name, model, 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 } 16 }
21 17
22 class _AttributeBinding extends NodeBinding { 18 class _AttributeBinding extends NodeBinding {
23 final bool conditional; 19 final bool conditional;
24 20
25 _AttributeBinding._(node, name, model, path, this.conditional) 21 _AttributeBinding._(node, name, model, path, this.conditional)
26 : super(node, name, model, path); 22 : super(node, name, model, path);
27 23
28 factory _AttributeBinding(Element node, name, model, path) { 24 factory _AttributeBinding(Element node, name, model, path) {
29 bool conditional = name.endsWith('?'); 25 bool conditional = name.endsWith('?');
30 if (conditional) { 26 if (conditional) {
31 node.xtag.attributes.remove(name); 27 node.attributes.remove(name);
32 name = name.substring(0, name.length - 1); 28 name = name.substring(0, name.length - 1);
33 } 29 }
34 return new _AttributeBinding._(node, name, model, path, conditional); 30 return new _AttributeBinding._(node, name, model, path, conditional);
35 } 31 }
36 32
37 Element get node => super.node; 33 Element get node => super.node;
38 34
39 void boundValueChanged(value) { 35 void boundValueChanged(value) {
40 if (conditional) { 36 if (conditional) {
41 if (_toBoolean(value)) { 37 if (_toBoolean(value)) {
42 node.xtag.attributes[property] = ''; 38 node.attributes[property] = '';
43 } else { 39 } else {
44 node.xtag.attributes.remove(property); 40 node.attributes.remove(property);
45 } 41 }
46 } else { 42 } else {
47 // TODO(jmesserly): escape value if needed to protect against XSS. 43 // TODO(jmesserly): escape value if needed to protect against XSS.
48 // See https://github.com/polymer-project/mdv/issues/58 44 // See https://github.com/polymer-project/mdv/issues/58
49 node.xtag.attributes[property] = sanitizeBoundValue(value); 45 node.attributes[property] = sanitizeBoundValue(value);
50 } 46 }
51 } 47 }
52 } 48 }
OLDNEW
« no previous file with comments | « pkg/polymer_expressions/test/syntax_test.dart ('k') | pkg/template_binding/lib/src/input_bindings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698