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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 return node is ShadowRoot ? node.host : null; | 51 return node is ShadowRoot ? node.host : null; |
52 } | 52 } |
53 | 53 |
54 EventListener getEventHandler(controller, target, String method) => (e) { | 54 EventListener getEventHandler(controller, target, String method) => (e) { |
55 if (controller == null || controller is! Polymer) { | 55 if (controller == null || controller is! Polymer) { |
56 controller = findController(target); | 56 controller = findController(target); |
57 } | 57 } |
58 | 58 |
59 if (controller is Polymer) { | 59 if (controller is Polymer) { |
60 var args = [e, e.detail, e.currentTarget]; | 60 var detail = null; |
| 61 if (e is CustomEvent) { |
| 62 detail = e.detail; |
| 63 // TODO(sigmund): this shouldn't be necessary. See issue 19315. |
| 64 if (detail == null) { |
| 65 detail = new JsObject.fromBrowserObject(e)['detail']; |
| 66 } |
| 67 } |
| 68 var args = [e, detail, e.currentTarget]; |
61 controller.dispatchMethod(controller, method, args); | 69 controller.dispatchMethod(controller, method, args); |
62 } else { | 70 } else { |
63 throw new StateError('controller $controller is not a ' | 71 throw new StateError('controller $controller is not a ' |
64 'Dart polymer-element.'); | 72 'Dart polymer-element.'); |
65 } | 73 } |
66 }; | 74 }; |
67 | 75 |
68 prepareEventBinding(String path, String name, Node node) { | 76 prepareEventBinding(String path, String name, Node node) { |
69 if (!_hasEventPrefix(name)) return null; | 77 if (!_hasEventPrefix(name)) return null; |
70 | 78 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return map; | 148 return map; |
141 }(); | 149 }(); |
142 | 150 |
143 // Dart note: we need this function because we have additional renames JS does | 151 // Dart note: we need this function because we have additional renames JS does |
144 // not have. The JS renames are simply case differences, whereas we have ones | 152 // not have. The JS renames are simply case differences, whereas we have ones |
145 // like doubleclick -> dblclick and stripping the webkit prefix. | 153 // like doubleclick -> dblclick and stripping the webkit prefix. |
146 String _eventNameFromType(String eventType) { | 154 String _eventNameFromType(String eventType) { |
147 final result = _reverseEventTranslations[eventType]; | 155 final result = _reverseEventTranslations[eventType]; |
148 return result != null ? result : eventType; | 156 return result != null ? result : eventType; |
149 } | 157 } |
OLD | NEW |