|
|
|
@ -17,15 +17,21 @@
@@ -17,15 +17,21 @@
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
var PDFHistory = { |
|
|
|
|
initialized: false, |
|
|
|
|
initialDestination: null, |
|
|
|
|
var PDFHistory = (function () { |
|
|
|
|
function PDFHistory(options) { |
|
|
|
|
this.linkService = options.linkService; |
|
|
|
|
|
|
|
|
|
this.initialized = false; |
|
|
|
|
this.initialDestination = null; |
|
|
|
|
this.initialBookmark = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PDFHistory.prototype = { |
|
|
|
|
/** |
|
|
|
|
* @param {string} fingerprint |
|
|
|
|
* @param {IPDFLinkService} linkService |
|
|
|
|
*/ |
|
|
|
|
initialize: function pdfHistoryInitialize(fingerprint, linkService) { |
|
|
|
|
initialize: function pdfHistoryInitialize(fingerprint) { |
|
|
|
|
this.initialized = true; |
|
|
|
|
this.reInitialized = false; |
|
|
|
|
this.allowHashChange = true; |
|
|
|
@ -41,7 +47,6 @@ var PDFHistory = {
@@ -41,7 +47,6 @@ var PDFHistory = {
|
|
|
|
|
this.nextHashParam = ''; |
|
|
|
|
|
|
|
|
|
this.fingerprint = fingerprint; |
|
|
|
|
this.linkService = linkService; |
|
|
|
|
this.currentUid = this.uid = 0; |
|
|
|
|
this.current = {}; |
|
|
|
|
|
|
|
|
@ -52,7 +57,7 @@ var PDFHistory = {
@@ -52,7 +57,7 @@ var PDFHistory = {
|
|
|
|
|
if (state.target.dest) { |
|
|
|
|
this.initialDestination = state.target.dest; |
|
|
|
|
} else { |
|
|
|
|
linkService.setHash(state.target.hash); |
|
|
|
|
this.initialBookmark = state.target.hash; |
|
|
|
|
} |
|
|
|
|
this.currentUid = state.uid; |
|
|
|
|
this.uid = state.uid + 1; |
|
|
|
@ -65,7 +70,7 @@ var PDFHistory = {
@@ -65,7 +70,7 @@ var PDFHistory = {
|
|
|
|
|
// is opened in the web viewer.
|
|
|
|
|
this.reInitialized = true; |
|
|
|
|
} |
|
|
|
|
this._pushOrReplaceState({ fingerprint: this.fingerprint }, true); |
|
|
|
|
this._pushOrReplaceState({fingerprint: this.fingerprint}, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
@ -88,8 +93,8 @@ var PDFHistory = {
@@ -88,8 +93,8 @@ var PDFHistory = {
|
|
|
|
|
if (self.uid === 0) { |
|
|
|
|
var previousParams = (self.previousHash && self.currentBookmark && |
|
|
|
|
self.previousHash !== self.currentBookmark) ? |
|
|
|
|
{ hash: self.currentBookmark, page: self.currentPage } : |
|
|
|
|
{ page: 1 }; |
|
|
|
|
{hash: self.currentBookmark, page: self.currentPage} : |
|
|
|
|
{page: 1}; |
|
|
|
|
self.historyUnlocked = false; |
|
|
|
|
self.allowHashChange = false; |
|
|
|
|
window.history.back(); |
|
|
|
@ -97,7 +102,7 @@ var PDFHistory = {
@@ -97,7 +102,7 @@ var PDFHistory = {
|
|
|
|
|
window.history.forward(); |
|
|
|
|
self.historyUnlocked = true; |
|
|
|
|
} |
|
|
|
|
self._pushToHistory({ hash: self.previousHash }, false, true); |
|
|
|
|
self._pushToHistory({hash: self.previousHash}, false, true); |
|
|
|
|
self._updatePreviousBookmark(); |
|
|
|
|
} |
|
|
|
|
}, false); |
|
|
|
@ -112,14 +117,16 @@ var PDFHistory = {
@@ -112,14 +117,16 @@ var PDFHistory = {
|
|
|
|
|
} |
|
|
|
|
// Remove the event listener when navigating away from the document,
|
|
|
|
|
// since 'beforeunload' prevents Firefox from caching the document.
|
|
|
|
|
window.removeEventListener('beforeunload', pdfHistoryBeforeUnload, false); |
|
|
|
|
window.removeEventListener('beforeunload', pdfHistoryBeforeUnload, |
|
|
|
|
false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false); |
|
|
|
|
|
|
|
|
|
window.addEventListener('pageshow', function pdfHistoryPageShow(evt) { |
|
|
|
|
// If the entire viewer (including the PDF file) is cached in the browser,
|
|
|
|
|
// we need to reattach the 'beforeunload' event listener since
|
|
|
|
|
// the 'DOMContentLoaded' event is not fired on 'pageshow'.
|
|
|
|
|
// If the entire viewer (including the PDF file) is cached in
|
|
|
|
|
// the browser, we need to reattach the 'beforeunload' event listener
|
|
|
|
|
// since the 'DOMContentLoaded' event is not fired on 'pageshow'.
|
|
|
|
|
window.addEventListener('beforeunload', pdfHistoryBeforeUnload, false); |
|
|
|
|
}, false); |
|
|
|
|
|
|
|
|
@ -266,10 +273,12 @@ var PDFHistory = {
@@ -266,10 +273,12 @@ var PDFHistory = {
|
|
|
|
|
} |
|
|
|
|
if (this.uid > 0 && !(this.previousBookmark && this.previousPage)) { |
|
|
|
|
// Prevent the history from getting stuck in the current state,
|
|
|
|
|
// effectively preventing the user from going back/forward in the history.
|
|
|
|
|
// effectively preventing the user from going back/forward in
|
|
|
|
|
// the history.
|
|
|
|
|
//
|
|
|
|
|
// This happens if the current position in the document didn't change when
|
|
|
|
|
// the history was previously updated. The reasons for this are either:
|
|
|
|
|
// This happens if the current position in the document didn't change
|
|
|
|
|
// when the history was previously updated. The reasons for this are
|
|
|
|
|
// either:
|
|
|
|
|
// 1. The current zoom value is such that the document does not need to,
|
|
|
|
|
// or cannot, be scrolled to display the destination.
|
|
|
|
|
// 2. The previous destination is broken, and doesn't actally point to a
|
|
|
|
@ -289,7 +298,7 @@ var PDFHistory = {
@@ -289,7 +298,7 @@ var PDFHistory = {
|
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
var params = { hash: this.currentBookmark, page: this.currentPage }; |
|
|
|
|
var params = {hash: this.currentBookmark, page: this.currentPage}; |
|
|
|
|
if (this.isViewerInPresentationMode) { |
|
|
|
|
params.hash = null; |
|
|
|
|
} |
|
|
|
@ -297,7 +306,7 @@ var PDFHistory = {
@@ -297,7 +306,7 @@ var PDFHistory = {
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_stateObj: function pdfHistory_stateObj(params) { |
|
|
|
|
return { fingerprint: this.fingerprint, uid: this.uid, target: params }; |
|
|
|
|
return {fingerprint: this.fingerprint, uid: this.uid, target: params}; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_pushToHistory: function pdfHistory_pushToHistory(params, |
|
|
|
@ -379,4 +388,7 @@ var PDFHistory = {
@@ -379,4 +388,7 @@ var PDFHistory = {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return PDFHistory; |
|
|
|
|
})(); |
|
|
|
|