OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * Creates a PageSettings object. This object encapsulates all settings and | 9 * Creates a PageSettings object. This object encapsulates all settings and |
10 * logic related to page selection. | 10 * logic related to page selection. |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 */ | 315 */ |
316 onSelectedPagesRadioButtonChecked_: function() { | 316 onSelectedPagesRadioButtonChecked_: function() { |
317 this.selectedPagesTextfield_.focus(); | 317 this.selectedPagesTextfield_.focus(); |
318 }, | 318 }, |
319 | 319 |
320 /** | 320 /** |
321 * Listener executing when an input event occurs in | 321 * Listener executing when an input event occurs in |
322 * |this.selectedPagesTextfield|. Ensures that | 322 * |this.selectedPagesTextfield|. Ensures that |
323 * |this.selectedPagesTextfield| is non-empty before checking | 323 * |this.selectedPagesTextfield| is non-empty before checking |
324 * |this.selectedPagesRadioButton|. | 324 * |this.selectedPagesRadioButton|. |
| 325 * @private |
325 */ | 326 */ |
326 onSelectedPagesTextfieldInput: function() { | 327 onSelectedPagesTextfieldInput_: function() { |
327 if (this.selectedPagesText.length) | 328 if (this.selectedPagesText.length) |
328 this.selectedPagesRadioButton.checked = true; | 329 this.selectedPagesRadioButton.checked = true; |
329 if (!hasPendingPreviewRequest) { | 330 this.resetSelectedPagesTextfieldTimer_(); |
330 this.resetSelectedPagesTextfieldTimer_(); | |
331 } | |
332 }, | 331 }, |
333 | 332 |
334 /** | 333 /** |
335 * Adding listeners to all pages related controls. The listeners take care | 334 * Adding listeners to all pages related controls. The listeners take care |
336 * of altering their behavior depending on |hasPendingPreviewRequest|. | 335 * of altering their behavior depending on |hasPendingPreviewRequest|. |
337 */ | 336 */ |
338 addEventListeners: function() { | 337 addEventListeners: function() { |
339 this.allPagesRadioButton.onclick = function() { | 338 this.allPagesRadioButton.onclick = |
340 if (hasPendingPreviewRequest) | 339 this.onSelectedPagesMayHaveChanged_.bind(this); |
341 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 340 this.selectedPagesRadioButton.onclick = |
342 else | 341 this.onSelectedPagesMayHaveChanged_.bind(this); |
343 this.onSelectedPagesMayHaveChanged_(); | |
344 }.bind(this); | |
345 | |
346 this.selectedPagesRadioButton.onclick = function() { | |
347 if (!hasPendingPreviewRequest) | |
348 this.onSelectedPagesMayHaveChanged_(); | |
349 }.bind(this); | |
350 | |
351 this.selectedPagesTextfield.oninput = | 342 this.selectedPagesTextfield.oninput = |
352 this.onSelectedPagesTextfieldInput.bind(this); | 343 this.onSelectedPagesTextfieldInput_.bind(this); |
353 | 344 this.selectedPagesTextfield.onfocus = |
354 this.selectedPagesTextfield.onfocus = function() { | 345 this.addTimerToSelectedPagesTextfield_.bind(this); |
355 if (!hasPendingPreviewRequest) | |
356 this.addTimerToSelectedPagesTextfield_(); | |
357 }.bind(this); | |
358 | 346 |
359 // Handler for the blur event on |this.selectedPagesTextfield|. Un-checks | 347 // Handler for the blur event on |this.selectedPagesTextfield|. Un-checks |
360 // |this.selectedPagesRadioButton| if the input field is empty. | 348 // |this.selectedPagesRadioButton| if the input field is empty. |
361 this.selectedPagesTextfield.onblur = function() { | 349 this.selectedPagesTextfield.onblur = function() { |
362 if (!this.selectedPagesText.length) | 350 if (!this.selectedPagesText.length) |
363 this.allPagesRadioButton_.checked = true; | 351 this.allPagesRadioButton_.checked = true; |
364 | 352 |
365 if (hasPendingPreviewRequest) { | 353 clearTimeout(this.timerId_); |
366 this.validateSelectedPages_(); | 354 this.onSelectedPagesMayHaveChanged_(); |
367 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | |
368 } else { | |
369 clearTimeout(this.timerId_); | |
370 this.onSelectedPagesMayHaveChanged_(); | |
371 } | |
372 }.bind(this); | 355 }.bind(this); |
373 } | 356 } |
374 }; | 357 }; |
375 | 358 |
376 return { | 359 return { |
377 PageSettings: PageSettings, | 360 PageSettings: PageSettings, |
378 }; | 361 }; |
379 }); | 362 }); |
OLD | NEW |