| 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 /// Code from declaration/events.js | 5 /// Code from declaration/events.js |
| 6 part of polymer; | 6 part of polymer; |
| 7 | 7 |
| 8 /// An extension of [polymer_expressions.PolymerExpressions] that adds support | 8 /// An extension of [polymer_expressions.PolymerExpressions] that adds support |
| 9 /// for binding events using `on-eventName` using [PolymerEventBindings]. | 9 /// for binding events using `on-eventName` using [PolymerEventBindings]. |
| 10 // TODO(jmesserly): the JS layering is a bit odd, with polymer-dev implementing | 10 // TODO(jmesserly): the JS layering is a bit odd, with polymer-dev implementing |
| 11 // events and polymer-expressions implementing everything else. I don't think | 11 // events and polymer-expressions implementing everything else. I don't think |
| 12 // this separation is right in the long term, so we're using the same class name | 12 // this separation is right in the long term, so we're using the same class name |
| 13 // until we can sort it out. | 13 // until we can sort it out. |
| 14 class PolymerExpressions extends BindingDelegate with PolymerEventBindings { | 14 class PolymerExpressions extends BindingDelegate with PolymerEventBindings { |
| 15 | 15 |
| 16 /// A wrapper around polymer_expressions used to implement forwarding. | 16 /// A wrapper around polymer_expressions used to implement forwarding. |
| 17 /// Ideally we would inherit from it, but mixins can't be applied to a type | 17 /// Ideally we would inherit from it, but mixins can't be applied to a type |
| 18 /// that forwards to a superclass with a constructor that has optional or | 18 /// that forwards to a superclass with a constructor that has optional or |
| 19 /// named arguments. | 19 /// named arguments. |
| 20 final BindingDelegate _delegate; | 20 final polymer_expressions.PolymerExpressions _delegate; |
| 21 |
| 22 Map<String, Object> get globals => _delegate.globals; |
| 21 | 23 |
| 22 PolymerExpressions({Map<String, Object> globals}) | 24 PolymerExpressions({Map<String, Object> globals}) |
| 23 : _delegate = new polymer_expressions.PolymerExpressions( | 25 : _delegate = new polymer_expressions.PolymerExpressions( |
| 24 globals: globals); | 26 globals: globals); |
| 25 | 27 |
| 26 prepareBinding(String path, name, node) { | 28 prepareBinding(String path, name, node) { |
| 27 if (_hasEventPrefix(name)) { | 29 if (_hasEventPrefix(name)) { |
| 28 return prepareEventBinding(path, name, node); | 30 return prepareEventBinding(path, name, node); |
| 29 } | 31 } |
| 30 return _delegate.prepareBinding(path, name, node); | 32 return _delegate.prepareBinding(path, name, node); |
| 31 } | 33 } |
| 32 | 34 |
| 33 prepareInstanceModel(Element template) => | 35 prepareInstanceModel(Element template) => |
| 34 _delegate.prepareInstanceModel(template); | 36 _delegate.prepareInstanceModel(template); |
| 35 | 37 |
| 36 prepareInstancePositionChanged(Element template) => | 38 prepareInstancePositionChanged(Element template) => |
| 37 _delegate.prepareInstancePositionChanged(template); | 39 _delegate.prepareInstancePositionChanged(template); |
| 40 |
| 41 static final getExpression = |
| 42 polymer_expressions.PolymerExpressions.getExpression; |
| 43 static final getBinding = polymer_expressions.PolymerExpressions.getBinding; |
| 44 |
| 38 } | 45 } |
| 39 | 46 |
| 40 /// A mixin for a [BindingDelegate] to add Polymer event support. | 47 /// A mixin for a [BindingDelegate] to add Polymer event support. |
| 41 /// This is included in [PolymerExpressions]. | 48 /// This is included in [PolymerExpressions]. |
| 42 abstract class PolymerEventBindings { | 49 abstract class PolymerEventBindings { |
| 43 /// Finds the event controller for this node. | 50 /// Finds the event controller for this node. |
| 44 Element findController(Node node) { | 51 Element findController(Node node) { |
| 45 while (node.parentNode != null) { | 52 while (node.parentNode != null) { |
| 46 if (node is Polymer && node.eventController != null) { | 53 if (node is Polymer && node.eventController != null) { |
| 47 return node.eventController; | 54 return node.eventController; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return map; | 158 return map; |
| 152 }(); | 159 }(); |
| 153 | 160 |
| 154 // Dart note: we need this function because we have additional renames JS does | 161 // Dart note: we need this function because we have additional renames JS does |
| 155 // not have. The JS renames are simply case differences, whereas we have ones | 162 // not have. The JS renames are simply case differences, whereas we have ones |
| 156 // like doubleclick -> dblclick and stripping the webkit prefix. | 163 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 157 String _eventNameFromType(String eventType) { | 164 String _eventNameFromType(String eventType) { |
| 158 final result = _reverseEventTranslations[eventType]; | 165 final result = _reverseEventTranslations[eventType]; |
| 159 return result != null ? result : eventType; | 166 return result != null ? result : eventType; |
| 160 } | 167 } |
| OLD | NEW |