Keep current scroll position when zooming the document
This commit is contained in:
parent
f7d2a09bf8
commit
edf3163fa6
@ -251,28 +251,45 @@ var PDFView = {
|
|||||||
}, true);
|
}, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
setScale: function pdfViewSetScale(val, resetAutoSettings, noScroll) {
|
getPageTop: function pdfViewGetPageTop(id) {
|
||||||
if (val == this.currentScale)
|
return (this.pages[id - 1].el.offsetTop + this.pages[id - 1].el.clientTop);
|
||||||
|
},
|
||||||
|
|
||||||
|
setScale: function pdfViewSetScale(value, resetAutoSettings, noScroll) {
|
||||||
|
if (this.currentScale === value) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var pages = this.pages;
|
var pages = this.pages, page = this.page;
|
||||||
for (var i = 0; i < pages.length; i++)
|
var currentPage = pages[page - 1], dest = null;
|
||||||
pages[i].update(val * CSS_UNITS);
|
if (!noScroll && !this.isPresentationMode) {
|
||||||
|
// Obtain the current scroll position before resizing the pages.
|
||||||
|
var topLeft = currentPage.getPagePoint(this.container.scrollLeft,
|
||||||
|
(this.container.scrollTop - this.getPageTop(page)));
|
||||||
|
dest = [null, { name: 'XYZ' }, Math.round(topLeft[0]),
|
||||||
|
Math.round(topLeft[1]), null];
|
||||||
|
}
|
||||||
|
|
||||||
if (!noScroll && this.currentScale != val)
|
for (var i = 0; i < pages.length; i++) {
|
||||||
this.pages[this.page - 1].scrollIntoView();
|
pages[i].update(value * CSS_UNITS);
|
||||||
this.currentScale = val;
|
}
|
||||||
|
this.currentScale = value;
|
||||||
|
|
||||||
|
if (!noScroll) {
|
||||||
|
currentPage.scrollIntoView(dest);
|
||||||
|
}
|
||||||
|
|
||||||
var event = document.createEvent('UIEvents');
|
var event = document.createEvent('UIEvents');
|
||||||
event.initUIEvent('scalechange', false, false, window, 0);
|
event.initUIEvent('scalechange', false, false, window, 0);
|
||||||
event.scale = val;
|
event.scale = value;
|
||||||
event.resetAutoSettings = resetAutoSettings;
|
event.resetAutoSettings = resetAutoSettings;
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
|
|
||||||
parseScale: function pdfViewParseScale(value, resetAutoSettings, noScroll) {
|
parseScale: function pdfViewParseScale(value, resetAutoSettings, noScroll) {
|
||||||
if ('custom' == value)
|
if ('custom' === value) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var scale = parseFloat(value);
|
var scale = parseFloat(value);
|
||||||
this.currentScaleValue = value;
|
this.currentScaleValue = value;
|
||||||
@ -1040,14 +1057,14 @@ var PDFView = {
|
|||||||
} else if (storedHash) {
|
} else if (storedHash) {
|
||||||
this.setHash(storedHash);
|
this.setHash(storedHash);
|
||||||
} else if (scale) {
|
} else if (scale) {
|
||||||
this.parseScale(scale, true);
|
this.parseScale(scale, true, true);
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PDFView.currentScale === UNKNOWN_SCALE) {
|
if (PDFView.currentScale === UNKNOWN_SCALE) {
|
||||||
// Scale was not initialized: invalid bookmark or scale was not specified.
|
// Scale was not initialized: invalid bookmark or scale was not specified.
|
||||||
// Setting the default one.
|
// Setting the default one.
|
||||||
this.parseScale(DEFAULT_SCALE, true);
|
this.parseScale(DEFAULT_SCALE, true, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1372,15 +1389,28 @@ var PDFView = {
|
|||||||
|
|
||||||
enterPresentationMode: function pdfViewEnterPresentationMode() {
|
enterPresentationMode: function pdfViewEnterPresentationMode() {
|
||||||
this.isPresentationMode = true;
|
this.isPresentationMode = true;
|
||||||
this.page = this.presentationModeArgs.page;
|
|
||||||
this.parseScale('page-fit', true);
|
this.parseScale('page-fit', true);
|
||||||
|
// Since 'resize' events are fired when entering presentation mode,
|
||||||
|
// add this call to the end of the rendering queue to prevent
|
||||||
|
// the page from being scrolled partially out of view.
|
||||||
|
setTimeout(function() {
|
||||||
|
this.page = this.presentationModeArgs.page;
|
||||||
|
}.bind(this), 0);
|
||||||
|
|
||||||
this.showPresentationControls();
|
this.showPresentationControls();
|
||||||
},
|
},
|
||||||
|
|
||||||
exitPresentationMode: function pdfViewExitPresentationMode() {
|
exitPresentationMode: function pdfViewExitPresentationMode() {
|
||||||
this.isPresentationMode = false;
|
this.isPresentationMode = false;
|
||||||
this.parseScale(this.presentationModeArgs.previousScale);
|
var currentPage = this.pages[this.page - 1];
|
||||||
this.page = this.page;
|
this.parseScale(this.presentationModeArgs.previousScale, true, true);
|
||||||
|
// Since 'resize' events are fired when exiting from presentation mode,
|
||||||
|
// add this call to the end of the rendering queue to make sure
|
||||||
|
// that the current page is scrolled into view properly.
|
||||||
|
setTimeout(function() {
|
||||||
|
currentPage.scrollIntoView();
|
||||||
|
}, 0);
|
||||||
|
|
||||||
this.clearMouseScrollState();
|
this.clearMouseScrollState();
|
||||||
this.hidePresentationControls();
|
this.hidePresentationControls();
|
||||||
this.presentationModeArgs = null;
|
this.presentationModeArgs = null;
|
||||||
@ -1434,14 +1464,9 @@ var PDFView = {
|
|||||||
this.renderHighestPriority();
|
this.renderHighestPriority();
|
||||||
|
|
||||||
var currentPage = this.pages[this.page - 1];
|
var currentPage = this.pages[this.page - 1];
|
||||||
if (!currentPage) {
|
if (currentPage) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for presentation mode to take effect
|
|
||||||
setTimeout(function() {
|
|
||||||
currentPage.scrollIntoView();
|
currentPage.scrollIntoView();
|
||||||
}, 0);
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2490,9 +2515,10 @@ function updateViewarea() {
|
|||||||
window.addEventListener('resize', function webViewerResize(evt) {
|
window.addEventListener('resize', function webViewerResize(evt) {
|
||||||
if (PDFView.initialized &&
|
if (PDFView.initialized &&
|
||||||
(document.getElementById('pageWidthOption').selected ||
|
(document.getElementById('pageWidthOption').selected ||
|
||||||
document.getElementById('pageFitOption').selected ||
|
document.getElementById('pageFitOption').selected ||
|
||||||
document.getElementById('pageAutoOption').selected))
|
document.getElementById('pageAutoOption').selected)) {
|
||||||
PDFView.parseScale(document.getElementById('scaleSelect').value);
|
PDFView.parseScale(document.getElementById('scaleSelect').value);
|
||||||
|
}
|
||||||
updateViewarea();
|
updateViewarea();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2567,11 +2593,11 @@ window.addEventListener('scalechange', function scalechange(evt) {
|
|||||||
customScaleOption.selected = false;
|
customScaleOption.selected = false;
|
||||||
|
|
||||||
if (!evt.resetAutoSettings &&
|
if (!evt.resetAutoSettings &&
|
||||||
(document.getElementById('pageWidthOption').selected ||
|
(document.getElementById('pageWidthOption').selected ||
|
||||||
document.getElementById('pageFitOption').selected ||
|
document.getElementById('pageFitOption').selected ||
|
||||||
document.getElementById('pageAutoOption').selected)) {
|
document.getElementById('pageAutoOption').selected)) {
|
||||||
updateViewarea();
|
updateViewarea();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var predefinedValueFound = selectScaleOption('' + evt.scale);
|
var predefinedValueFound = selectScaleOption('' + evt.scale);
|
||||||
|
Loading…
Reference in New Issue
Block a user