Skip to content

Commit

Permalink
Merge pull request #6207 from Snuffleupagus/viewer-remove-setScale
Browse files Browse the repository at this point in the history
Remove `PDFViewerApplication.setScale` and further simplify the `scalechange` event handler (issue 6158)
  • Loading branch information
timvandermeij committed Jul 14, 2015
2 parents 367794f + 0c08113 commit 76d225d
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
},

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 76d225d

Please sign in to comment.