Skip to content

Commit

Permalink
Move the parseCurrentHash helper function into PDFHistory
Browse files Browse the repository at this point in the history
Looking at the `parseCurrentHash` function again it's now difficult for me to understand *what* I was thinking, since having a helper function that needs to be manually passed a `linkService` reference just looks weird.
  • Loading branch information
Snuffleupagus committed Dec 3, 2019
1 parent 9729f55 commit fef0cbb
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ function getCurrentHash() {
return document.location.hash;
}

function parseCurrentHash(linkService) {
let hash = unescape(getCurrentHash()).substring(1);
let params = parseQueryString(hash);

let page = params.page | 0;
if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
page = null;
}
return { hash, page, rotation: linkService.rotation, };
}

class PDFHistory {
/**
* @param {PDFHistoryOptions} options
Expand Down Expand Up @@ -125,7 +114,7 @@ class PDFHistory {
this._position = null;

if (!this._isValidState(state, /* checkReload = */ true) || resetHistory) {
let { hash, page, rotation, } = parseCurrentHash(this.linkService);
const { hash, page, rotation, } = this._parseCurrentHash();

if (!hash || reInitialized || resetHistory) {
// Ensure that the browser history is reset on PDF document load.
Expand Down Expand Up @@ -458,6 +447,20 @@ class PDFHistory {
this._numPositionUpdates = 0;
}

/**
* @private
*/
_parseCurrentHash() {
const hash = unescape(getCurrentHash()).substring(1);
let page = parseQueryString(hash).page | 0;

if (!(Number.isInteger(page) &&
page > 0 && page <= this.linkService.pagesCount)) {
page = null;
}
return { hash, page, rotation: this.linkService.rotation, };
}

/**
* @private
*/
Expand Down Expand Up @@ -530,7 +533,7 @@ class PDFHistory {
// This case corresponds to the user changing the hash of the document.
this._uid++;

let { hash, page, rotation, } = parseCurrentHash(this.linkService);
const { hash, page, rotation, } = this._parseCurrentHash();
this._pushOrReplaceState({ hash, page, rotation, },
/* forceReplace = */ true);
return;
Expand Down

0 comments on commit fef0cbb

Please sign in to comment.