Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'pin-keyboard' is a keyboard that can be used to enter PINs or more generally | 7 * 'pin-keyboard' is a keyboard that can be used to enter PINs or more generally |
| 8 * numeric values. | 8 * numeric values. |
| 9 * | 9 * |
| 10 * Properties: | 10 * Properties: |
| 11 * value: The value of the PIN keyboard. Writing to this property will adjust | 11 * value: The value of the PIN keyboard. Writing to this property will adjust |
| 12 * the PIN keyboard's value. | 12 * the PIN keyboard's value. |
| 13 * | 13 * |
| 14 * Events: | 14 * Events: |
| 15 * pin-change: Fired when the PIN value has changed. The pin is available at | 15 * pin-change: Fired when the PIN value has changed. The pin is available at |
| 16 * event.detail.pin. | 16 * event.detail.pin. |
| 17 * submit: Fired when the PIN is submitted. The pin is available at | 17 * submit: Fired when the PIN is submitted. The pin is available at |
| 18 * event.detail.pin. | 18 * event.detail.pin. |
| 19 * | 19 * |
| 20 * Example: | 20 * Example: |
| 21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit" | 21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit" |
| 22 * value="{{pinValue}}"> | 22 * value="{{pinValue}}"> |
| 23 * </pin-keyboard> | 23 * </pin-keyboard> |
| 24 */ | 24 */ |
| 25 Polymer({ | 25 Polymer({ |
| 26 is: 'pin-keyboard', | 26 is: 'pin-keyboard', |
| 27 | 27 |
| 28 behaviors: [ | |
| 29 I18nBehavior, | |
| 30 ], | |
| 31 | |
| 28 properties: { | 32 properties: { |
| 33 /** | |
| 34 * Whether or not the keyboard's input element should be numerical | |
| 35 * or password. | |
| 36 */ | |
| 37 enablePassword: { | |
| 38 type: Boolean, | |
| 39 value: false | |
| 40 }, | |
| 41 | |
| 29 /** The value stored in the keyboard's input element. */ | 42 /** The value stored in the keyboard's input element. */ |
| 30 value: { | 43 value: { |
| 31 type: String, | 44 type: String, |
| 32 notify: true, | 45 notify: true, |
| 33 value: '', | 46 value: '', |
| 34 observer: 'onPinValueChange_' | 47 observer: 'onPinValueChange_' |
| 35 } | 48 } |
| 36 }, | 49 }, |
| 37 | 50 |
| 38 /** Transfers focus to the input element. */ | 51 /** Transfers focus to the input element. */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 event.preventDefault(); | 90 event.preventDefault(); |
| 78 return; | 91 return; |
| 79 } | 92 } |
| 80 | 93 |
| 81 // Enter pressed. | 94 // Enter pressed. |
| 82 if (event.keyCode == 13) { | 95 if (event.keyCode == 13) { |
| 83 this.firePinSubmitEvent_(); | 96 this.firePinSubmitEvent_(); |
| 84 event.preventDefault(); | 97 event.preventDefault(); |
| 85 return; | 98 return; |
| 86 } | 99 } |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * Computes whether the input type for the pin input should be password or | |
| 104 * numerical. | |
|
jdufault
2016/06/30 18:22:12
All three methods should have an @private annotati
sammiequon
2016/06/30 22:18:41
Done.
| |
| 105 */ | |
| 106 computeInputType_: function(enablePassword) { | |
| 107 return enablePassword ? 'password' : 'number'; | |
| 108 }, | |
| 109 | |
| 110 /** Computes the value of the pin input placeholder. */ | |
| 111 computeInputPlaceholder_: function(enablePassword) { | |
| 112 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : | |
| 113 this.i18n('pinKeyboardPlaceholderPin'); | |
| 114 }, | |
| 115 | |
| 116 /** Computes the direction of the pin input. */ | |
| 117 computeInputClass_: function(password) { | |
| 118 // +password will convert a string to a number or to NaN if that's not | |
| 119 // possible. Number.isInteger will verify the value is not a NaN and that it | |
| 120 // does not contain decimals. | |
| 121 // | |
| 122 // This heuristic will fail for inputs like '1.0'. | |
| 123 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); | |
| 124 return enableRtl ? 'input-non-pin' : ''; | |
| 87 } | 125 } |
| 88 }); | 126 }); |
| OLD | NEW |