Merge pull request #9841 from Snuffleupagus/initial-position-misc-cleanup
Various (small) cleanup related to setting the initial document position on load
This commit is contained in:
commit
40d577d7dd
30
web/app.js
30
web/app.js
@ -48,7 +48,8 @@ import { Toolbar } from './toolbar';
|
|||||||
import { ViewHistory } from './view_history';
|
import { ViewHistory } from './view_history';
|
||||||
|
|
||||||
const DEFAULT_SCALE_DELTA = 1.1;
|
const DEFAULT_SCALE_DELTA = 1.1;
|
||||||
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
|
||||||
|
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
||||||
|
|
||||||
const DefaultExternalServices = {
|
const DefaultExternalServices = {
|
||||||
updateFindControlState(data) {},
|
updateFindControlState(data) {},
|
||||||
@ -1016,8 +1017,7 @@ let PDFViewerApplication = {
|
|||||||
hash: null,
|
hash: null,
|
||||||
};
|
};
|
||||||
let storePromise = store.getMultiple({
|
let storePromise = store.getMultiple({
|
||||||
exists: false,
|
page: null,
|
||||||
page: '1',
|
|
||||||
zoom: DEFAULT_SCALE_VALUE,
|
zoom: DEFAULT_SCALE_VALUE,
|
||||||
scrollLeft: '0',
|
scrollLeft: '0',
|
||||||
scrollTop: '0',
|
scrollTop: '0',
|
||||||
@ -1030,17 +1030,18 @@ let PDFViewerApplication = {
|
|||||||
Promise.all([storePromise, pageModePromise]).then(
|
Promise.all([storePromise, pageModePromise]).then(
|
||||||
([values = {}, pageMode]) => {
|
([values = {}, pageMode]) => {
|
||||||
// Initialize the default values, from user preferences.
|
// Initialize the default values, from user preferences.
|
||||||
let hash = AppOptions.get('defaultZoomValue') ?
|
const zoom = AppOptions.get('defaultZoomValue');
|
||||||
('zoom=' + AppOptions.get('defaultZoomValue')) : null;
|
let hash = zoom ? `zoom=${zoom}` : null;
|
||||||
|
|
||||||
let rotation = null;
|
let rotation = null;
|
||||||
let sidebarView = AppOptions.get('sidebarViewOnLoad');
|
let sidebarView = AppOptions.get('sidebarViewOnLoad');
|
||||||
let scrollMode = AppOptions.get('scrollModeOnLoad');
|
let scrollMode = AppOptions.get('scrollModeOnLoad');
|
||||||
let spreadMode = AppOptions.get('spreadModeOnLoad');
|
let spreadMode = AppOptions.get('spreadModeOnLoad');
|
||||||
|
|
||||||
if (values.exists && AppOptions.get('showPreviousViewOnLoad')) {
|
if (values.page && AppOptions.get('showPreviousViewOnLoad')) {
|
||||||
hash = 'page=' + values.page +
|
hash = 'page=' + values.page + '&zoom=' + (zoom || values.zoom) +
|
||||||
'&zoom=' + (AppOptions.get('defaultZoomValue') || values.zoom) +
|
|
||||||
',' + values.scrollLeft + ',' + values.scrollTop;
|
',' + values.scrollLeft + ',' + values.scrollTop;
|
||||||
|
|
||||||
rotation = parseInt(values.rotation, 10);
|
rotation = parseInt(values.rotation, 10);
|
||||||
sidebarView = sidebarView || (values.sidebarView | 0);
|
sidebarView = sidebarView || (values.sidebarView | 0);
|
||||||
if (values.scrollMode !== null) {
|
if (values.scrollMode !== null) {
|
||||||
@ -1074,10 +1075,20 @@ let PDFViewerApplication = {
|
|||||||
if (!this.isViewerEmbedded) {
|
if (!this.isViewerEmbedded) {
|
||||||
pdfViewer.focus();
|
pdfViewer.focus();
|
||||||
}
|
}
|
||||||
return pagesPromise;
|
|
||||||
|
return Promise.race([
|
||||||
|
pagesPromise,
|
||||||
|
new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// For documents with different page sizes, once all pages are resolved,
|
// For documents with different page sizes, once all pages are resolved,
|
||||||
// ensure that the correct location becomes visible on load.
|
// ensure that the correct location becomes visible on load.
|
||||||
|
// To reduce the risk, in very large and/or slow loading documents,
|
||||||
|
// that the location changes *after* the user has started interacting
|
||||||
|
// with the viewer, wait for either `pagesPromise` or a timeout above.
|
||||||
|
|
||||||
if (!initialParams.bookmark && !initialParams.hash) {
|
if (!initialParams.bookmark && !initialParams.hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1852,7 +1863,6 @@ function webViewerUpdateViewarea(evt) {
|
|||||||
|
|
||||||
if (store && PDFViewerApplication.isInitialViewSet) {
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
||||||
store.setMultiple({
|
store.setMultiple({
|
||||||
'exists': true,
|
|
||||||
'page': location.pageNumber,
|
'page': location.pageNumber,
|
||||||
'zoom': location.scale,
|
'zoom': location.scale,
|
||||||
'scrollLeft': location.left,
|
'scrollLeft': location.left,
|
||||||
|
@ -33,11 +33,12 @@ class ViewHistory {
|
|||||||
let database = JSON.parse(databaseStr || '{}');
|
let database = JSON.parse(databaseStr || '{}');
|
||||||
if (!('files' in database)) {
|
if (!('files' in database)) {
|
||||||
database.files = [];
|
database.files = [];
|
||||||
|
} else {
|
||||||
|
while (database.files.length >= this.cacheSize) {
|
||||||
|
database.files.shift();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (database.files.length >= this.cacheSize) {
|
let index = -1;
|
||||||
database.files.shift();
|
|
||||||
}
|
|
||||||
let index;
|
|
||||||
for (let i = 0, length = database.files.length; i < length; i++) {
|
for (let i = 0, length = database.files.length; i < length; i++) {
|
||||||
let branch = database.files[i];
|
let branch = database.files[i];
|
||||||
if (branch.fingerprint === this.fingerprint) {
|
if (branch.fingerprint === this.fingerprint) {
|
||||||
@ -45,7 +46,7 @@ class ViewHistory {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof index !== 'number') {
|
if (index === -1) {
|
||||||
index = database.files.push({ fingerprint: this.fingerprint, }) - 1;
|
index = database.files.push({ fingerprint: this.fingerprint, }) - 1;
|
||||||
}
|
}
|
||||||
this.file = database.files[index];
|
this.file = database.files[index];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user