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: |
(...skipping 29 matching lines...) Expand all Loading... | |
40 }, | 40 }, |
41 | 41 |
42 /** | 42 /** |
43 * Whether or not the keyboard's submit button should be shown. | 43 * Whether or not the keyboard's submit button should be shown. |
44 */ | 44 */ |
45 enableSubmitButton: { | 45 enableSubmitButton: { |
46 type: Boolean, | 46 type: Boolean, |
47 value: false | 47 value: false |
48 }, | 48 }, |
49 | 49 |
50 /** | |
51 * Whether or not to show an erro. | |
jdufault
2016/08/08 23:47:25
nit: error
sammiequon
2016/08/11 01:03:07
Done.
| |
52 */ | |
53 enableError: { | |
54 type: Boolean, | |
55 value: false | |
56 }, | |
57 | |
50 /** The value stored in the keyboard's input element. */ | 58 /** The value stored in the keyboard's input element. */ |
51 value: { | 59 value: { |
52 type: String, | 60 type: String, |
53 notify: true, | 61 notify: true, |
54 value: '', | 62 value: '', |
55 observer: 'onPinValueChange_' | 63 observer: 'onPinValueChange_' |
56 } | 64 } |
57 }, | 65 }, |
58 | 66 |
59 /** | 67 /** |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 128 |
121 // Enter pressed. | 129 // Enter pressed. |
122 if (event.keyCode == 13) { | 130 if (event.keyCode == 13) { |
123 this.firePinSubmitEvent_(); | 131 this.firePinSubmitEvent_(); |
124 event.preventDefault(); | 132 event.preventDefault(); |
125 return; | 133 return; |
126 } | 134 } |
127 }, | 135 }, |
128 | 136 |
129 /** | 137 /** |
130 * Changes the color of the submit button if PIN is ready. | 138 * Changes the color of the input text if it is not empty. |
131 * @param {string} value | 139 * @param {string} value |
132 * @private | 140 * @private |
133 */ | 141 */ |
134 getSubmitClass_: function(value) { | 142 getContentClass_: function(value) { |
135 return value.length > 0 ? 'ready-background' : ''; | 143 return value.length > 0 ? 'has-content' : ''; |
136 }, | 144 }, |
137 | 145 |
138 /** | 146 /** |
147 * Disables the submit and backspace button if nothing is entered. | |
148 * @param {string} value | |
149 * @private | |
150 */ | |
151 hasInput_: function(value) { | |
152 return value.length > 0; | |
153 }, | |
154 | |
155 /** | |
139 * Computes whether the input type for the pin input should be password or | 156 * Computes whether the input type for the pin input should be password or |
140 * numerical. | 157 * numerical. |
141 * @param {boolean} enablePassword | 158 * @param {boolean} enablePassword |
142 * @private | 159 * @private |
143 */ | 160 */ |
144 getInputType_: function(enablePassword) { | 161 getInputType_: function(enablePassword) { |
145 return enablePassword ? 'password' : 'number'; | 162 return enablePassword ? 'password' : 'number'; |
146 }, | 163 }, |
147 | 164 |
148 /** | 165 /** |
149 * Computes the value of the pin input placeholder. | 166 * Computes the value of the pin input placeholder. |
150 * @param {boolean} enablePassword | 167 * @param {boolean} enablePassword |
151 * @private | 168 * @private |
152 */ | 169 */ |
153 getInputPlaceholder_: function(enablePassword) { | 170 getInputPlaceholder_: function(enablePassword) { |
154 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : | 171 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : |
155 this.i18n('pinKeyboardPlaceholderPin'); | 172 this.i18n('pinKeyboardPlaceholderPin'); |
156 }, | 173 }, |
157 | 174 |
158 /** | 175 /** |
176 * Computes the value of the pin input placeholder. | |
177 * @param {boolean} enablePassword | |
178 * @private | |
179 */ | |
180 getErrorClass_: function(showError) { | |
181 return showError ? 'error-show' : ''; | |
182 }, | |
183 | |
184 /** | |
159 * Computes the direction of the pin input. | 185 * Computes the direction of the pin input. |
160 * @param {string} password | 186 * @param {string} password |
161 * @private | 187 * @private |
162 */ | 188 */ |
163 getInputClass_: function(password) { | 189 getInputClass_: function(password) { |
164 // +password will convert a string to a number or to NaN if that's not | 190 // +password will convert a string to a number or to NaN if that's not |
165 // possible. Number.isInteger will verify the value is not a NaN and that it | 191 // possible. Number.isInteger will verify the value is not a NaN and that it |
166 // does not contain decimals. | 192 // does not contain decimals. |
167 // This heuristic will fail for inputs like '1.0'. | 193 // This heuristic will fail for inputs like '1.0'. |
168 // | 194 // |
169 // Since we still support users entering their passwords through the PIN | 195 // Since we still support users entering their passwords through the PIN |
170 // keyboard, we swap the input box to rtl when we think it is a password | 196 // keyboard, we swap the input box to rtl when we think it is a password |
171 // (just numbers), if the document direction is rtl. | 197 // (just numbers), if the document direction is rtl. |
172 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); | 198 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); |
173 return enableRtl ? 'input-non-pin' : ''; | 199 return enableRtl ? 'input-non-pin' : ''; |
174 }, | 200 }, |
175 | 201 |
176 /** | 202 /** |
177 * Computes if the submit button is visible. | 203 * Computes if the submit button is visible. |
178 * @param {boolean} submitEnabled | 204 * @param {boolean} submitEnabled |
179 * @private | 205 * @private |
180 */ | 206 */ |
181 getSubmitHiddenClass_: function(submitEnabled) { | 207 getSubmitClass_: function(submitEnabled) { |
182 return submitEnabled ? '' : 'submit-button-hidden'; | 208 return submitEnabled ? '' : 'submit-button-hidden'; |
183 } | 209 } |
184 }); | 210 }); |
OLD | NEW |