Merge pull request #3787 from Snuffleupagus/inline-setScale
Inline setScale in parseScale
This commit is contained in:
commit
2726a0be96
@ -330,9 +330,9 @@ var PageView = function pageView(container, id, scale,
|
||||
}
|
||||
|
||||
if (scale && scale !== PDFView.currentScale) {
|
||||
PDFView.parseScale(scale, true, true);
|
||||
PDFView.setScale(scale, true, true);
|
||||
} else if (PDFView.currentScale === UNKNOWN_SCALE) {
|
||||
PDFView.parseScale(DEFAULT_SCALE, true, true);
|
||||
PDFView.setScale(DEFAULT_SCALE, true, true);
|
||||
}
|
||||
|
||||
if (scale === 'page-fit' && !dest[4]) {
|
||||
|
@ -93,7 +93,7 @@ var PresentationMode = {
|
||||
this.active = true;
|
||||
|
||||
PDFView.page = this.args.page;
|
||||
PDFView.parseScale('page-fit', true);
|
||||
PDFView.setScale('page-fit', true);
|
||||
|
||||
window.addEventListener('mousemove', this.mouseMove, false);
|
||||
window.addEventListener('mousedown', this.mouseDown, false);
|
||||
@ -108,7 +108,7 @@ var PresentationMode = {
|
||||
this.active = false;
|
||||
|
||||
var page = PDFView.page;
|
||||
PDFView.parseScale(this.args.previousScale);
|
||||
PDFView.setScale(this.args.previousScale);
|
||||
PDFView.page = page;
|
||||
|
||||
window.removeEventListener('mousemove', this.mouseMove, false);
|
||||
|
@ -194,45 +194,25 @@ var PDFView = {
|
||||
}, true);
|
||||
},
|
||||
|
||||
setScale: function pdfViewSetScale(val, resetAutoSettings, noScroll) {
|
||||
if (val == this.currentScale)
|
||||
return;
|
||||
|
||||
var pages = this.pages;
|
||||
for (var i = 0; i < pages.length; i++)
|
||||
pages[i].update(val);
|
||||
|
||||
if (!noScroll && this.currentScale != val)
|
||||
this.pages[this.page - 1].scrollIntoView();
|
||||
this.currentScale = val;
|
||||
|
||||
var event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('scalechange', false, false, window, 0);
|
||||
event.scale = val;
|
||||
event.resetAutoSettings = resetAutoSettings;
|
||||
window.dispatchEvent(event);
|
||||
},
|
||||
|
||||
parseScale: function pdfViewParseScale(value, resetAutoSettings, noScroll) {
|
||||
if ('custom' == value)
|
||||
return;
|
||||
|
||||
var scale = parseFloat(value);
|
||||
this.currentScaleValue = value;
|
||||
if (scale) {
|
||||
this.setScale(scale, true, noScroll);
|
||||
setScale: function pdfViewSetScale(value, resetAutoSettings, noScroll) {
|
||||
if (value === 'custom') {
|
||||
return;
|
||||
}
|
||||
var pages = this.pages;
|
||||
var currentPage = pages[this.page - 1];
|
||||
var number = parseFloat(value);
|
||||
var scale;
|
||||
|
||||
var container = this.container;
|
||||
var currentPage = this.pages[this.page - 1];
|
||||
if (number) {
|
||||
scale = number;
|
||||
resetAutoSettings = true;
|
||||
} else {
|
||||
if (!currentPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pageWidthScale = (container.clientWidth - SCROLLBAR_PADDING) /
|
||||
var pageWidthScale = (this.container.clientWidth - SCROLLBAR_PADDING) /
|
||||
currentPage.width * currentPage.scale;
|
||||
var pageHeightScale = (container.clientHeight - VERTICAL_PADDING) /
|
||||
var pageHeightScale = (this.container.clientHeight - VERTICAL_PADDING) /
|
||||
currentPage.height * currentPage.scale;
|
||||
switch (value) {
|
||||
case 'page-actual':
|
||||
@ -251,9 +231,30 @@ var PDFView = {
|
||||
scale = Math.min(1.0, pageWidthScale);
|
||||
break;
|
||||
}
|
||||
this.setScale(scale, resetAutoSettings, noScroll);
|
||||
}
|
||||
this.currentScaleValue = value;
|
||||
|
||||
if (scale === this.currentScale) {
|
||||
return;
|
||||
}
|
||||
for (var i = 0, ii = pages.length; i < ii; i++) {
|
||||
pages[i].update(scale);
|
||||
}
|
||||
this.currentScale = scale;
|
||||
|
||||
if (!noScroll) {
|
||||
currentPage.scrollIntoView();
|
||||
}
|
||||
|
||||
var event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('scalechange', false, false, window, 0);
|
||||
event.scale = scale;
|
||||
event.resetAutoSettings = resetAutoSettings;
|
||||
window.dispatchEvent(event);
|
||||
|
||||
if (!number) {
|
||||
selectScaleOption(value);
|
||||
}
|
||||
},
|
||||
|
||||
zoomIn: function pdfViewZoomIn(ticks) {
|
||||
@ -263,7 +264,7 @@ var PDFView = {
|
||||
newScale = Math.ceil(newScale * 10) / 10;
|
||||
newScale = Math.min(MAX_SCALE, newScale);
|
||||
} while (--ticks && newScale < MAX_SCALE);
|
||||
this.parseScale(newScale, true);
|
||||
this.setScale(newScale, true);
|
||||
},
|
||||
|
||||
zoomOut: function pdfViewZoomOut(ticks) {
|
||||
@ -273,7 +274,7 @@ var PDFView = {
|
||||
newScale = Math.floor(newScale * 10) / 10;
|
||||
newScale = Math.max(MIN_SCALE, newScale);
|
||||
} while (--ticks && newScale > MIN_SCALE);
|
||||
this.parseScale(newScale, true);
|
||||
this.setScale(newScale, true);
|
||||
},
|
||||
|
||||
set page(val) {
|
||||
@ -1018,14 +1019,14 @@ var PDFView = {
|
||||
} else if (storedHash) {
|
||||
this.setHash(storedHash);
|
||||
} else if (scale) {
|
||||
this.parseScale(scale, true);
|
||||
this.setScale(scale, true);
|
||||
this.page = 1;
|
||||
}
|
||||
|
||||
if (PDFView.currentScale === UNKNOWN_SCALE) {
|
||||
// Scale was not initialized: invalid bookmark or scale was not specified.
|
||||
// Setting the default one.
|
||||
this.parseScale(DEFAULT_SCALE, true);
|
||||
this.setScale(DEFAULT_SCALE, true);
|
||||
}
|
||||
},
|
||||
|
||||
@ -1326,7 +1327,7 @@ var PDFView = {
|
||||
thumb.update(this.pageRotation);
|
||||
}
|
||||
|
||||
this.parseScale(this.currentScaleValue, true);
|
||||
this.setScale(this.currentScaleValue, true);
|
||||
|
||||
this.renderHighestPriority();
|
||||
|
||||
@ -1654,7 +1655,7 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
||||
|
||||
document.getElementById('scaleSelect').addEventListener('change',
|
||||
function() {
|
||||
PDFView.parseScale(this.value);
|
||||
PDFView.setScale(this.value);
|
||||
});
|
||||
|
||||
document.getElementById('presentationMode').addEventListener('click',
|
||||
@ -1750,7 +1751,7 @@ window.addEventListener('resize', function webViewerResize(evt) {
|
||||
(document.getElementById('pageWidthOption').selected ||
|
||||
document.getElementById('pageFitOption').selected ||
|
||||
document.getElementById('pageAutoOption').selected)) {
|
||||
PDFView.parseScale(document.getElementById('scaleSelect').value);
|
||||
PDFView.setScale(document.getElementById('scaleSelect').value);
|
||||
}
|
||||
updateViewarea();
|
||||
|
||||
@ -1949,7 +1950,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
|
||||
PDFView.parseScale(DEFAULT_SCALE, true);
|
||||
PDFView.setScale(DEFAULT_SCALE, true);
|
||||
});
|
||||
handled = false;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user