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