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 passowrd. | |
|
jdufault
2016/06/29 21:06:29
nit: password
sammiequon
2016/06/29 23:35:48
Done.
| |
| 36 */ | |
| 37 enablePassword: { | |
| 38 type: Boolean, | |
| 39 value: false, | |
| 40 observer: 'onEnablePasswordChange_' | |
| 41 }, | |
| 42 | |
| 43 /** | |
| 44 * @private | |
| 45 * Stores the input type of the keyboard's input element. | |
| 46 */ | |
| 47 inputType_: { | |
| 48 type: String, | |
| 49 value: 'password' | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * @private | |
| 54 * Stores the placeholder of the keyboard's input element. | |
| 55 */ | |
| 56 placeholder_: { | |
| 57 type: String, | |
| 58 value: 'Enter PIN' | |
| 59 }, | |
| 60 | |
| 29 /** The value stored in the keyboard's input element. */ | 61 /** The value stored in the keyboard's input element. */ |
| 30 value: { | 62 value: { |
| 31 type: String, | 63 type: String, |
| 32 notify: true, | 64 notify: true, |
| 33 value: '', | 65 value: '', |
| 34 observer: 'onPinValueChange_' | 66 observer: 'onPinValueChange_' |
| 35 } | 67 } |
| 36 }, | 68 }, |
| 37 | 69 |
| 38 /** Transfers focus to the input element. */ | 70 /** Transfers focus to the input element. */ |
| 39 focus: function() { | 71 focus: function() { |
| 40 this.$$('#pin-input').focus(); | 72 this.$$('#pin-input').focus(); |
| 41 }, | 73 }, |
| 42 | 74 |
| 43 /** Called when a keypad number has been tapped. */ | 75 /** Called when a keypad number has been tapped. */ |
| 44 onNumberTap_: function(event, detail) { | 76 onNumberTap_: function(event, detail) { |
| 45 var numberValue = event.target.getAttribute('value'); | 77 var numberValue = event.target.getAttribute('value'); |
| 46 this.value += numberValue; | 78 this.value += numberValue; |
| 47 }, | 79 }, |
| 48 | 80 |
| 49 /** Fires a submit event with the current PIN value. */ | 81 /** Fires a submit event with the current PIN value. */ |
| 50 firePinSubmitEvent_: function() { | 82 firePinSubmitEvent_: function() { |
| 51 this.fire('submit', { pin: this.value }); | 83 this.fire('submit', { pin: this.value }); |
| 52 }, | 84 }, |
| 53 | 85 |
| 86 /** Changes the pin or password input based on the contents of the | |
| 87 * password. */ | |
|
jdufault
2016/06/29 21:06:29
Maybe move this function definition to the bottom
sammiequon
2016/06/29 23:35:48
Done.
| |
| 88 computeRtlState_: function(password) { | |
| 89 // Converts a password to number, then verifies there are no periods/etc. | |
|
jdufault
2016/06/29 21:06:29
Can you make the comment be a bit more specific? M
sammiequon
2016/06/29 23:35:48
Done.
| |
| 90 var isNumeric = Number.isInteger(+password); | |
| 91 var enableRtl = !isNumeric && (document.dir == 'rtl'); | |
|
jdufault
2016/06/29 21:06:29
I'd put the document.dir == 'rtl' condition first
sammiequon
2016/06/29 23:35:48
Done.
| |
| 92 var newClass = enableRtl ? 'pin-keyboard-input-non-pin' : ''; | |
| 93 return newClass; | |
|
jdufault
2016/06/29 21:06:29
Eliminate the newClass var and directly return the
sammiequon
2016/06/29 23:35:48
Done.
| |
| 94 }, | |
| 95 | |
| 54 /** | 96 /** |
| 55 * Fires an update event with the current PIN value. The event will only be | 97 * Fires an update event with the current PIN value. The event will only be |
| 56 * fired if the PIN value has actually changed. | 98 * fired if the PIN value has actually changed. |
| 57 * @param {string} value | 99 * @param {string} value |
| 58 * @param {string} previous | 100 * @param {string} previous |
| 59 */ | 101 */ |
| 60 onPinValueChange_: function(value, previous) { | 102 onPinValueChange_: function(value, previous) { |
| 61 if (value != previous) | 103 if (value != previous) |
| 62 this.fire('pin-change', { pin: value }); | 104 this.fire('pin-change', { pin: value }); |
| 63 }, | 105 }, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 77 event.preventDefault(); | 119 event.preventDefault(); |
| 78 return; | 120 return; |
| 79 } | 121 } |
| 80 | 122 |
| 81 // Enter pressed. | 123 // Enter pressed. |
| 82 if (event.keyCode == 13) { | 124 if (event.keyCode == 13) { |
| 83 this.firePinSubmitEvent_(); | 125 this.firePinSubmitEvent_(); |
| 84 event.preventDefault(); | 126 event.preventDefault(); |
| 85 return; | 127 return; |
| 86 } | 128 } |
| 129 }, | |
| 130 | |
| 131 /** | |
| 132 * Changes the input type for the pin-keyboard input element, based on the | |
| 133 * input specified for the pin-keyboard. | |
| 134 * @param {boolean} value describes when passwords are accepted | |
| 135 */ | |
| 136 onEnablePasswordChange_: function(value) { | |
| 137 this.inputType_ = value ? 'password' : 'number'; | |
| 138 this.placeholder_ = value ? this.i18n('pinKeyboardPlaceholderPinPassword') : | |
|
jdufault
2016/06/29 21:06:29
The placeholder_ and inputType_ can be removed if
sammiequon
2016/06/29 23:35:48
Done.
| |
| 139 this.i18n('pinKeyboardPlaceholderPin'); | |
| 87 } | 140 } |
| 88 }); | 141 }); |
| OLD | NEW |