Maintain the current position in the document when zooming
This commit is contained in:
parent
d6ed4f2631
commit
05c331c295
3 changed files with 87 additions and 33 deletions
|
@ -40,6 +40,7 @@ var SCALE_SELECT_PADDING = 22;
|
|||
var THUMBNAIL_SCROLL_MARGIN = -19;
|
||||
var USE_ONLY_CSS_ZOOM = false;
|
||||
var CLEANUP_TIMEOUT = 30000;
|
||||
var IGNORE_CURRENT_POSITION_ON_ZOOM = false;
|
||||
//#if B2G
|
||||
//USE_ONLY_CSS_ZOOM = true;
|
||||
//#endif
|
||||
|
@ -111,6 +112,7 @@ var PDFView = {
|
|||
previousPageNumber: 1,
|
||||
isViewerEmbedded: (window.parent !== window),
|
||||
idleTimeout: null,
|
||||
currentPosition: null,
|
||||
|
||||
// called once when the document is loaded
|
||||
initialize: function pdfViewInitialize() {
|
||||
|
@ -219,7 +221,13 @@ var PDFView = {
|
|||
this.currentScale = newScale;
|
||||
|
||||
if (!noScroll) {
|
||||
this.pages[this.page - 1].scrollIntoView();
|
||||
var page = this.page, dest;
|
||||
if (this.currentPosition && !IGNORE_CURRENT_POSITION_ON_ZOOM) {
|
||||
page = this.currentPosition.page;
|
||||
dest = [null, { name: 'XYZ' }, this.currentPosition.left,
|
||||
this.currentPosition.top, null];
|
||||
}
|
||||
this.pages[page - 1].scrollIntoView(dest);
|
||||
}
|
||||
var event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('scalechange', false, false, window, 0);
|
||||
|
@ -1049,6 +1057,9 @@ var PDFView = {
|
|||
// Reset 'currentPageNumber', since otherwise the page's scale will be wrong
|
||||
// if 'currentPageNumber' is larger than the number of pages in the file.
|
||||
document.getElementById('pageNumber').value = currentPageNumber = 1;
|
||||
// Reset the current position when loading a new file,
|
||||
// to prevent displaying the wrong position in the document.
|
||||
this.currentPosition = null;
|
||||
|
||||
if (PDFHistory.initialDestination) {
|
||||
this.navigateTo(PDFHistory.initialDestination);
|
||||
|
@ -1307,7 +1318,7 @@ var PDFView = {
|
|||
Math.max(0, currentHeight + viewHeight - bottom);
|
||||
percentHeight = ((viewHeight - hiddenHeight) * 100 / viewHeight) | 0;
|
||||
|
||||
visible.push({ id: view.id, y: currentHeight,
|
||||
visible.push({ id: view.id, x: currentWidth, y: currentHeight,
|
||||
view: view, percent: percentHeight });
|
||||
}
|
||||
|
||||
|
@ -1379,7 +1390,7 @@ var PDFView = {
|
|||
},
|
||||
|
||||
rotatePages: function pdfViewRotatePages(delta) {
|
||||
|
||||
var currentPage = this.pages[this.page - 1];
|
||||
this.pageRotation = (this.pageRotation + 360 + delta) % 360;
|
||||
|
||||
for (var i = 0, l = this.pages.length; i < l; i++) {
|
||||
|
@ -1392,19 +1403,13 @@ var PDFView = {
|
|||
thumb.update(this.pageRotation);
|
||||
}
|
||||
|
||||
this.setScale(this.currentScaleValue, true);
|
||||
this.setScale(this.currentScaleValue, true, true);
|
||||
|
||||
this.renderHighestPriority();
|
||||
|
||||
var currentPage = this.pages[this.page - 1];
|
||||
if (!currentPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for presentation mode to take effect
|
||||
setTimeout(function() {
|
||||
if (currentPage) {
|
||||
currentPage.scrollIntoView();
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1615,6 +1620,11 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
|||
PDFJS.verbosity = hashParams['verbosity'] | 0;
|
||||
}
|
||||
|
||||
if ('ignoreCurrentPositionOnZoom' in hashParams) {
|
||||
IGNORE_CURRENT_POSITION_ON_ZOOM =
|
||||
(hashParams['ignoreCurrentPositionOnZoom'] === 'true');
|
||||
}
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
var locale = navigator.language;
|
||||
if ('locale' in hashParams)
|
||||
|
@ -1812,17 +1822,26 @@ function updateViewarea() {
|
|||
var pdfOpenParams = '#page=' + pageNumber;
|
||||
pdfOpenParams += '&zoom=' + normalizedScaleValue;
|
||||
var currentPage = PDFView.pages[pageNumber - 1];
|
||||
var topLeft = currentPage.getPagePoint(PDFView.container.scrollLeft,
|
||||
(PDFView.container.scrollTop - firstPage.y));
|
||||
pdfOpenParams += ',' + Math.round(topLeft[0]) + ',' + Math.round(topLeft[1]);
|
||||
var container = PDFView.container;
|
||||
var topLeft = currentPage.getPagePoint((container.scrollLeft - firstPage.x),
|
||||
(container.scrollTop - firstPage.y));
|
||||
var intLeft = Math.round(topLeft[0]);
|
||||
var intTop = Math.round(topLeft[1]);
|
||||
pdfOpenParams += ',' + intLeft + ',' + intTop;
|
||||
|
||||
if (PresentationMode.active || PresentationMode.switchInProgress) {
|
||||
PDFView.currentPosition = null;
|
||||
} else {
|
||||
PDFView.currentPosition = { page: pageNumber, left: intLeft, top: intTop };
|
||||
}
|
||||
|
||||
var store = PDFView.store;
|
||||
store.initializedPromise.then(function() {
|
||||
store.set('exists', true);
|
||||
store.set('page', pageNumber);
|
||||
store.set('zoom', normalizedScaleValue);
|
||||
store.set('scrollLeft', Math.round(topLeft[0]));
|
||||
store.set('scrollTop', Math.round(topLeft[1]));
|
||||
store.set('scrollLeft', intLeft);
|
||||
store.set('scrollTop', intTop);
|
||||
});
|
||||
var href = PDFView.getAnchorUrl(pdfOpenParams);
|
||||
document.getElementById('viewBookmark').href = href;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue