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 properties: { | 28 properties: { |
| 29 enablePassword: { | |
|
jdufault
2016/06/28 23:06:09
Document this
sammiequon
2016/06/29 19:44:07
Done.
| |
| 30 type: Boolean, | |
| 31 value: false, | |
| 32 observer: 'onInputTypeChange_' | |
|
jdufault
2016/06/28 23:06:09
nit: rename to onEnablePasswordChange_
sammiequon
2016/06/29 19:44:07
Done.
| |
| 33 }, | |
| 34 | |
| 35 placeholder: { | |
|
jdufault
2016/06/28 23:06:09
This should be private; the value for this should
sammiequon
2016/06/29 19:44:07
Done.
| |
| 36 type: String, | |
| 37 value: '', | |
|
jdufault
2016/06/28 23:06:09
Since enablePassword defaults to false this should
sammiequon
2016/06/29 19:44:07
I do not think this works, my current default is E
| |
| 38 observer: 'onPlaceHolderChange_' | |
|
jdufault
2016/06/28 23:06:09
Instead of using an observer to update the element
sammiequon
2016/06/29 19:44:08
Done.
| |
| 39 }, | |
| 40 | |
| 29 /** The value stored in the keyboard's input element. */ | 41 /** The value stored in the keyboard's input element. */ |
| 30 value: { | 42 value: { |
| 31 type: String, | 43 type: String, |
| 32 notify: true, | 44 notify: true, |
| 33 value: '', | 45 value: '', |
| 34 observer: 'onPinValueChange_' | 46 observer: 'onPinValueChange_' |
| 35 } | 47 } |
| 36 }, | 48 }, |
| 37 | 49 |
| 38 /** Transfers focus to the input element. */ | 50 /** Transfers focus to the input element. */ |
| 39 focus: function() { | 51 focus: function() { |
| 40 this.$$('#pin-input').focus(); | 52 this.$$('#pin-input').focus(); |
| 41 }, | 53 }, |
| 42 | 54 |
| 43 /** Called when a keypad number has been tapped. */ | 55 /** Called when a keypad number has been tapped. */ |
| 44 onNumberTap_: function(event, detail) { | 56 onNumberTap_: function(event, detail) { |
| 45 var numberValue = event.target.getAttribute('value'); | 57 var numberValue = event.target.getAttribute('value'); |
| 46 this.value += numberValue; | 58 this.value += numberValue; |
| 47 }, | 59 }, |
| 48 | 60 |
| 49 /** Fires a submit event with the current PIN value. */ | 61 /** Fires a submit event with the current PIN value. */ |
| 50 firePinSubmitEvent_: function() { | 62 firePinSubmitEvent_: function() { |
| 51 this.fire('submit', { pin: this.value }); | 63 this.fire('submit', { pin: this.value }); |
| 52 }, | 64 }, |
| 53 | 65 |
| 66 /** Changes the pin or password input based on the contents of the | |
| 67 * password. */ | |
| 68 updateRtlState_: function(password) { | |
| 69 // Converts a password to number, then verifies there are no periods/etc. | |
|
jdufault
2016/06/28 23:06:09
Instead of hooking into the pin-change event, we c
sammiequon
2016/06/29 19:44:08
Done.
| |
| 70 var isNumeric = Number.isInteger(+password); | |
| 71 this.$$('#pin-input').classList.toggle( | |
| 72 'pin-keyboard-input-non-pin', !isNumeric); | |
| 73 }, | |
| 74 | |
| 54 /** | 75 /** |
| 55 * Fires an update event with the current PIN value. The event will only be | 76 * Fires an update event with the current PIN value. The event will only be |
| 56 * fired if the PIN value has actually changed. | 77 * fired if the PIN value has actually changed. |
| 57 * @param {string} value | 78 * @param {string} value |
| 58 * @param {string} previous | 79 * @param {string} previous |
| 59 */ | 80 */ |
| 60 onPinValueChange_: function(value, previous) { | 81 onPinValueChange_: function(value, previous) { |
| 61 if (value != previous) | 82 if (value != previous) { |
| 62 this.fire('pin-change', { pin: value }); | 83 this.fire('pin-change', { pin: value }); |
| 84 this.updateRtlState_(value); | |
| 85 } | |
| 63 }, | 86 }, |
| 64 | 87 |
| 65 /** Called when the user wants to erase the last character of the entered | 88 /** Called when the user wants to erase the last character of the entered |
| 66 * PIN value. | 89 * PIN value. |
| 67 */ | 90 */ |
| 68 onPinClear_: function() { | 91 onPinClear_: function() { |
| 69 this.value = this.value.substring(0, this.value.length - 1); | 92 this.value = this.value.substring(0, this.value.length - 1); |
| 70 }, | 93 }, |
| 71 | 94 |
| 72 /** Called when a key event is pressed while the input element has focus. */ | 95 /** Called when a key event is pressed while the input element has focus. */ |
| 73 onInputKeyDown_: function(event) { | 96 onInputKeyDown_: function(event) { |
| 74 // Up/down pressed, swallow the event to prevent the input value from | 97 // Up/down pressed, swallow the event to prevent the input value from |
| 75 // being incremented or decremented. | 98 // being incremented or decremented. |
| 76 if (event.keyCode == 38 || event.keyCode == 40) { | 99 if (event.keyCode == 38 || event.keyCode == 40) { |
| 77 event.preventDefault(); | 100 event.preventDefault(); |
| 78 return; | 101 return; |
| 79 } | 102 } |
| 80 | 103 |
| 81 // Enter pressed. | 104 // Enter pressed. |
| 82 if (event.keyCode == 13) { | 105 if (event.keyCode == 13) { |
| 83 this.firePinSubmitEvent_(); | 106 this.firePinSubmitEvent_(); |
| 84 event.preventDefault(); | 107 event.preventDefault(); |
| 85 return; | 108 return; |
| 86 } | 109 } |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * Changes the input type for the pin-keyboard input element, based on the | |
| 114 * input specified for the pin-keyboard. | |
| 115 * @param {string} value | |
| 116 */ | |
| 117 onInputTypeChange_: function(value) { | |
| 118 if (value) | |
| 119 this.$$('#pin-input').type = 'password'; | |
|
jdufault
2016/06/28 23:06:09
Let's bind the input type to a property. The prope
sammiequon
2016/06/29 19:44:07
Done.
| |
| 120 else | |
| 121 this.$$('#pin-input').type = 'number'; | |
| 122 }, | |
| 123 | |
| 124 /** | |
| 125 * Changes the placeholder text for the pin-keyboard input element, | |
| 126 * based on the i18n placeholder specified for the pin-keyboard. | |
| 127 * @param {string} value | |
| 128 */ | |
| 129 onPlaceHolderChange_: function(value) { | |
| 130 this.$$('#pin-input').placeholder = value; | |
| 87 } | 131 } |
| 88 }); | 132 }); |
| OLD | NEW |