Skip to content

Commit

Permalink
Move the PDFHistory initialization into a helper method in `PDFView…
Browse files Browse the repository at this point in the history
…erApplication`

This avoids having the initialization code "spread out", and will become even simpler once the `TODO` is addressed (which I'm planning on fixing as soon as possible).
  • Loading branch information
Snuffleupagus committed Feb 2, 2019
1 parent 4d4c98d commit 9d83420
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,22 +907,6 @@ let PDFViewerApplication = {
firstPagePromise.then((pdfPage) => {
this.loadingBar.setWidth(this.appConfig.viewerContainer);

if (!AppOptions.get('disableHistory') && !this.isViewerEmbedded) {
// The browsing history is only enabled when the viewer is standalone,
// i.e. not when it is embedded in a web page.
this.pdfHistory.initialize({
fingerprint: pdfDocument.fingerprint,
resetHistory: AppOptions.get('viewOnLoad') === ViewOnLoad.INITIAL,
updateUrl: AppOptions.get('historyUpdateUrl'),
});

if (this.pdfHistory.initialBookmark) {
this.initialBookmark = this.pdfHistory.initialBookmark;

this.initialRotation = this.pdfHistory.initialRotation;
}
}

const storePromise = store.getMultiple({
page: null,
zoom: DEFAULT_SCALE_VALUE,
Expand All @@ -939,15 +923,11 @@ let PDFViewerApplication = {
]).then(async ([values = {}, pageMode, openActionDest]) => {
const viewOnLoad = AppOptions.get('viewOnLoad');

// Always let the browser history/document hash take precedence.
if (openActionDest && !this.initialBookmark &&
viewOnLoad === ViewOnLoad.UNKNOWN) {
this.initialBookmark = JSON.stringify(openActionDest);
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
// that's currently necessary to prevent weird initial history state.
this.pdfHistory.push({ explicitDest: openActionDest,
pageNumber: null, });
}
this._initializePdfHistory({
fingerprint: pdfDocument.fingerprint,
viewOnLoad,
initialDest: openActionDest,
});
const initialBookmark = this.initialBookmark;

// Initialize the default values, from user preferences.
Expand Down Expand Up @@ -1164,6 +1144,37 @@ let PDFViewerApplication = {
});
},

/**
* @private
*/
_initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null, }) {
if (AppOptions.get('disableHistory') || this.isViewerEmbedded) {
// The browsing history is only enabled when the viewer is standalone,
// i.e. not when it is embedded in a web page.
return;
}
this.pdfHistory.initialize({
fingerprint,
resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
updateUrl: AppOptions.get('historyUpdateUrl'),
});

if (this.pdfHistory.initialBookmark) {
this.initialBookmark = this.pdfHistory.initialBookmark;

this.initialRotation = this.pdfHistory.initialRotation;
}

// Always let the browser history/document hash take precedence.
if (initialDest && !this.initialBookmark &&
viewOnLoad === ViewOnLoad.UNKNOWN) {
this.initialBookmark = JSON.stringify(initialDest);
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
// that's currently necessary to prevent weird initial history state.
this.pdfHistory.push({ explicitDest: initialDest, pageNumber: null, });
}
},

setInitialView(storedHash, { rotation, sidebarView,
scrollMode, spreadMode, } = {}) {
const setRotation = (angle) => {
Expand Down

0 comments on commit 9d83420

Please sign in to comment.