From 0c08113e393d534703aee9d88c583c0996288130 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 11 Jul 2015 11:47:45 +0200 Subject: [PATCH] Remove `PDFViewerApplication.setScale` and further simplify the `scalechange` event handler (issue 6158) This finally fixes 6158. --- web/viewer.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 5f5e0b14e..758281f7f 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -298,7 +298,7 @@ var PDFViewerApplication = { newScale = Math.ceil(newScale * 10) / 10; newScale = Math.min(MAX_SCALE, newScale); } while (--ticks > 0 && newScale < MAX_SCALE); - this.setScale(newScale, true); + this.pdfViewer.currentScaleValue = newScale; }, zoomOut: function pdfViewZoomOut(ticks) { @@ -308,7 +308,7 @@ var PDFViewerApplication = { newScale = Math.floor(newScale * 10) / 10; newScale = Math.max(MIN_SCALE, newScale); } while (--ticks > 0 && newScale > MIN_SCALE); - this.setScale(newScale, true); + this.pdfViewer.currentScaleValue = newScale; }, get pagesCount() { @@ -969,14 +969,14 @@ var PDFViewerApplication = { } else if (storedHash) { this.pdfLinkService.setHash(storedHash); } else if (scale) { - this.setScale(scale, true); + this.pdfViewer.currentScaleValue = scale; this.page = 1; } if (!this.pdfViewer.currentScaleValue) { // Scale was not initialized: invalid bookmark or scale was not specified. // Setting the default one. - this.setScale(DEFAULT_SCALE_VALUE, true); + this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; } }, @@ -1172,10 +1172,6 @@ var PDFViewerApplication = { this.forceRendering(); }, - setScale: function (value, resetAutoSettings) { - this.pdfViewer.currentScaleValue = value; - }, - rotatePages: function pdfViewRotatePages(delta) { var pageNumber = this.page; this.pageRotation = (this.pageRotation + 360 + delta) % 360; @@ -1443,10 +1439,9 @@ function webViewerInitialized() { } }); - document.getElementById('scaleSelect').addEventListener('change', - function() { - PDFViewerApplication.setScale(this.value, false); - }); + document.getElementById('scaleSelect').addEventListener('change', function() { + PDFViewerApplication.pdfViewer.currentScaleValue = this.value; + }); document.getElementById('presentationMode').addEventListener('click', SecondaryToolbar.presentationModeClick.bind(SecondaryToolbar)); @@ -1748,13 +1743,9 @@ window.addEventListener('scalechange', function scalechange(evt) { document.getElementById('zoomOut').disabled = (evt.scale === MIN_SCALE); document.getElementById('zoomIn').disabled = (evt.scale === MAX_SCALE); - if (evt.presetValue) { - selectScaleOption(evt.presetValue); - updateViewarea(); - return; - } - - var predefinedValueFound = selectScaleOption('' + evt.scale); + // Update the 'scaleSelect' DOM element. + var predefinedValueFound = selectScaleOption(evt.presetValue || + '' + evt.scale); if (!predefinedValueFound) { var customScaleOption = document.getElementById('customScaleOption'); var customScale = Math.round(evt.scale * 10000) / 100; @@ -1889,7 +1880,7 @@ window.addEventListener('keydown', function keydown(evt) { // keeping it unhandled (to restore page zoom to 100%) setTimeout(function () { // ... and resetting the scale after browser adjusts its scale - PDFViewerApplication.setScale(DEFAULT_SCALE_VALUE, true); + pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; }); handled = false; }