OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 |
| 11 <link rel="import" href="../lib/gestures.html"> |
| 12 |
| 13 <script> |
| 14 |
| 15 /** |
| 16 * Supports `listeners` and `keyPresses` objects. |
| 17 * |
| 18 * Example: |
| 19 * |
| 20 * using('Base', function(Base) { |
| 21 * |
| 22 * Polymer({ |
| 23 * |
| 24 * listeners: { |
| 25 * // `click` events on the host are delegated to `clickHandler` |
| 26 * 'click': 'clickHandler' |
| 27 * }, |
| 28 * |
| 29 * keyPresses: { |
| 30 * // 'ESC' key presses are delegated to `escHandler` |
| 31 * Base.ESC_KEY: 'escHandler' |
| 32 * }, |
| 33 * |
| 34 * ... |
| 35 * |
| 36 * }); |
| 37 * |
| 38 * }); |
| 39 * |
| 40 * @class standard feature: events |
| 41 * |
| 42 */ |
| 43 |
| 44 Polymer.Base._addFeature({ |
| 45 |
| 46 listeners: {}, |
| 47 |
| 48 _listenListeners: function(listeners) { |
| 49 var node, name, key; |
| 50 for (key in listeners) { |
| 51 if (key.indexOf('.') < 0) { |
| 52 node = this; |
| 53 name = key; |
| 54 } else { |
| 55 name = key.split('.'); |
| 56 node = this.$[name[0]]; |
| 57 name = name[1]; |
| 58 } |
| 59 this.listen(node, name, listeners[key]); |
| 60 } |
| 61 }, |
| 62 |
| 63 listen: function(node, eventName, methodName) { |
| 64 var host = this; |
| 65 var handler = function(e) { |
| 66 if (host[methodName]) { |
| 67 host[methodName](e, e.detail); |
| 68 } else { |
| 69 console.warn('[%s].[%s]: event handler [%s] is null in scope (%o)', |
| 70 node.localName, eventName, methodName, host); |
| 71 } |
| 72 }; |
| 73 switch (eventName) { |
| 74 case 'tap': |
| 75 case 'track': |
| 76 Polymer.Gestures.add(eventName, node, handler); |
| 77 break; |
| 78 |
| 79 default: |
| 80 node.addEventListener(eventName, handler); |
| 81 break; |
| 82 } |
| 83 }, |
| 84 |
| 85 keyCodes: { |
| 86 ESC_KEY: 27, |
| 87 ENTER_KEY: 13, |
| 88 LEFT: 37, |
| 89 UP: 38, |
| 90 RIGHT: 39, |
| 91 DOWN: 40, |
| 92 SPACE: 32 |
| 93 } |
| 94 |
| 95 }); |
| 96 |
| 97 </script> |
OLD | NEW |