OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Component that renders the copies settings UI. | 9 * Component that renders the copies settings UI. |
10 * @param {!print_preview.ticket_items.Copies} copiesTicketItem Used to read | 10 * @param {!print_preview.ticket_items.Copies} copiesTicketItem Used to read |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 this.getChildElement('button.decrement').disabled = true; | 68 this.getChildElement('button.decrement').disabled = true; |
69 } | 69 } |
70 }, | 70 }, |
71 | 71 |
72 /** @override */ | 72 /** @override */ |
73 enterDocument: function() { | 73 enterDocument: function() { |
74 print_preview.Component.prototype.enterDocument.call(this); | 74 print_preview.Component.prototype.enterDocument.call(this); |
75 fadeOutOption(this.getElement(), true); | 75 fadeOutOption(this.getElement(), true); |
76 this.tracker.add( | 76 this.tracker.add( |
77 this.getChildElement('input.copies'), | 77 this.getChildElement('input.copies'), |
| 78 'keydown', |
| 79 this.onTextfieldKeyDown_.bind(this)); |
| 80 this.tracker.add( |
| 81 this.getChildElement('input.copies'), |
78 'input', | 82 'input', |
79 this.onTextfieldInput_.bind(this)); | 83 this.onTextfieldInput_.bind(this)); |
80 this.tracker.add( | 84 this.tracker.add( |
81 this.getChildElement('input.copies'), | 85 this.getChildElement('input.copies'), |
82 'blur', | 86 'blur', |
83 this.onTextfieldBlur_.bind(this)); | 87 this.onTextfieldBlur_.bind(this)); |
84 this.tracker.add( | 88 this.tracker.add( |
85 this.getChildElement('button.increment'), | 89 this.getChildElement('button.increment'), |
86 'click', | 90 'click', |
87 this.onButtonClicked_.bind(this, 1)); | 91 this.onButtonClicked_.bind(this, 1)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 var newValue = | 165 var newValue = |
162 parseInt(this.getChildElement('input.copies').value) + delta; | 166 parseInt(this.getChildElement('input.copies').value) + delta; |
163 this.copiesTicketItem_.updateValue(newValue + ''); | 167 this.copiesTicketItem_.updateValue(newValue + ''); |
164 }, | 168 }, |
165 | 169 |
166 /** | 170 /** |
167 * Called after a timeout after user input into the textfield. | 171 * Called after a timeout after user input into the textfield. |
168 * @private | 172 * @private |
169 */ | 173 */ |
170 onTextfieldTimeout_: function() { | 174 onTextfieldTimeout_: function() { |
| 175 this.textfieldTimeout_ = null; |
171 var copiesVal = this.getChildElement('input.copies').value; | 176 var copiesVal = this.getChildElement('input.copies').value; |
172 if (copiesVal != '') { | 177 if (copiesVal != '') { |
173 this.copiesTicketItem_.updateValue(copiesVal); | 178 this.copiesTicketItem_.updateValue(copiesVal); |
174 } | 179 } |
175 }, | 180 }, |
176 | 181 |
177 /** | 182 /** |
| 183 * Called when a key is pressed on the custom input. |
| 184 * @param {Event} event Contains the key that was pressed. |
| 185 * @private |
| 186 */ |
| 187 onTextfieldKeyDown_: function(event) { |
| 188 if (event.keyCode == 13 /*enter*/) { |
| 189 if (this.textfieldTimeout_) { |
| 190 clearTimeout(this.textfieldTimeout_); |
| 191 } |
| 192 this.onTextfieldTimeout_(); |
| 193 } |
| 194 }, |
| 195 |
| 196 /** |
178 * Called when a input event occurs on the textfield. Starts an input | 197 * Called when a input event occurs on the textfield. Starts an input |
179 * timeout. | 198 * timeout. |
180 * @private | 199 * @private |
181 */ | 200 */ |
182 onTextfieldInput_: function() { | 201 onTextfieldInput_: function() { |
183 if (this.textfieldTimeout_) { | 202 if (this.textfieldTimeout_) { |
184 clearTimeout(this.textfieldTimeout_); | 203 clearTimeout(this.textfieldTimeout_); |
185 } | 204 } |
186 this.textfieldTimeout_ = setTimeout( | 205 this.textfieldTimeout_ = setTimeout( |
187 this.onTextfieldTimeout_.bind(this), CopiesSettings.TEXTFIELD_DELAY_); | 206 this.onTextfieldTimeout_.bind(this), CopiesSettings.TEXTFIELD_DELAY_); |
(...skipping 18 matching lines...) Expand all Loading... |
206 this.collateTicketItem_.updateValue( | 225 this.collateTicketItem_.updateValue( |
207 this.getChildElement('input.collate').checked); | 226 this.getChildElement('input.collate').checked); |
208 } | 227 } |
209 }; | 228 }; |
210 | 229 |
211 // Export | 230 // Export |
212 return { | 231 return { |
213 CopiesSettings: CopiesSettings | 232 CopiesSettings: CopiesSettings |
214 }; | 233 }; |
215 }); | 234 }); |
OLD | NEW |