Chromium Code Reviews| 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 // Destination list special value constants. | 26 // Destination list special value constants. |
| 27 const PRINT_TO_PDF = 'Print To PDF'; | 27 const PRINT_TO_PDF = 'Print To PDF'; |
| 28 const MANAGE_PRINTERS = 'Manage Printers'; | 28 const MANAGE_PRINTERS = 'Manage Printers'; |
| 29 | 29 |
| 30 // State of the print preview settings. | 30 // State of the print preview settings. |
| 31 var printSettings = new PrintSettings(); | 31 var printSettings = new PrintSettings(); |
| 32 | 32 |
| 33 // The name of the default or last used printer. | 33 // The name of the default or last used printer. |
| 34 var defaultOrLastUsedPrinterName = ''; | 34 var defaultOrLastUsedPrinterName = ''; |
| 35 | 35 |
| 36 // True when a pending print preview request exists. | |
| 37 var hasPendingPreviewRequest = false; | |
| 38 | |
| 39 // True when a pending print file request exists. | |
| 40 var hasPendingPrintFileRequest = false; | |
| 41 | |
| 42 // True when a compatible plugin exists. | |
| 43 var hasCompatiblePlugin = false; | |
| 44 | |
| 45 // True when initiator tab is closed. | |
| 46 var isInitiatorTabClosed = false; | |
| 47 | |
| 36 /** | 48 /** |
| 37 * Window onload handler, sets up the page and starts print preview by getting | 49 * Window onload handler, sets up the page and starts print preview by getting |
| 38 * the printer list. | 50 * the printer list. |
| 39 */ | 51 */ |
| 40 function onLoad() { | 52 function onLoad() { |
| 41 $('system-dialog-link').addEventListener('click', showSystemDialog); | 53 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 42 $('cancel-button').addEventListener('click', handleCancelButtonClick); | 54 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 43 | 55 |
| 44 if (!checkCompatiblePluginExists()) { | 56 if (!checkCompatiblePluginExists()) { |
| 45 displayErrorMessage(localStrings.getString('noPlugin'), false); | 57 displayErrorMessage(localStrings.getString('noPlugin'), false); |
| 46 $('mainview').parentElement.removeChild($('dummy-viewer')); | 58 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 47 return; | 59 return; |
| 48 } | 60 } |
| 61 hasCompatiblePlugin = true; | |
| 49 $('mainview').parentElement.removeChild($('dummy-viewer')); | 62 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 50 | 63 |
| 51 $('printer-list').disabled = true; | 64 $('printer-list').disabled = true; |
| 52 $('print-button').disabled = true; | 65 $('print-button').onclick = printFile; |
| 66 | |
| 67 setDefaultHandlersForPagesAndCopiesControls(); | |
| 53 showLoadingAnimation(); | 68 showLoadingAnimation(); |
| 54 chrome.send('getDefaultPrinter'); | 69 chrome.send('getDefaultPrinter'); |
| 55 } | 70 } |
| 56 | 71 |
| 57 /** | 72 /** |
| 73 * Handles the individual pages input event. | |
| 74 */ | |
| 75 function handleIndividualPagesInputEvent() { | |
| 76 $('print-pages').checked = true; | |
| 77 resetPageRangeFieldTimer(); | |
| 78 } | |
| 79 | |
| 80 /** | |
| 81 * Validates the individual pages text format. | |
| 82 */ | |
| 83 function validateIndividualPagesText() { | |
|
dpapad
2011/06/09 18:58:41
There are validateIndividualPagesText() and valida
kmadhusu
2011/06/09 20:15:08
Done.
| |
| 84 $('print-pages').checked = true; | |
| 85 validatePageRangesField(); | |
| 86 updatePrintButtonState(); | |
| 87 } | |
| 88 | |
| 89 /** | |
| 90 * Sets the default event handlers for pages and copies controls. | |
| 91 */ | |
| 92 function setDefaultHandlersForPagesAndCopiesControls() { | |
| 93 var allPages = $('all-pages'); | |
| 94 var printPages = $('print-pages'); | |
| 95 var individualPages = $('individual-pages'); | |
| 96 | |
| 97 allPages.onclick = null; | |
| 98 printPages.onclick = null; | |
| 99 individualPages.oninput = null; | |
| 100 individualPages.onfocus = null; | |
| 101 individualPages.onblur = null; | |
| 102 | |
| 103 if (hasCompatiblePlugin && !isInitiatorTabClosed) { | |
| 104 allPages.onclick = updatePrintButtonState; | |
| 105 printPages.onclick = handleIndividualPagesCheckbox; | |
| 106 individualPages.onblur = validateIndividualPagesText; | |
| 107 } | |
| 108 | |
| 109 $('copies').oninput = copiesFieldChanged; | |
| 110 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; | |
| 111 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); }; | |
| 112 } | |
| 113 | |
| 114 /** | |
| 58 * Adds event listeners to the settings controls. | 115 * Adds event listeners to the settings controls. |
| 59 */ | 116 */ |
| 60 function addEventListeners() { | 117 function addEventListeners() { |
| 61 $('print-button').onclick = printFile; | |
| 62 | |
| 63 // Controls that require preview rendering. | 118 // Controls that require preview rendering. |
| 64 $('all-pages').onclick = onPageSelectionMayHaveChanged; | 119 $('all-pages').onclick = onPageSelectionMayHaveChanged; |
| 65 $('print-pages').onclick = handleIndividualPagesCheckbox; | 120 $('print-pages').onclick = handleIndividualPagesCheckbox; |
| 66 var individualPages = $('individual-pages'); | 121 var individualPages = $('individual-pages'); |
| 67 individualPages.onblur = function() { | 122 individualPages.onblur = function() { |
| 68 clearTimeout(timerId); | 123 clearTimeout(timerId); |
| 69 onPageSelectionMayHaveChanged(); | 124 onPageSelectionMayHaveChanged(); |
| 70 }; | 125 }; |
| 71 individualPages.onfocus = addTimerToPageRangeField; | 126 individualPages.onfocus = addTimerToPageRangeField; |
| 72 individualPages.oninput = resetPageRangeFieldTimer; | 127 individualPages.oninput = handleIndividualPagesInputEvent; |
| 73 $('landscape').onclick = onLayoutModeToggle; | 128 $('landscape').onclick = onLayoutModeToggle; |
| 74 $('portrait').onclick = onLayoutModeToggle; | 129 $('portrait').onclick = onLayoutModeToggle; |
| 75 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 130 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 76 | 131 |
| 77 // Controls that dont require preview rendering. | 132 // Controls that dont require preview rendering. |
| 78 $('copies').oninput = function() { | 133 $('copies').oninput = function() { |
| 79 copiesFieldChanged(); | 134 copiesFieldChanged(); |
| 80 updatePrintButtonState(); | 135 updatePrintButtonState(); |
| 81 updatePrintSummary(); | 136 updatePrintSummary(); |
| 82 }; | 137 }; |
| 83 $('two-sided').onclick = handleTwoSidedClick; | 138 $('two-sided').onclick = handleTwoSidedClick; |
| 84 $('color').onclick = function() { setColor(true); }; | 139 $('color').onclick = function() { setColor(true); }; |
| 85 $('bw').onclick = function() { setColor(false); }; | 140 $('bw').onclick = function() { setColor(false); }; |
| 86 $('increment').onclick = function() { | 141 $('increment').onclick = function() { |
| 87 onCopiesButtonsClicked(1); | 142 onCopiesButtonsClicked(1); |
| 88 updatePrintButtonState(); | 143 updatePrintButtonState(); |
| 89 updatePrintSummary(); | 144 updatePrintSummary(); |
| 90 }; | 145 }; |
| 91 $('decrement').onclick = function() { | 146 $('decrement').onclick = function() { |
| 92 onCopiesButtonsClicked(-1); | 147 onCopiesButtonsClicked(-1); |
| 93 updatePrintButtonState(); | 148 updatePrintButtonState(); |
| 94 updatePrintSummary(); | 149 updatePrintSummary(); |
| 95 }; | 150 }; |
| 96 } | 151 } |
| 97 | 152 |
| 98 /** | 153 /** |
| 99 * Removes event listeners from the settings controls. | 154 * Removes event listeners from the settings controls. |
| 100 */ | 155 */ |
| 101 function removeEventListeners() { | 156 function removeEventListeners() { |
| 102 // Controls that require preview rendering. | |
| 103 $('print-button').disabled = true; | |
| 104 $('all-pages').onclick = null; | |
| 105 $('print-pages').onclick = null; | |
| 106 var individualPages = $('individual-pages'); | |
| 107 individualPages.onblur = null; | |
| 108 individualPages.onfocus = null; | |
| 109 individualPages.oninput = null; | |
| 110 clearTimeout(timerId); | 157 clearTimeout(timerId); |
| 158 setDefaultHandlersForPagesAndCopiesControls(); | |
| 159 | |
| 160 // Controls that require preview rendering | |
| 111 $('landscape').onclick = null; | 161 $('landscape').onclick = null; |
| 112 $('portrait').onclick = null; | 162 $('portrait').onclick = null; |
| 113 $('printer-list').onchange = null; | 163 $('printer-list').onchange = null; |
| 114 | 164 |
| 115 // Controls that dont require preview rendering. | 165 // Controls that dont require preview rendering. |
| 116 $('copies').oninput = copiesFieldChanged; | |
| 117 $('two-sided').onclick = null; | 166 $('two-sided').onclick = null; |
| 118 $('color').onclick = null; | 167 $('color').onclick = null; |
| 119 $('bw').onclick = null; | 168 $('bw').onclick = null; |
| 120 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; | |
| 121 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); }; | |
| 122 } | 169 } |
| 123 | 170 |
| 124 /** | 171 /** |
| 125 * Asks the browser to close the preview tab. | 172 * Asks the browser to close the preview tab. |
| 126 */ | 173 */ |
| 127 function handleCancelButtonClick() { | 174 function handleCancelButtonClick() { |
| 128 chrome.send('closePrintPreviewTab'); | 175 chrome.send('closePrintPreviewTab'); |
| 129 } | 176 } |
| 130 | 177 |
| 131 /** | 178 /** |
| 132 * Asks the browser to show the native print dialog for printing. | 179 * Asks the browser to show the native print dialog for printing. |
| 133 */ | 180 */ |
| 134 function showSystemDialog() { | 181 function showSystemDialog() { |
| 135 chrome.send('showSystemDialog'); | 182 chrome.send('showSystemDialog'); |
| 136 } | 183 } |
| 137 | 184 |
| 138 /** | 185 /** |
| 139 * Disables the controls which need the initiator tab to generate preview | 186 * Disables the controls which need the initiator tab to generate preview |
| 140 * data. This function is called when the initiator tab is closed. | 187 * data. This function is called when the initiator tab is closed. |
| 141 * @param {string} initiatorTabURL The URL of the initiator tab. | 188 * @param {string} initiatorTabURL The URL of the initiator tab. |
| 142 */ | 189 */ |
| 143 function onInitiatorTabClosed(initiatorTabURL) { | 190 function onInitiatorTabClosed(initiatorTabURL) { |
| 191 isInitiatorTabClosed = true; | |
| 144 $('reopen-page').addEventListener('click', function() { | 192 $('reopen-page').addEventListener('click', function() { |
| 145 window.location = initiatorTabURL; | 193 window.location = initiatorTabURL; |
| 146 }); | 194 }); |
| 147 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); | 195 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); |
| 148 } | 196 } |
| 149 | 197 |
| 150 /** | 198 /** |
| 151 * Gets the selected printer capabilities and updates the controls accordingly. | 199 * Gets the selected printer capabilities and updates the controls accordingly. |
| 152 */ | 200 */ |
| 153 function updateControlsWithSelectedPrinterCapabilities() { | 201 function updateControlsWithSelectedPrinterCapabilities() { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 var deviceName = ''; | 370 var deviceName = ''; |
| 323 if (selectedPrinter >= 0) | 371 if (selectedPrinter >= 0) |
| 324 deviceName = printerList.options[selectedPrinter].value; | 372 deviceName = printerList.options[selectedPrinter].value; |
| 325 return deviceName; | 373 return deviceName; |
| 326 } | 374 } |
| 327 | 375 |
| 328 /** | 376 /** |
| 329 * Asks the browser to print the preview PDF based on current print settings. | 377 * Asks the browser to print the preview PDF based on current print settings. |
| 330 */ | 378 */ |
| 331 function printFile() { | 379 function printFile() { |
| 380 hasPendingPrintFileRequest = hasPendingPreviewRequest ? true : false; | |
| 381 | |
| 382 if (hasPendingPrintFileRequest) { | |
| 383 if (getSelectedPrinterName() != PRINT_TO_PDF) | |
| 384 chrome.send('hidePreview'); | |
| 385 return; | |
| 386 } | |
| 387 | |
| 332 if (getSelectedPrinterName() != PRINT_TO_PDF) { | 388 if (getSelectedPrinterName() != PRINT_TO_PDF) { |
| 333 $('print-button').classList.add('loading'); | 389 $('print-button').classList.add('loading'); |
| 334 $('cancel-button').classList.add('loading'); | 390 $('cancel-button').classList.add('loading'); |
| 335 $('print-summary').innerHTML = localStrings.getString('printing'); | 391 $('print-summary').innerHTML = localStrings.getString('printing'); |
| 336 removeEventListeners(); | 392 removeEventListeners(); |
| 337 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, | 393 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, |
| 338 1000); | 394 1000); |
| 339 } else | 395 } else { |
| 340 chrome.send('print', [getSettingsJSON()]); | 396 chrome.send('print', [getSettingsJSON()]); |
| 397 } | |
| 341 } | 398 } |
| 342 | 399 |
| 343 /** | 400 /** |
| 344 * Asks the browser to generate a preview PDF based on current print settings. | 401 * Asks the browser to generate a preview PDF based on current print settings. |
| 345 */ | 402 */ |
| 346 function requestPrintPreview() { | 403 function requestPrintPreview() { |
| 404 hasPendingPreviewRequest = true; | |
| 347 removeEventListeners(); | 405 removeEventListeners(); |
| 348 printSettings.save(); | 406 printSettings.save(); |
| 349 showLoadingAnimation(); | 407 showLoadingAnimation(); |
| 350 chrome.send('getPreview', [getSettingsJSON()]); | 408 chrome.send('getPreview', [getSettingsJSON()]); |
| 351 } | 409 } |
| 352 | 410 |
| 353 /** | 411 /** |
| 354 * Set the default printer. If there is one, generate a print preview. | 412 * Set the default printer. If there is one, generate a print preview. |
| 355 * @param {string} printer Name of the default printer. Empty if none. | 413 * @param {string} printer Name of the default printer. Empty if none. |
| 356 */ | 414 */ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 var pdfViewer = $('pdf-viewer'); | 488 var pdfViewer = $('pdf-viewer'); |
| 431 if (!pdfViewer) { | 489 if (!pdfViewer) { |
| 432 return; | 490 return; |
| 433 } | 491 } |
| 434 pdfViewer.grayscale(!color); | 492 pdfViewer.grayscale(!color); |
| 435 } | 493 } |
| 436 | 494 |
| 437 /** | 495 /** |
| 438 * Display an error message in the center of the preview area. | 496 * Display an error message in the center of the preview area. |
| 439 * @param {string} errorMessage The error message to be displayed. | 497 * @param {string} errorMessage The error message to be displayed. |
| 440 * @param {boolean} showButton Indivates whether the "Reopen the page" button | 498 * @param {boolean} showButton Indicates whether the "Reopen the page" button |
| 441 * should be displayed. | 499 * should be displayed. |
| 442 */ | 500 */ |
| 443 function displayErrorMessage(errorMessage, showButton) { | 501 function displayErrorMessage(errorMessage, showButton) { |
| 502 $('print-button').disabled = true; | |
| 444 $('overlay-layer').classList.remove('invisible'); | 503 $('overlay-layer').classList.remove('invisible'); |
| 445 $('dancing-dots-text').classList.add('hidden'); | 504 $('dancing-dots-text').classList.add('hidden'); |
| 446 $('error-text').innerHTML = errorMessage; | 505 $('error-text').innerHTML = errorMessage; |
| 447 $('error-text').classList.remove('hidden'); | 506 $('error-text').classList.remove('hidden'); |
| 448 if (showButton) | 507 if (showButton) |
| 449 $('reopen-page').classList.remove('hidden'); | 508 $('reopen-page').classList.remove('hidden'); |
| 450 else | 509 else |
| 451 $('reopen-page').classList.add('hidden'); | 510 $('reopen-page').classList.add('hidden'); |
| 452 | 511 |
| 453 removeEventListeners(); | 512 removeEventListeners(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 * @param {string} jobTitle The print job title. | 548 * @param {string} jobTitle The print job title. |
| 490 * @param {boolean} modifiable If the preview is modifiable. | 549 * @param {boolean} modifiable If the preview is modifiable. |
| 491 * @param {string} previewUid Preview unique identifier. | 550 * @param {string} previewUid Preview unique identifier. |
| 492 */ | 551 */ |
| 493 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { | 552 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUid) { |
| 494 var tempPrintSettings = new PrintSettings(); | 553 var tempPrintSettings = new PrintSettings(); |
| 495 tempPrintSettings.save(); | 554 tempPrintSettings.save(); |
| 496 | 555 |
| 497 previewModifiable = modifiable; | 556 previewModifiable = modifiable; |
| 498 | 557 |
| 558 hasPendingPreviewRequest = false; | |
| 559 | |
| 499 if (totalPageCount == -1) | 560 if (totalPageCount == -1) |
| 500 totalPageCount = pageCount; | 561 totalPageCount = pageCount; |
| 501 | 562 |
| 502 if (previouslySelectedPages.length == 0) | 563 if (previouslySelectedPages.length == 0) |
| 503 for (var i = 0; i < totalPageCount; i++) | 564 for (var i = 0; i < totalPageCount; i++) |
| 504 previouslySelectedPages.push(i+1); | 565 previouslySelectedPages.push(i+1); |
| 505 | 566 |
| 506 if (printSettings.deviceName != tempPrintSettings.deviceName) { | 567 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
| 507 updateControlsWithSelectedPrinterCapabilities(); | 568 updateControlsWithSelectedPrinterCapabilities(); |
| 508 return; | 569 return; |
| 509 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | 570 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { |
| 510 setDefaultValuesAndRegeneratePreview(); | 571 setDefaultValuesAndRegeneratePreview(); |
| 511 return; | 572 return; |
| 512 } else if (isSelectedPagesValid()) { | 573 } else if (isSelectedPagesValid()) { |
| 513 var currentlySelectedPages = getSelectedPagesSet(); | 574 var currentlySelectedPages = getSelectedPagesSet(); |
| 514 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { | 575 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { |
| 515 previouslySelectedPages = currentlySelectedPages; | 576 previouslySelectedPages = currentlySelectedPages; |
| 516 requestPrintPreview(); | 577 requestPrintPreview(); |
| 517 return; | 578 return; |
| 518 } | 579 } |
| 519 } | 580 } |
| 520 | 581 |
| 521 if (!isSelectedPagesValid()) | 582 if (!isSelectedPagesValid()) |
| 522 pageRangesFieldChanged(); | 583 pageRangesFieldChanged(); |
| 523 | 584 |
| 524 // Update the current tab title. | 585 // Update the current tab title. |
| 525 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 586 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 526 | 587 |
| 527 createPDFPlugin(previewUid); | 588 createPDFPlugin(previewUid); |
| 589 | |
| 528 updatePrintSummary(); | 590 updatePrintSummary(); |
| 529 updatePrintButtonState(); | 591 updatePrintButtonState(); |
| 530 addEventListeners(); | 592 addEventListeners(); |
| 593 | |
| 594 if (hasPendingPrintFileRequest) | |
| 595 printFile(); | |
| 531 } | 596 } |
| 532 | 597 |
| 533 /** | 598 /** |
| 534 * Create the PDF plugin or reload the existing one. | 599 * Create the PDF plugin or reload the existing one. |
| 535 * @param {string} previewUid Preview unique identifier. | 600 * @param {string} previewUid Preview unique identifier. |
| 536 */ | 601 */ |
| 537 function createPDFPlugin(previewUid) { | 602 function createPDFPlugin(previewUid) { |
| 538 // Enable the print button. | 603 // Enable the print button. |
| 539 if (!$('printer-list').disabled) { | 604 if (!$('printer-list').disabled) { |
| 540 $('print-button').disabled = false; | 605 $('print-button').disabled = false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 /** | 664 /** |
| 600 * Listener function that executes whenever a change occurs in the 'copies' | 665 * Listener function that executes whenever a change occurs in the 'copies' |
| 601 * field. | 666 * field. |
| 602 */ | 667 */ |
| 603 function copiesFieldChanged() { | 668 function copiesFieldChanged() { |
| 604 updateCopiesButtonsState(); | 669 updateCopiesButtonsState(); |
| 605 $('collate-option').hidden = getCopies() <= 1; | 670 $('collate-option').hidden = getCopies() <= 1; |
| 606 } | 671 } |
| 607 | 672 |
| 608 /** | 673 /** |
| 609 * Executes whenever a blur event occurs on the 'individual-pages' | 674 * Validates the page ranges text and updates the hint accordingly. |
| 610 * field or when the timer expires. It takes care of | |
| 611 * 1) showing/hiding warnings/suggestions | |
| 612 * 2) updating print button/summary | |
| 613 */ | 675 */ |
| 614 function pageRangesFieldChanged() { | 676 function validatePageRangesField() { |
| 615 var currentlySelectedPages = getSelectedPagesSet(); | |
| 616 var individualPagesField = $('individual-pages'); | 677 var individualPagesField = $('individual-pages'); |
| 617 var individualPagesHint = $('individual-pages-hint'); | 678 var individualPagesHint = $('individual-pages-hint'); |
| 618 | 679 |
| 619 if (isSelectedPagesValid()) { | 680 if (isSelectedPagesValid()) { |
| 620 individualPagesField.classList.remove('invalid'); | 681 individualPagesField.classList.remove('invalid'); |
| 621 fadeOutElement(individualPagesHint); | 682 fadeOutElement(individualPagesHint); |
| 622 } else { | 683 } else { |
| 623 individualPagesField.classList.add('invalid'); | 684 individualPagesField.classList.add('invalid'); |
| 624 individualPagesHint.classList.remove('suggestion'); | 685 individualPagesHint.classList.remove('suggestion'); |
| 625 individualPagesHint.innerHTML = | 686 individualPagesHint.innerHTML = |
| 626 localStrings.getStringF('pageRangeInstruction', | 687 localStrings.getStringF('pageRangeInstruction', |
| 627 localStrings.getString( | 688 localStrings.getString( |
| 628 'examplePageRangeText')); | 689 'examplePageRangeText')); |
| 629 fadeInElement(individualPagesHint); | 690 fadeInElement(individualPagesHint); |
| 630 } | 691 } |
| 692 } | |
| 693 | |
| 694 /** | |
| 695 * Executes whenever a blur event occurs on the 'individual-pages' | |
| 696 * field or when the timer expires. It takes care of | |
| 697 * 1) showing/hiding warnings/suggestions | |
| 698 * 2) updating print button/summary | |
| 699 */ | |
| 700 function pageRangesFieldChanged() { | |
| 701 validatePageRangesField(); | |
| 631 | 702 |
| 632 resetPageRangeFieldTimer(); | 703 resetPageRangeFieldTimer(); |
| 633 updatePrintButtonState(); | 704 updatePrintButtonState(); |
| 634 updatePrintSummary(); | 705 updatePrintSummary(); |
| 635 } | 706 } |
| 636 | 707 |
| 637 /** | 708 /** |
| 638 * Updates the state of the increment/decrement buttons based on the current | 709 * Updates the state of the increment/decrement buttons based on the current |
| 639 * 'copies' value. | 710 * 'copies' value. |
| 640 */ | 711 */ |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 var successfullyParsed = 0; | 870 var successfullyParsed = 0; |
| 800 var parts = pageText.split(/,/); | 871 var parts = pageText.split(/,/); |
| 801 | 872 |
| 802 for (var i = 0; i < parts.length; ++i) { | 873 for (var i = 0; i < parts.length; ++i) { |
| 803 var part = parts[i].replace(/\s*/g, ''); | 874 var part = parts[i].replace(/\s*/g, ''); |
| 804 if (part.length == 0) | 875 if (part.length == 0) |
| 805 continue; | 876 continue; |
| 806 | 877 |
| 807 var match = part.match(/^([0-9]+)-([0-9]*)$/); | 878 var match = part.match(/^([0-9]+)-([0-9]*)$/); |
| 808 if (match && isValidNonZeroPositiveInteger(match[1])) { | 879 if (match && isValidNonZeroPositiveInteger(match[1])) { |
| 880 if (!match[2] && totalPageCount == -1) { | |
| 881 successfullyParsed += 1; | |
| 882 continue; | |
| 883 } | |
| 809 var from = parseInt(match[1], 10); | 884 var from = parseInt(match[1], 10); |
| 810 var to = match[2] ? parseInt(match[2], 10) : totalPageCount; | 885 var to = match[2] ? parseInt(match[2], 10) : totalPageCount; |
| 811 | 886 |
| 812 if (!to || from > to) | 887 if (!to || from > to) |
| 813 return false; | 888 return false; |
| 814 } else if (!isValidNonZeroPositiveInteger(part) || | 889 } else if (!isValidNonZeroPositiveInteger(part) || (totalPageCount != -1 && |
| 815 !(parseInt(part, 10) <= totalPageCount)) { | 890 !(parseInt(part, 10) <= totalPageCount))) { |
| 816 return false; | 891 return false; |
| 817 } | 892 } |
| 818 successfullyParsed += 1; | 893 successfullyParsed += 1; |
| 819 } | 894 } |
| 820 return successfullyParsed > 0 | 895 return successfullyParsed > 0 |
| 821 } | 896 } |
| 822 | 897 |
| 823 /** | 898 /** |
| 824 * Returns true if |value| is a valid non zero positive integer. | 899 * Returns true if |value| is a valid non zero positive integer. |
| 825 * @param {string} value The string to be tested. | 900 * @param {string} value The string to be tested. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 this.isLandscape = ''; | 1030 this.isLandscape = ''; |
| 956 } | 1031 } |
| 957 | 1032 |
| 958 /** | 1033 /** |
| 959 * Takes a snapshot of the print settings. | 1034 * Takes a snapshot of the print settings. |
| 960 */ | 1035 */ |
| 961 PrintSettings.prototype.save = function() { | 1036 PrintSettings.prototype.save = function() { |
| 962 this.deviceName = getSelectedPrinterName(); | 1037 this.deviceName = getSelectedPrinterName(); |
| 963 this.isLandscape = isLandscape(); | 1038 this.isLandscape = isLandscape(); |
| 964 } | 1039 } |
| OLD | NEW |