|
@@ -113,10 +113,12 @@ module.exports = pdfjsLib;
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
value: true
|
|
|
});
|
|
|
-exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.mozL10n = exports.RendererType = exports.cloneObj = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
|
|
|
+exports.waitOnEventOrTimeout = exports.WaitOnType = exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.mozL10n = exports.RendererType = exports.cloneObj = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
|
|
|
|
|
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
|
|
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
|
+
|
|
|
var _pdfjsLib = __w_pdfjs_require__(0);
|
|
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -420,6 +422,41 @@ function cloneObj(obj) {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+var WaitOnType = {
|
|
|
+ EVENT: 'event',
|
|
|
+ TIMEOUT: 'timeout'
|
|
|
+};
|
|
|
+function waitOnEventOrTimeout(_ref) {
|
|
|
+ var target = _ref.target,
|
|
|
+ name = _ref.name,
|
|
|
+ _ref$delay = _ref.delay,
|
|
|
+ delay = _ref$delay === undefined ? 0 : _ref$delay;
|
|
|
+
|
|
|
+ if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) !== 'object' || !(name && typeof name === 'string') || !(Number.isInteger(delay) && delay >= 0)) {
|
|
|
+ return Promise.reject(new Error('waitOnEventOrTimeout - invalid paramaters.'));
|
|
|
+ }
|
|
|
+ var capability = (0, _pdfjsLib.createPromiseCapability)();
|
|
|
+ function handler(type) {
|
|
|
+ if (target instanceof EventBus) {
|
|
|
+ target.off(name, eventHandler);
|
|
|
+ } else {
|
|
|
+ target.removeEventListener(name, eventHandler);
|
|
|
+ }
|
|
|
+ if (timeout) {
|
|
|
+ clearTimeout(timeout);
|
|
|
+ }
|
|
|
+ capability.resolve(type);
|
|
|
+ }
|
|
|
+ var eventHandler = handler.bind(null, WaitOnType.EVENT);
|
|
|
+ if (target instanceof EventBus) {
|
|
|
+ target.on(name, eventHandler);
|
|
|
+ } else {
|
|
|
+ target.addEventListener(name, eventHandler);
|
|
|
+ }
|
|
|
+ var timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
|
|
|
+ var timeout = setTimeout(timeoutHandler, delay);
|
|
|
+ return capability.promise;
|
|
|
+}
|
|
|
var animationStarted = new Promise(function (resolve) {
|
|
|
window.requestAnimationFrame(resolve);
|
|
|
});
|
|
@@ -476,10 +513,10 @@ function clamp(v, min, max) {
|
|
|
|
|
|
var ProgressBar = function () {
|
|
|
function ProgressBar(id) {
|
|
|
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
|
- height = _ref.height,
|
|
|
- width = _ref.width,
|
|
|
- units = _ref.units;
|
|
|
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
|
+ height = _ref2.height,
|
|
|
+ width = _ref2.width,
|
|
|
+ units = _ref2.units;
|
|
|
|
|
|
_classCallCheck(this, ProgressBar);
|
|
|
|
|
@@ -580,6 +617,8 @@ exports.binarySearchFirstItem = binarySearchFirstItem;
|
|
|
exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
|
|
|
exports.animationStarted = animationStarted;
|
|
|
exports.localized = localized;
|
|
|
+exports.WaitOnType = WaitOnType;
|
|
|
+exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
|
|
|
|
|
|
/***/ }),
|
|
|
/* 2 */
|
|
@@ -792,17 +831,18 @@ var PDFLinkService = function () {
|
|
|
console.error('PDFLinkService.navigateTo: "' + pageNumber + '" is not ' + ('a valid page number, for dest="' + dest + '".'));
|
|
|
return;
|
|
|
}
|
|
|
- _this.pdfViewer.scrollPageIntoView({
|
|
|
- pageNumber: pageNumber,
|
|
|
- destArray: explicitDest
|
|
|
- });
|
|
|
if (_this.pdfHistory) {
|
|
|
+ _this.pdfHistory.pushCurrentPosition();
|
|
|
_this.pdfHistory.push({
|
|
|
- dest: explicitDest,
|
|
|
- hash: namedDest,
|
|
|
- page: pageNumber
|
|
|
+ namedDest: namedDest,
|
|
|
+ explicitDest: explicitDest,
|
|
|
+ pageNumber: pageNumber
|
|
|
});
|
|
|
}
|
|
|
+ _this.pdfViewer.scrollPageIntoView({
|
|
|
+ pageNumber: pageNumber,
|
|
|
+ destArray: explicitDest
|
|
|
+ });
|
|
|
};
|
|
|
new Promise(function (resolve, reject) {
|
|
|
if (typeof dest === 'string') {
|
|
@@ -858,9 +898,6 @@ var PDFLinkService = function () {
|
|
|
});
|
|
|
}
|
|
|
if ('nameddest' in params) {
|
|
|
- if (this.pdfHistory) {
|
|
|
- this.pdfHistory.updateNextHashParam(params.nameddest);
|
|
|
- }
|
|
|
this.navigateTo(params.nameddest);
|
|
|
return;
|
|
|
}
|
|
@@ -917,9 +954,6 @@ var PDFLinkService = function () {
|
|
|
}
|
|
|
} catch (ex) {}
|
|
|
if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
|
|
|
- if (this.pdfHistory) {
|
|
|
- this.pdfHistory.updateNextHashParam(dest);
|
|
|
- }
|
|
|
this.navigateTo(dest);
|
|
|
return;
|
|
|
}
|
|
@@ -3083,302 +3117,421 @@ exports.PDFViewer = PDFViewer;
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
value: true
|
|
|
});
|
|
|
-exports.PDFHistory = undefined;
|
|
|
+exports.isDestsEqual = exports.PDFHistory = undefined;
|
|
|
+
|
|
|
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
|
+
|
|
|
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
+
|
|
|
+var _ui_utils = __w_pdfjs_require__(1);
|
|
|
|
|
|
var _dom_events = __w_pdfjs_require__(2);
|
|
|
|
|
|
-function PDFHistory(options) {
|
|
|
- this.linkService = options.linkService;
|
|
|
- this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
|
|
|
- this.initialized = false;
|
|
|
- this.initialDestination = null;
|
|
|
- this.initialBookmark = null;
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
+
|
|
|
+var HASH_CHANGE_TIMEOUT = 1000;
|
|
|
+var POSITION_UPDATED_THRESHOLD = 50;
|
|
|
+var UPDATE_VIEWAREA_TIMEOUT = 2000;
|
|
|
+function getCurrentHash() {
|
|
|
+ return document.location.hash;
|
|
|
}
|
|
|
-PDFHistory.prototype = {
|
|
|
- initialize: function pdfHistoryInitialize(fingerprint) {
|
|
|
- this.initialized = true;
|
|
|
- this.reInitialized = false;
|
|
|
- this.allowHashChange = true;
|
|
|
- this.historyUnlocked = true;
|
|
|
- this.isViewerInPresentationMode = false;
|
|
|
- this.previousHash = window.location.hash.substring(1);
|
|
|
- this.currentBookmark = '';
|
|
|
- this.currentPage = 0;
|
|
|
- this.updatePreviousBookmark = false;
|
|
|
- this.previousBookmark = '';
|
|
|
- this.previousPage = 0;
|
|
|
- this.nextHashParam = '';
|
|
|
- this.fingerprint = fingerprint;
|
|
|
- this.currentUid = this.uid = 0;
|
|
|
- this.current = {};
|
|
|
- var state = window.history.state;
|
|
|
- if (this._isStateObjectDefined(state)) {
|
|
|
- if (state.target.dest) {
|
|
|
- this.initialDestination = state.target.dest;
|
|
|
- } else {
|
|
|
- this.initialBookmark = state.target.hash;
|
|
|
+function parseCurrentHash(linkService) {
|
|
|
+ var hash = unescape(getCurrentHash()).substring(1);
|
|
|
+ var params = (0, _ui_utils.parseQueryString)(hash);
|
|
|
+ var page = params.page | 0;
|
|
|
+ if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
|
|
|
+ page = null;
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ hash: hash,
|
|
|
+ page: page
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+var PDFHistory = function () {
|
|
|
+ function PDFHistory(_ref) {
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
+ var linkService = _ref.linkService,
|
|
|
+ eventBus = _ref.eventBus;
|
|
|
+
|
|
|
+ _classCallCheck(this, PDFHistory);
|
|
|
+
|
|
|
+ this.linkService = linkService;
|
|
|
+ this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
|
|
|
+ this.initialized = false;
|
|
|
+ this.initialBookmark = null;
|
|
|
+ this._boundEvents = Object.create(null);
|
|
|
+ this._isViewerInPresentationMode = false;
|
|
|
+ this._isPagesLoaded = false;
|
|
|
+ this.eventBus.on('presentationmodechanged', function (evt) {
|
|
|
+ _this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
|
|
|
+ });
|
|
|
+ this.eventBus.on('pagesloaded', function (evt) {
|
|
|
+ _this._isPagesLoaded = !!evt.pagesCount;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ _createClass(PDFHistory, [{
|
|
|
+ key: 'initialize',
|
|
|
+ value: function initialize(fingerprint) {
|
|
|
+ var resetHistory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
+
|
|
|
+ if (!fingerprint || typeof fingerprint !== 'string') {
|
|
|
+ console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
|
|
|
+ return;
|
|
|
}
|
|
|
- this.currentUid = state.uid;
|
|
|
- this.uid = state.uid + 1;
|
|
|
- this.current = state.target;
|
|
|
- } else {
|
|
|
- if (state && state.fingerprint && this.fingerprint !== state.fingerprint) {
|
|
|
- this.reInitialized = true;
|
|
|
+ var reInitialized = this.initialized && this.fingerprint !== fingerprint;
|
|
|
+ this.fingerprint = fingerprint;
|
|
|
+ if (!this.initialized) {
|
|
|
+ this._bindEvents();
|
|
|
+ }
|
|
|
+ var state = window.history.state;
|
|
|
+ this.initialized = true;
|
|
|
+ this.initialBookmark = null;
|
|
|
+ this._popStateInProgress = false;
|
|
|
+ this._blockHashChange = 0;
|
|
|
+ this._currentHash = getCurrentHash();
|
|
|
+ this._numPositionUpdates = 0;
|
|
|
+ this._currentUid = this._uid = 0;
|
|
|
+ this._destination = null;
|
|
|
+ this._position = null;
|
|
|
+ if (!this._isValidState(state) || resetHistory) {
|
|
|
+ var _parseCurrentHash = parseCurrentHash(this.linkService),
|
|
|
+ hash = _parseCurrentHash.hash,
|
|
|
+ page = _parseCurrentHash.page;
|
|
|
+
|
|
|
+ if (!hash || reInitialized || resetHistory) {
|
|
|
+ this._pushOrReplaceState(null, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._pushOrReplaceState({
|
|
|
+ hash: hash,
|
|
|
+ page: page
|
|
|
+ }, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var destination = state.destination;
|
|
|
+ this._updateInternalState(destination, state.uid, true);
|
|
|
+ if (destination.dest) {
|
|
|
+ this.initialBookmark = JSON.stringify(destination.dest);
|
|
|
+ this._destination.page = null;
|
|
|
+ } else if (destination.hash) {
|
|
|
+ this.initialBookmark = destination.hash;
|
|
|
+ } else if (destination.page) {
|
|
|
+ this.initialBookmark = 'page=' + destination.page;
|
|
|
}
|
|
|
- this._pushOrReplaceState({ fingerprint: this.fingerprint }, true);
|
|
|
}
|
|
|
- var self = this;
|
|
|
- window.addEventListener('popstate', function pdfHistoryPopstate(evt) {
|
|
|
- if (!self.historyUnlocked) {
|
|
|
+ }, {
|
|
|
+ key: 'push',
|
|
|
+ value: function push(_ref2) {
|
|
|
+ var namedDest = _ref2.namedDest,
|
|
|
+ explicitDest = _ref2.explicitDest,
|
|
|
+ pageNumber = _ref2.pageNumber;
|
|
|
+
|
|
|
+ if (!this.initialized) {
|
|
|
return;
|
|
|
}
|
|
|
- if (evt.state) {
|
|
|
- self._goTo(evt.state);
|
|
|
+ if (namedDest && typeof namedDest !== 'string' || !(explicitDest instanceof Array) || !(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
|
|
|
+ console.error('PDFHistory.push: Invalid parameters.');
|
|
|
return;
|
|
|
}
|
|
|
- if (self.uid === 0) {
|
|
|
- var previousParams = self.previousHash && self.currentBookmark && self.previousHash !== self.currentBookmark ? {
|
|
|
- hash: self.currentBookmark,
|
|
|
- page: self.currentPage
|
|
|
- } : { page: 1 };
|
|
|
- replacePreviousHistoryState(previousParams, function () {
|
|
|
- updateHistoryWithCurrentHash();
|
|
|
- });
|
|
|
- } else {
|
|
|
- updateHistoryWithCurrentHash();
|
|
|
+ var hash = namedDest || JSON.stringify(explicitDest);
|
|
|
+ if (!hash) {
|
|
|
+ return;
|
|
|
}
|
|
|
- });
|
|
|
- function updateHistoryWithCurrentHash() {
|
|
|
- self.previousHash = window.location.hash.slice(1);
|
|
|
- self._pushToHistory({ hash: self.previousHash }, false, true);
|
|
|
- self._updatePreviousBookmark();
|
|
|
- }
|
|
|
- function replacePreviousHistoryState(params, callback) {
|
|
|
- self.historyUnlocked = false;
|
|
|
- self.allowHashChange = false;
|
|
|
- window.addEventListener('popstate', rewriteHistoryAfterBack);
|
|
|
- history.back();
|
|
|
- function rewriteHistoryAfterBack() {
|
|
|
- window.removeEventListener('popstate', rewriteHistoryAfterBack);
|
|
|
- window.addEventListener('popstate', rewriteHistoryAfterForward);
|
|
|
- self._pushToHistory(params, false, true);
|
|
|
- history.forward();
|
|
|
- }
|
|
|
- function rewriteHistoryAfterForward() {
|
|
|
- window.removeEventListener('popstate', rewriteHistoryAfterForward);
|
|
|
- self.allowHashChange = true;
|
|
|
- self.historyUnlocked = true;
|
|
|
- callback();
|
|
|
+ var forceReplace = false;
|
|
|
+ if (this._destination && (this._destination.hash === hash || isDestsEqual(this._destination.dest, explicitDest))) {
|
|
|
+ if (this._destination.page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ forceReplace = true;
|
|
|
}
|
|
|
- }
|
|
|
- function pdfHistoryBeforeUnload() {
|
|
|
- var previousParams = self._getPreviousParams(null, true);
|
|
|
- if (previousParams) {
|
|
|
- var replacePrevious = !self.current.dest && self.current.hash !== self.previousHash;
|
|
|
- self._pushToHistory(previousParams, false, replacePrevious);
|
|
|
- self._updatePreviousBookmark();
|
|
|
+ if (this._popStateInProgress && !forceReplace) {
|
|
|
+ return;
|
|
|
}
|
|
|
- window.removeEventListener('beforeunload', pdfHistoryBeforeUnload);
|
|
|
- }
|
|
|
- window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
|
|
|
- window.addEventListener('pageshow', function pdfHistoryPageShow(evt) {
|
|
|
- window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
|
|
|
- });
|
|
|
- self.eventBus.on('presentationmodechanged', function (e) {
|
|
|
- self.isViewerInPresentationMode = e.active;
|
|
|
- });
|
|
|
- },
|
|
|
- clearHistoryState: function pdfHistory_clearHistoryState() {
|
|
|
- this._pushOrReplaceState(null, true);
|
|
|
- },
|
|
|
- _isStateObjectDefined: function pdfHistory_isStateObjectDefined(state) {
|
|
|
- return state && state.uid >= 0 && state.fingerprint && this.fingerprint === state.fingerprint && state.target && state.target.hash ? true : false;
|
|
|
- },
|
|
|
- _pushOrReplaceState: function pdfHistory_pushOrReplaceState(stateObj, replace) {
|
|
|
- if (replace) {
|
|
|
- window.history.replaceState(stateObj, '', document.URL);
|
|
|
- } else {
|
|
|
- window.history.pushState(stateObj, '', document.URL);
|
|
|
- }
|
|
|
- },
|
|
|
- get isHashChangeUnlocked() {
|
|
|
- if (!this.initialized) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return this.allowHashChange;
|
|
|
- },
|
|
|
- _updatePreviousBookmark: function pdfHistory_updatePreviousBookmark() {
|
|
|
- if (this.updatePreviousBookmark && this.currentBookmark && this.currentPage) {
|
|
|
- this.previousBookmark = this.currentBookmark;
|
|
|
- this.previousPage = this.currentPage;
|
|
|
- this.updatePreviousBookmark = false;
|
|
|
- }
|
|
|
- },
|
|
|
- updateCurrentBookmark: function pdfHistoryUpdateCurrentBookmark(bookmark, pageNum) {
|
|
|
- if (this.initialized) {
|
|
|
- this.currentBookmark = bookmark.substring(1);
|
|
|
- this.currentPage = pageNum | 0;
|
|
|
- this._updatePreviousBookmark();
|
|
|
+ this._pushOrReplaceState({
|
|
|
+ dest: explicitDest,
|
|
|
+ hash: hash,
|
|
|
+ page: pageNumber
|
|
|
+ }, forceReplace);
|
|
|
}
|
|
|
- },
|
|
|
- updateNextHashParam: function pdfHistoryUpdateNextHashParam(param) {
|
|
|
- if (this.initialized) {
|
|
|
- this.nextHashParam = param;
|
|
|
- }
|
|
|
- },
|
|
|
- push: function pdfHistoryPush(params, isInitialBookmark) {
|
|
|
- if (!(this.initialized && this.historyUnlocked)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (params.dest && !params.hash) {
|
|
|
- params.hash = this.current.hash && this.current.dest && this.current.dest === params.dest ? this.current.hash : this.linkService.getDestinationHash(params.dest).split('#')[1];
|
|
|
- }
|
|
|
- if (params.page) {
|
|
|
- params.page |= 0;
|
|
|
+ }, {
|
|
|
+ key: 'pushCurrentPosition',
|
|
|
+ value: function pushCurrentPosition() {
|
|
|
+ if (!this.initialized || this._popStateInProgress) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._tryPushCurrentPosition();
|
|
|
}
|
|
|
- if (isInitialBookmark) {
|
|
|
- var target = window.history.state.target;
|
|
|
- if (!target) {
|
|
|
- this._pushToHistory(params, false);
|
|
|
- this.previousHash = window.location.hash.substring(1);
|
|
|
+ }, {
|
|
|
+ key: 'back',
|
|
|
+ value: function back() {
|
|
|
+ if (!this.initialized || this._popStateInProgress) {
|
|
|
+ return;
|
|
|
}
|
|
|
- this.updatePreviousBookmark = this.nextHashParam ? false : true;
|
|
|
- if (target) {
|
|
|
- this._updatePreviousBookmark();
|
|
|
+ var state = window.history.state;
|
|
|
+ if (this._isValidState(state) && state.uid > 0) {
|
|
|
+ window.history.back();
|
|
|
}
|
|
|
- return;
|
|
|
}
|
|
|
- if (this.nextHashParam) {
|
|
|
- if (this.nextHashParam === params.hash) {
|
|
|
- this.nextHashParam = null;
|
|
|
- this.updatePreviousBookmark = true;
|
|
|
+ }, {
|
|
|
+ key: 'forward',
|
|
|
+ value: function forward() {
|
|
|
+ if (!this.initialized || this._popStateInProgress) {
|
|
|
return;
|
|
|
}
|
|
|
- this.nextHashParam = null;
|
|
|
+ var state = window.history.state;
|
|
|
+ if (this._isValidState(state) && state.uid < this._uid - 1) {
|
|
|
+ window.history.forward();
|
|
|
+ }
|
|
|
}
|
|
|
- if (params.hash) {
|
|
|
- if (this.current.hash) {
|
|
|
- if (this.current.hash !== params.hash) {
|
|
|
- this._pushToHistory(params, true);
|
|
|
- } else {
|
|
|
- if (!this.current.page && params.page) {
|
|
|
- this._pushToHistory(params, false, true);
|
|
|
- }
|
|
|
- this.updatePreviousBookmark = true;
|
|
|
- }
|
|
|
+ }, {
|
|
|
+ key: '_pushOrReplaceState',
|
|
|
+ value: function _pushOrReplaceState(destination) {
|
|
|
+ var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
+
|
|
|
+ var shouldReplace = forceReplace || !this._destination;
|
|
|
+ var newState = {
|
|
|
+ fingerprint: this.fingerprint,
|
|
|
+ uid: shouldReplace ? this._currentUid : this._uid,
|
|
|
+ destination: destination
|
|
|
+ };
|
|
|
+ this._updateInternalState(destination, newState.uid);
|
|
|
+ if (shouldReplace) {
|
|
|
+ window.history.replaceState(newState, '', document.URL);
|
|
|
} else {
|
|
|
- this._pushToHistory(params, true);
|
|
|
+ window.history.pushState(newState, '', document.URL);
|
|
|
}
|
|
|
- } else if (this.current.page && params.page && this.current.page !== params.page) {
|
|
|
- this._pushToHistory(params, true);
|
|
|
- }
|
|
|
- },
|
|
|
- _getPreviousParams: function pdfHistory_getPreviousParams(onlyCheckPage, beforeUnload) {
|
|
|
- if (!(this.currentBookmark && this.currentPage)) {
|
|
|
- return null;
|
|
|
- } else if (this.updatePreviousBookmark) {
|
|
|
- this.updatePreviousBookmark = false;
|
|
|
}
|
|
|
- if (this.uid > 0 && !(this.previousBookmark && this.previousPage)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!this.current.dest && !onlyCheckPage || beforeUnload) {
|
|
|
- if (this.previousBookmark === this.currentBookmark) {
|
|
|
- return null;
|
|
|
+ }, {
|
|
|
+ key: '_tryPushCurrentPosition',
|
|
|
+ value: function _tryPushCurrentPosition() {
|
|
|
+ var temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+
|
|
|
+ if (!this._position) {
|
|
|
+ return;
|
|
|
}
|
|
|
- } else if (this.current.page || onlyCheckPage) {
|
|
|
- if (this.previousPage === this.currentPage) {
|
|
|
- return null;
|
|
|
+ var position = this._position;
|
|
|
+ if (temporary) {
|
|
|
+ position = (0, _ui_utils.cloneObj)(this._position);
|
|
|
+ position.temporary = true;
|
|
|
}
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- var params = {
|
|
|
- hash: this.currentBookmark,
|
|
|
- page: this.currentPage
|
|
|
- };
|
|
|
- if (this.isViewerInPresentationMode) {
|
|
|
- params.hash = null;
|
|
|
- }
|
|
|
- return params;
|
|
|
- },
|
|
|
- _stateObj: function pdfHistory_stateObj(params) {
|
|
|
- return {
|
|
|
- fingerprint: this.fingerprint,
|
|
|
- uid: this.uid,
|
|
|
- target: params
|
|
|
- };
|
|
|
- },
|
|
|
- _pushToHistory: function pdfHistory_pushToHistory(params, addPrevious, overwrite) {
|
|
|
- if (!this.initialized) {
|
|
|
- return;
|
|
|
+ if (!this._destination) {
|
|
|
+ this._pushOrReplaceState(position);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this._destination.temporary) {
|
|
|
+ this._pushOrReplaceState(position, true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this._destination.hash === position.hash) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var forceReplace = false;
|
|
|
+ if (this._destination.page === position.first || this._destination.page === position.page) {
|
|
|
+ if (this._destination.dest || !this._destination.first) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ forceReplace = true;
|
|
|
+ }
|
|
|
+ this._pushOrReplaceState(position, forceReplace);
|
|
|
}
|
|
|
- if (!params.hash && params.page) {
|
|
|
- params.hash = 'page=' + params.page;
|
|
|
+ }, {
|
|
|
+ key: '_isValidState',
|
|
|
+ value: function _isValidState(state) {
|
|
|
+ if (!state) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (state.fingerprint !== this.fingerprint) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!Number.isInteger(state.uid) || state.uid < 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (state.destination === null || _typeof(state.destination) !== 'object') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
- if (addPrevious && !overwrite) {
|
|
|
- var previousParams = this._getPreviousParams();
|
|
|
- if (previousParams) {
|
|
|
- var replacePrevious = !this.current.dest && this.current.hash !== this.previousHash;
|
|
|
- this._pushToHistory(previousParams, false, replacePrevious);
|
|
|
+ }, {
|
|
|
+ key: '_updateInternalState',
|
|
|
+ value: function _updateInternalState(destination, uid) {
|
|
|
+ var removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
|
+
|
|
|
+ if (removeTemporary && destination && destination.temporary) {
|
|
|
+ delete destination.temporary;
|
|
|
}
|
|
|
+ this._destination = destination;
|
|
|
+ this._currentUid = uid;
|
|
|
+ this._uid = this._currentUid + 1;
|
|
|
+ this._numPositionUpdates = 0;
|
|
|
}
|
|
|
- this._pushOrReplaceState(this._stateObj(params), overwrite || this.uid === 0);
|
|
|
- this.currentUid = this.uid++;
|
|
|
- this.current = params;
|
|
|
- this.updatePreviousBookmark = true;
|
|
|
- },
|
|
|
- _goTo: function pdfHistory_goTo(state) {
|
|
|
- if (!(this.initialized && this.historyUnlocked && this._isStateObjectDefined(state))) {
|
|
|
- return;
|
|
|
+ }, {
|
|
|
+ key: '_updateViewarea',
|
|
|
+ value: function _updateViewarea(_ref3) {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
+ var location = _ref3.location;
|
|
|
+
|
|
|
+ if (this._updateViewareaTimeout) {
|
|
|
+ clearTimeout(this._updateViewareaTimeout);
|
|
|
+ this._updateViewareaTimeout = null;
|
|
|
+ }
|
|
|
+ this._position = {
|
|
|
+ hash: this._isViewerInPresentationMode ? 'page=' + location.pageNumber : location.pdfOpenParams.substring(1),
|
|
|
+ page: this.linkService.page,
|
|
|
+ first: location.pageNumber
|
|
|
+ };
|
|
|
+ if (this._popStateInProgress) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
|
|
|
+ this._numPositionUpdates++;
|
|
|
+ }
|
|
|
+ if (UPDATE_VIEWAREA_TIMEOUT > 0) {
|
|
|
+ this._updateViewareaTimeout = setTimeout(function () {
|
|
|
+ if (!_this2._popStateInProgress) {
|
|
|
+ _this2._tryPushCurrentPosition(true);
|
|
|
+ }
|
|
|
+ _this2._updateViewareaTimeout = null;
|
|
|
+ }, UPDATE_VIEWAREA_TIMEOUT);
|
|
|
+ }
|
|
|
}
|
|
|
- if (!this.reInitialized && state.uid < this.currentUid) {
|
|
|
- var previousParams = this._getPreviousParams(true);
|
|
|
- if (previousParams) {
|
|
|
- this._pushToHistory(this.current, false);
|
|
|
- this._pushToHistory(previousParams, false);
|
|
|
- this.currentUid = state.uid;
|
|
|
- window.history.back();
|
|
|
+ }, {
|
|
|
+ key: '_popState',
|
|
|
+ value: function _popState(_ref4) {
|
|
|
+ var _this3 = this;
|
|
|
+
|
|
|
+ var state = _ref4.state;
|
|
|
+
|
|
|
+ var newHash = getCurrentHash(),
|
|
|
+ hashChanged = this._currentHash !== newHash;
|
|
|
+ this._currentHash = newHash;
|
|
|
+ if (!state || false) {
|
|
|
+ this._currentUid = this._uid;
|
|
|
+
|
|
|
+ var _parseCurrentHash2 = parseCurrentHash(this.linkService),
|
|
|
+ hash = _parseCurrentHash2.hash,
|
|
|
+ page = _parseCurrentHash2.page;
|
|
|
+
|
|
|
+ this._pushOrReplaceState({
|
|
|
+ hash: hash,
|
|
|
+ page: page
|
|
|
+ }, true);
|
|
|
return;
|
|
|
}
|
|
|
+ if (!this._isValidState(state)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._popStateInProgress = true;
|
|
|
+ if (hashChanged) {
|
|
|
+ this._blockHashChange++;
|
|
|
+ (0, _ui_utils.waitOnEventOrTimeout)({
|
|
|
+ target: window,
|
|
|
+ name: 'hashchange',
|
|
|
+ delay: HASH_CHANGE_TIMEOUT
|
|
|
+ }).then(function () {
|
|
|
+ _this3._blockHashChange--;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (state.uid < this._currentUid && this._position && this._destination) {
|
|
|
+ var shouldGoBack = false;
|
|
|
+ if (this._destination.temporary) {
|
|
|
+ this._pushOrReplaceState(this._position);
|
|
|
+ shouldGoBack = true;
|
|
|
+ } else if (this._destination.page && this._destination.page !== this._position.first && this._destination.page !== this._position.page) {
|
|
|
+ this._pushOrReplaceState(this._destination);
|
|
|
+ this._pushOrReplaceState(this._position);
|
|
|
+ shouldGoBack = true;
|
|
|
+ }
|
|
|
+ if (shouldGoBack) {
|
|
|
+ this._currentUid = state.uid;
|
|
|
+ window.history.back();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var destination = state.destination;
|
|
|
+ this._updateInternalState(destination, state.uid, true);
|
|
|
+ if (destination.dest) {
|
|
|
+ this.linkService.navigateTo(destination.dest);
|
|
|
+ } else if (destination.hash) {
|
|
|
+ this.linkService.setHash(destination.hash);
|
|
|
+ } else if (destination.page) {
|
|
|
+ this.linkService.page = destination.page;
|
|
|
+ }
|
|
|
+ Promise.resolve().then(function () {
|
|
|
+ _this3._popStateInProgress = false;
|
|
|
+ });
|
|
|
}
|
|
|
- this.historyUnlocked = false;
|
|
|
- if (state.target.dest) {
|
|
|
- this.linkService.navigateTo(state.target.dest);
|
|
|
- } else {
|
|
|
- this.linkService.setHash(state.target.hash);
|
|
|
+ }, {
|
|
|
+ key: '_bindEvents',
|
|
|
+ value: function _bindEvents() {
|
|
|
+ var _this4 = this;
|
|
|
+
|
|
|
+ var _boundEvents = this._boundEvents,
|
|
|
+ eventBus = this.eventBus;
|
|
|
+
|
|
|
+ _boundEvents.updateViewarea = this._updateViewarea.bind(this);
|
|
|
+ _boundEvents.popState = this._popState.bind(this);
|
|
|
+ _boundEvents.pageHide = function (evt) {
|
|
|
+ if (!_this4._destination) {
|
|
|
+ _this4._tryPushCurrentPosition();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ eventBus.on('updateviewarea', _boundEvents.updateViewarea);
|
|
|
+ window.addEventListener('popstate', _boundEvents.popState);
|
|
|
+ window.addEventListener('pagehide', _boundEvents.pageHide);
|
|
|
}
|
|
|
- this.currentUid = state.uid;
|
|
|
- if (state.uid > this.uid) {
|
|
|
- this.uid = state.uid;
|
|
|
+ }, {
|
|
|
+ key: 'popStateInProgress',
|
|
|
+ get: function get() {
|
|
|
+ return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
|
|
|
}
|
|
|
- this.current = state.target;
|
|
|
- this.updatePreviousBookmark = true;
|
|
|
- var currentHash = window.location.hash.substring(1);
|
|
|
- if (this.previousHash !== currentHash) {
|
|
|
- this.allowHashChange = false;
|
|
|
+ }]);
|
|
|
+
|
|
|
+ return PDFHistory;
|
|
|
+}();
|
|
|
+
|
|
|
+function isDestsEqual(firstDest, secondDest) {
|
|
|
+ function isEntryEqual(first, second) {
|
|
|
+ if ((typeof first === 'undefined' ? 'undefined' : _typeof(first)) !== (typeof second === 'undefined' ? 'undefined' : _typeof(second))) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- this.previousHash = currentHash;
|
|
|
- this.historyUnlocked = true;
|
|
|
- },
|
|
|
- back: function pdfHistoryBack() {
|
|
|
- this.go(-1);
|
|
|
- },
|
|
|
- forward: function pdfHistoryForward() {
|
|
|
- this.go(1);
|
|
|
- },
|
|
|
- go: function pdfHistoryGo(direction) {
|
|
|
- if (this.initialized && this.historyUnlocked) {
|
|
|
- var state = window.history.state;
|
|
|
- if (direction === -1 && state && state.uid > 0) {
|
|
|
- window.history.back();
|
|
|
- } else if (direction === 1 && state && state.uid < this.uid - 1) {
|
|
|
- window.history.forward();
|
|
|
+ if (first instanceof Array || second instanceof Array) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (first !== null && (typeof first === 'undefined' ? 'undefined' : _typeof(first)) === 'object' && second !== null) {
|
|
|
+ if (Object.keys(first).length !== Object.keys(second).length) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (var key in first) {
|
|
|
+ if (!isEntryEqual(first[key], second[key])) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
+ return first === second || Number.isNaN(first) && Number.isNaN(second);
|
|
|
}
|
|
|
-};
|
|
|
+ if (!(firstDest instanceof Array && secondDest instanceof Array)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (firstDest.length !== secondDest.length) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (var i = 0, ii = firstDest.length; i < ii; i++) {
|
|
|
+ if (!isEntryEqual(firstDest[i], secondDest[i])) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
exports.PDFHistory = PDFHistory;
|
|
|
+exports.isDestsEqual = isDestsEqual;
|
|
|
|
|
|
/***/ }),
|
|
|
/* 11 */
|