Browse Source

Refactor reading from the `ViewHistory` in `PDFViewerApplication.load`

Jonas Jenwald 8 years ago
parent
commit
f7c4ed4bc3
  1. 43
      web/app.js

43
web/app.js

@ -932,37 +932,34 @@ let PDFViewerApplication = {
bookmark: this.initialBookmark, bookmark: this.initialBookmark,
hash: null, hash: null,
}; };
let storedHash = this.viewerPrefs['defaultZoomValue'] ? let storePromise = store.getMultiple({
('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
let sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
new Promise((resolve, reject) => {
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
resolve();
return;
}
store.getMultiple({
exists: false, exists: false,
page: '1', page: '1',
zoom: DEFAULT_SCALE_VALUE, zoom: DEFAULT_SCALE_VALUE,
scrollLeft: '0', scrollLeft: '0',
scrollTop: '0', scrollTop: '0',
sidebarView: SidebarView.NONE, sidebarView: SidebarView.NONE,
}).then((values) => { }).catch(() => { /* Unable to read from storage -- ignoring errors. */ });
if (!values.exists) {
resolve(); storePromise.then((values = {}) => {
return; // Initialize the default values, from user preferences.
} let hash = this.viewerPrefs['defaultZoomValue'] ?
storedHash = 'page=' + values.page + ('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
let sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
if (values.exists && this.viewerPrefs['showPreviousViewOnLoad']) {
hash = 'page=' + values.page +
'&zoom=' + (this.viewerPrefs['defaultZoomValue'] || values.zoom) + '&zoom=' + (this.viewerPrefs['defaultZoomValue'] || values.zoom) +
',' + values.scrollLeft + ',' + values.scrollTop; ',' + values.scrollLeft + ',' + values.scrollTop;
sidebarView = this.viewerPrefs['sidebarViewOnLoad'] || sidebarView = sidebarView || (values.sidebarView | 0);
(values.sidebarView | 0); }
resolve(); return {
}).catch(resolve); hash,
}).then(() => { sidebarView,
this.setInitialView(storedHash, { sidebarView, scale, }); };
initialParams.hash = storedHash; }).then(({ hash, sidebarView, }) => {
this.setInitialView(hash, { sidebarView, scale, });
initialParams.hash = hash;
// Make all navigation keys work on document load, // Make all navigation keys work on document load,
// unless the viewer is embedded in a web page. // unless the viewer is embedded in a web page.

Loading…
Cancel
Save