OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 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://polym
er.github.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polym
er.github.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS
.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/CO
NTRIBUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CO
NTRIBUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 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/P
ATENTS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/P
ATENTS.txt |
9 --> | 9 --> |
10 | 10 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 'U+007F': 'del' | 135 'U+007F': 'del' |
136 }; | 136 }; |
137 | 137 |
138 /* | 138 /* |
139 * Special table for KeyboardEvent.keyCode. | 139 * Special table for KeyboardEvent.keyCode. |
140 * KeyboardEvent.keyIdentifier is better, and KeyBoardEvent.key is even bett
er than that | 140 * KeyboardEvent.keyIdentifier is better, and KeyBoardEvent.key is even bett
er than that |
141 * | 141 * |
142 * Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve
nt.keyCode#Value_of_keyCode | 142 * Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve
nt.keyCode#Value_of_keyCode |
143 */ | 143 */ |
144 var KEY_CODE = { | 144 var KEY_CODE = { |
| 145 9: 'tab', |
145 13: 'enter', | 146 13: 'enter', |
146 27: 'esc', | 147 27: 'esc', |
147 33: 'pageup', | 148 33: 'pageup', |
148 34: 'pagedown', | 149 34: 'pagedown', |
149 35: 'end', | 150 35: 'end', |
150 36: 'home', | 151 36: 'home', |
151 32: 'space', | 152 32: 'space', |
152 37: 'left', | 153 37: 'left', |
153 38: 'up', | 154 38: 'up', |
154 39: 'right', | 155 39: 'right', |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // num pad 0-9 | 215 // num pad 0-9 |
215 validKey = String(96 - keyCode); | 216 validKey = String(96 - keyCode); |
216 } else { | 217 } else { |
217 validKey = KEY_CODE[keyCode]; | 218 validKey = KEY_CODE[keyCode]; |
218 } | 219 } |
219 } | 220 } |
220 return validKey; | 221 return validKey; |
221 } | 222 } |
222 | 223 |
223 function keyboardEventToKey(ev) { | 224 function keyboardEventToKey(ev) { |
224 // fall back from .key, to .keyIdentifier, and then to .keyCode | 225 // fall back from .key, to .keyIdentifier, to .keyCode, and then to .detai
l.key to support artificial keyboard events |
225 var normalizedKey = transformKey(ev.key) || transformKeyIdentifier(ev.keyI
dentifier) || transformKeyCode(ev.keyCode) || ''; | 226 var normalizedKey = transformKey(ev.key) || transformKeyIdentifier(ev.keyI
dentifier) || transformKeyCode(ev.keyCode) || transformKey(ev.detail.key) || ''; |
226 return { | 227 return { |
227 shift: ev.shiftKey, | 228 shift: ev.shiftKey, |
228 ctrl: ev.ctrlKey, | 229 ctrl: ev.ctrlKey, |
229 meta: ev.metaKey, | 230 meta: ev.metaKey, |
230 alt: ev.altKey, | 231 alt: ev.altKey, |
231 key: normalizedKey | 232 key: normalizedKey |
232 }; | 233 }; |
233 } | 234 } |
234 | 235 |
235 /* | 236 /* |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 if (node && node.removeEventListener) { | 286 if (node && node.removeEventListener) { |
286 node.removeEventListener('keydown', handler); | 287 node.removeEventListener('keydown', handler); |
287 } | 288 } |
288 } | 289 } |
289 | 290 |
290 Polymer('core-a11y-keys', { | 291 Polymer('core-a11y-keys', { |
291 created: function() { | 292 created: function() { |
292 this._keyHandler = processKeys.bind(this); | 293 this._keyHandler = processKeys.bind(this); |
293 }, | 294 }, |
294 attached: function() { | 295 attached: function() { |
| 296 if (!this.target) { |
| 297 this.target = this.parentNode; |
| 298 } |
295 listen(this.target, this._keyHandler); | 299 listen(this.target, this._keyHandler); |
296 }, | 300 }, |
297 detached: function() { | 301 detached: function() { |
298 unlisten(this.target, this._keyHandler); | 302 unlisten(this.target, this._keyHandler); |
299 }, | 303 }, |
300 publish: { | 304 publish: { |
301 /** | 305 /** |
302 * The set of key combinations to listen for. | 306 * The set of key combinations to listen for. |
303 * | 307 * |
304 * @attribute keys | 308 * @attribute keys |
305 * @type string (keys syntax) | 309 * @type string (keys syntax) |
306 * @default '' | 310 * @default '' |
307 */ | 311 */ |
308 keys: '', | 312 keys: '', |
309 /** | 313 /** |
310 * The node that will fire keyboard events. | 314 * The node that will fire keyboard events. |
| 315 * Default to this element's parentNode unless one is assigned |
311 * | 316 * |
312 * @attribute target | 317 * @attribute target |
313 * @type Node | 318 * @type Node |
314 * @default null | 319 * @default this.parentNode |
315 */ | 320 */ |
316 target: null | 321 target: null |
317 }, | 322 }, |
318 keysChanged: function() { | 323 keysChanged: function() { |
319 // * can have multiple mappings: shift+8, * on numpad or Multiply on num
pad | 324 // * can have multiple mappings: shift+8, * on numpad or Multiply on num
pad |
320 var normalized = this.keys.replace('*', '* shift+*'); | 325 var normalized = this.keys.replace('*', '* shift+*'); |
321 this._desiredKeys = normalized.toLowerCase().split(' ').map(stringToKey)
; | 326 this._desiredKeys = normalized.toLowerCase().split(' ').map(stringToKey)
; |
322 }, | 327 }, |
323 targetChanged: function(oldTarget) { | 328 targetChanged: function(oldTarget) { |
324 unlisten(oldTarget, this._keyHandler); | 329 unlisten(oldTarget, this._keyHandler); |
325 listen(this.target, this._keyHandler); | 330 listen(this.target, this._keyHandler); |
326 } | 331 } |
327 }); | 332 }); |
328 })(); | 333 })(); |
329 </script> | 334 </script> |
330 </polymer-element> | 335 </polymer-element> |
OLD | NEW |