| 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 library polymer.event; | 5 library polymer.event; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'custom_element.dart'; | 8 import 'package:custom_element/custom_element.dart'; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * *Warning*: this is an implementation helper and should not be used in your | 11 * *Warning*: this is an implementation helper and should not be used in your |
| 12 * code. This method will be replaced in favor of calling to the handler | 12 * code. This method will be replaced in favor of calling to the handler |
| 13 * via mirrors. | 13 * via mirrors. |
| 14 * | 14 * |
| 15 * Register an event handler. | 15 * Register an event handler. |
| 16 */ | 16 */ |
| 17 void registerEventHandler(String query, void registerEvent(Node node)) { | 17 void registerEventHandler(String query, void registerEvent(Node node)) { |
| 18 if (_eventHandlers == null) { | 18 if (_eventHandlers == null) { |
| 19 _eventHandlers = {}; | 19 _eventHandlers = {}; |
| 20 CustomElement.templateCreated.add(_hookEvents); | 20 CustomElement.templateCreated.add(_hookEvents); |
| 21 } | 21 } |
| 22 if (_eventHandlers.containsKey(query)) { | 22 if (_eventHandlers.containsKey(query)) { |
| 23 throw new ArgumentError('duplicate event handler selector $query'); | 23 throw new ArgumentError('duplicate event handler selector $query'); |
| 24 } | 24 } |
| 25 _eventHandlers[query] = registerEvent; | 25 _eventHandlers[query] = registerEvent; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void _hookEvents(DocumentFragment fragment) { | 28 void _hookEvents(DocumentFragment fragment) { |
| 29 _eventHandlers.forEach((query, hookEvent) { | 29 _eventHandlers.forEach((query, hookEvent) { |
| 30 for (var node in fragment.queryAll(query)) { | 30 for (var node in fragment.queryAll(query)) { |
| 31 hookEvent(node); | 31 hookEvent(node); |
| 32 } | 32 } |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 Map<String, Function> _eventHandlers; | 36 Map<String, Function> _eventHandlers; |
| OLD | NEW |