| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 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="../../polymer/polymer.html"> |
| 12 <link rel="import" href="../../paper-styles/paper-styles.html"> |
| 13 <link rel="import" href="../iron-a11y-keys-behavior.html"> |
| 14 |
| 15 <dom-module id="x-key-aware"> |
| 16 <style> |
| 17 :host { |
| 18 display: block; |
| 19 position: relative; |
| 20 } |
| 21 |
| 22 pre { |
| 23 color: var(--google-blue-700); |
| 24 } |
| 25 |
| 26 .keys { |
| 27 line-height: 25px; |
| 28 } |
| 29 |
| 30 .keys span { |
| 31 cursor: default; |
| 32 background-color: var(--google-grey-100); |
| 33 border: 1px solid var(--google-grey-300); |
| 34 padding: 1px 5px; |
| 35 border-radius: 5px; |
| 36 } |
| 37 </style> |
| 38 <template> |
| 39 <h4>Press any of these keys</h4> |
| 40 <p class="keys"> |
| 41 <template is="dom-repeat" items="[[boundKeys]]"> |
| 42 <span>{{item}}</span> |
| 43 </template> |
| 44 </p> |
| 45 <pre>[[pressed]]</pre> |
| 46 </template> |
| 47 </dom-module> |
| 48 |
| 49 <script> |
| 50 Polymer({ |
| 51 is: 'x-key-aware', |
| 52 |
| 53 behaviors: [ |
| 54 Polymer.IronA11yKeysBehavior |
| 55 ], |
| 56 |
| 57 properties: { |
| 58 pressed: { |
| 59 type: String, |
| 60 readOnly: true, |
| 61 value: '' |
| 62 }, |
| 63 |
| 64 boundKeys: { |
| 65 type: Array, |
| 66 value: function() { |
| 67 return Object.keys(this.keyBindings).join(' ').split(' '); |
| 68 } |
| 69 }, |
| 70 |
| 71 keyEventTarget: { |
| 72 type: Object, |
| 73 value: function() { |
| 74 return document.body; |
| 75 } |
| 76 } |
| 77 }, |
| 78 |
| 79 keyBindings: { |
| 80 '* pageup pagedown left right down up shift+a alt+a home end space enter':
'_updatePressed' |
| 81 }, |
| 82 |
| 83 _updatePressed: function(event) { |
| 84 console.log(event.detail); |
| 85 |
| 86 this._setPressed( |
| 87 this.pressed + event.detail.combo + ' pressed!\n' |
| 88 ); |
| 89 } |
| 90 }); |
| 91 </script> |
| OLD | NEW |