|
@@ -19,14 +19,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
});
|
|
|
exports.PDFPresentationMode = 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 _ui_utils = require('./ui_utils');
|
|
|
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
+
|
|
|
var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
|
|
|
var DELAY_BEFORE_HIDING_CONTROLS = 3000;
|
|
|
var ACTIVE_SELECTOR = 'pdfPresentationMode';
|
|
|
var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
|
|
|
-var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
+var MOUSE_SCROLL_COOLDOWN_TIME = 50;
|
|
|
+var PAGE_SWITCH_THRESHOLD = 0.1;
|
|
|
+var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
|
|
|
+var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
|
|
|
+
|
|
|
+var PDFPresentationMode = function () {
|
|
|
function PDFPresentationMode(options) {
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
+ _classCallCheck(this, PDFPresentationMode);
|
|
|
+
|
|
|
this.container = options.container;
|
|
|
this.viewer = options.viewer || options.container.firstElementChild;
|
|
|
this.pdfViewer = options.pdfViewer;
|
|
@@ -39,26 +52,28 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
this.mouseScrollDelta = 0;
|
|
|
this.touchSwipeState = null;
|
|
|
if (contextMenuItems) {
|
|
|
- contextMenuItems.contextFirstPage.addEventListener('click', function PDFPresentationMode_contextFirstPageClick(e) {
|
|
|
- this.contextMenuOpen = false;
|
|
|
- this.eventBus.dispatch('firstpage');
|
|
|
- }.bind(this));
|
|
|
- contextMenuItems.contextLastPage.addEventListener('click', function PDFPresentationMode_contextLastPageClick(e) {
|
|
|
- this.contextMenuOpen = false;
|
|
|
- this.eventBus.dispatch('lastpage');
|
|
|
- }.bind(this));
|
|
|
- contextMenuItems.contextPageRotateCw.addEventListener('click', function PDFPresentationMode_contextPageRotateCwClick(e) {
|
|
|
- this.contextMenuOpen = false;
|
|
|
- this.eventBus.dispatch('rotatecw');
|
|
|
- }.bind(this));
|
|
|
- contextMenuItems.contextPageRotateCcw.addEventListener('click', function PDFPresentationMode_contextPageRotateCcwClick(e) {
|
|
|
- this.contextMenuOpen = false;
|
|
|
- this.eventBus.dispatch('rotateccw');
|
|
|
- }.bind(this));
|
|
|
+ contextMenuItems.contextFirstPage.addEventListener('click', function () {
|
|
|
+ _this.contextMenuOpen = false;
|
|
|
+ _this.eventBus.dispatch('firstpage');
|
|
|
+ });
|
|
|
+ contextMenuItems.contextLastPage.addEventListener('click', function () {
|
|
|
+ _this.contextMenuOpen = false;
|
|
|
+ _this.eventBus.dispatch('lastpage');
|
|
|
+ });
|
|
|
+ contextMenuItems.contextPageRotateCw.addEventListener('click', function () {
|
|
|
+ _this.contextMenuOpen = false;
|
|
|
+ _this.eventBus.dispatch('rotatecw');
|
|
|
+ });
|
|
|
+ contextMenuItems.contextPageRotateCcw.addEventListener('click', function () {
|
|
|
+ _this.contextMenuOpen = false;
|
|
|
+ _this.eventBus.dispatch('rotateccw');
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
- PDFPresentationMode.prototype = {
|
|
|
- request: function PDFPresentationMode_request() {
|
|
|
+
|
|
|
+ _createClass(PDFPresentationMode, [{
|
|
|
+ key: 'request',
|
|
|
+ value: function request() {
|
|
|
if (this.switchInProgress || this.active || !this.viewer.hasChildNodes()) {
|
|
|
return false;
|
|
|
}
|
|
@@ -81,15 +96,15 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
previousScale: this.pdfViewer.currentScaleValue
|
|
|
};
|
|
|
return true;
|
|
|
- },
|
|
|
- _mouseWheel: function PDFPresentationMode_mouseWheel(evt) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_mouseWheel',
|
|
|
+ value: function _mouseWheel(evt) {
|
|
|
if (!this.active) {
|
|
|
return;
|
|
|
}
|
|
|
evt.preventDefault();
|
|
|
var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
|
|
|
- var MOUSE_SCROLL_COOLDOWN_TIME = 50;
|
|
|
- var PAGE_SWITCH_THRESHOLD = 0.1;
|
|
|
var currentTime = new Date().getTime();
|
|
|
var storedTime = this.mouseScrollTimeStamp;
|
|
|
if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
|
|
@@ -107,82 +122,101 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
this.mouseScrollTimeStamp = currentTime;
|
|
|
}
|
|
|
}
|
|
|
- },
|
|
|
- get isFullscreen() {
|
|
|
- return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
|
|
|
- },
|
|
|
- _goToPreviousPage: function PDFPresentationMode_goToPreviousPage() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_goToPreviousPage',
|
|
|
+ value: function _goToPreviousPage() {
|
|
|
var page = this.pdfViewer.currentPageNumber;
|
|
|
if (page <= 1) {
|
|
|
return false;
|
|
|
}
|
|
|
this.pdfViewer.currentPageNumber = page - 1;
|
|
|
return true;
|
|
|
- },
|
|
|
- _goToNextPage: function PDFPresentationMode_goToNextPage() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_goToNextPage',
|
|
|
+ value: function _goToNextPage() {
|
|
|
var page = this.pdfViewer.currentPageNumber;
|
|
|
if (page >= this.pdfViewer.pagesCount) {
|
|
|
return false;
|
|
|
}
|
|
|
this.pdfViewer.currentPageNumber = page + 1;
|
|
|
return true;
|
|
|
- },
|
|
|
- _notifyStateChange: function PDFPresentationMode_notifyStateChange() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_notifyStateChange',
|
|
|
+ value: function _notifyStateChange() {
|
|
|
this.eventBus.dispatch('presentationmodechanged', {
|
|
|
source: this,
|
|
|
active: this.active,
|
|
|
switchInProgress: !!this.switchInProgress
|
|
|
});
|
|
|
- },
|
|
|
- _setSwitchInProgress: function PDFPresentationMode_setSwitchInProgress() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_setSwitchInProgress',
|
|
|
+ value: function _setSwitchInProgress() {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
if (this.switchInProgress) {
|
|
|
clearTimeout(this.switchInProgress);
|
|
|
}
|
|
|
- this.switchInProgress = setTimeout(function switchInProgressTimeout() {
|
|
|
- this._removeFullscreenChangeListeners();
|
|
|
- delete this.switchInProgress;
|
|
|
- this._notifyStateChange();
|
|
|
- }.bind(this), DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
|
|
|
- },
|
|
|
- _resetSwitchInProgress: function PDFPresentationMode_resetSwitchInProgress() {
|
|
|
+ this.switchInProgress = setTimeout(function () {
|
|
|
+ _this2._removeFullscreenChangeListeners();
|
|
|
+ delete _this2.switchInProgress;
|
|
|
+ _this2._notifyStateChange();
|
|
|
+ }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_resetSwitchInProgress',
|
|
|
+ value: function _resetSwitchInProgress() {
|
|
|
if (this.switchInProgress) {
|
|
|
clearTimeout(this.switchInProgress);
|
|
|
delete this.switchInProgress;
|
|
|
}
|
|
|
- },
|
|
|
- _enter: function PDFPresentationMode_enter() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_enter',
|
|
|
+ value: function _enter() {
|
|
|
+ var _this3 = this;
|
|
|
+
|
|
|
this.active = true;
|
|
|
this._resetSwitchInProgress();
|
|
|
this._notifyStateChange();
|
|
|
this.container.classList.add(ACTIVE_SELECTOR);
|
|
|
- setTimeout(function enterPresentationModeTimeout() {
|
|
|
- this.pdfViewer.currentPageNumber = this.args.page;
|
|
|
- this.pdfViewer.currentScaleValue = 'page-fit';
|
|
|
- }.bind(this), 0);
|
|
|
+ setTimeout(function () {
|
|
|
+ _this3.pdfViewer.currentPageNumber = _this3.args.page;
|
|
|
+ _this3.pdfViewer.currentScaleValue = 'page-fit';
|
|
|
+ }, 0);
|
|
|
this._addWindowListeners();
|
|
|
this._showControls();
|
|
|
this.contextMenuOpen = false;
|
|
|
this.container.setAttribute('contextmenu', 'viewerContextMenu');
|
|
|
window.getSelection().removeAllRanges();
|
|
|
- },
|
|
|
- _exit: function PDFPresentationMode_exit() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_exit',
|
|
|
+ value: function _exit() {
|
|
|
+ var _this4 = this;
|
|
|
+
|
|
|
var page = this.pdfViewer.currentPageNumber;
|
|
|
this.container.classList.remove(ACTIVE_SELECTOR);
|
|
|
- setTimeout(function exitPresentationModeTimeout() {
|
|
|
- this.active = false;
|
|
|
- this._removeFullscreenChangeListeners();
|
|
|
- this._notifyStateChange();
|
|
|
- this.pdfViewer.currentScaleValue = this.args.previousScale;
|
|
|
- this.pdfViewer.currentPageNumber = page;
|
|
|
- this.args = null;
|
|
|
- }.bind(this), 0);
|
|
|
+ setTimeout(function () {
|
|
|
+ _this4.active = false;
|
|
|
+ _this4._removeFullscreenChangeListeners();
|
|
|
+ _this4._notifyStateChange();
|
|
|
+ _this4.pdfViewer.currentScaleValue = _this4.args.previousScale;
|
|
|
+ _this4.pdfViewer.currentPageNumber = page;
|
|
|
+ _this4.args = null;
|
|
|
+ }, 0);
|
|
|
this._removeWindowListeners();
|
|
|
this._hideControls();
|
|
|
this._resetMouseScrollState();
|
|
|
this.container.removeAttribute('contextmenu');
|
|
|
this.contextMenuOpen = false;
|
|
|
- },
|
|
|
- _mouseDown: function PDFPresentationMode_mouseDown(evt) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_mouseDown',
|
|
|
+ value: function _mouseDown(evt) {
|
|
|
if (this.contextMenuOpen) {
|
|
|
this.contextMenuOpen = false;
|
|
|
evt.preventDefault();
|
|
@@ -195,39 +229,49 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
this.pdfViewer.currentPageNumber += evt.shiftKey ? -1 : 1;
|
|
|
}
|
|
|
}
|
|
|
- },
|
|
|
- _contextMenu: function PDFPresentationMode_contextMenu() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_contextMenu',
|
|
|
+ value: function _contextMenu() {
|
|
|
this.contextMenuOpen = true;
|
|
|
- },
|
|
|
- _showControls: function PDFPresentationMode_showControls() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_showControls',
|
|
|
+ value: function _showControls() {
|
|
|
+ var _this5 = this;
|
|
|
+
|
|
|
if (this.controlsTimeout) {
|
|
|
clearTimeout(this.controlsTimeout);
|
|
|
} else {
|
|
|
this.container.classList.add(CONTROLS_SELECTOR);
|
|
|
}
|
|
|
- this.controlsTimeout = setTimeout(function showControlsTimeout() {
|
|
|
- this.container.classList.remove(CONTROLS_SELECTOR);
|
|
|
- delete this.controlsTimeout;
|
|
|
- }.bind(this), DELAY_BEFORE_HIDING_CONTROLS);
|
|
|
- },
|
|
|
- _hideControls: function PDFPresentationMode_hideControls() {
|
|
|
+ this.controlsTimeout = setTimeout(function () {
|
|
|
+ _this5.container.classList.remove(CONTROLS_SELECTOR);
|
|
|
+ delete _this5.controlsTimeout;
|
|
|
+ }, DELAY_BEFORE_HIDING_CONTROLS);
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_hideControls',
|
|
|
+ value: function _hideControls() {
|
|
|
if (!this.controlsTimeout) {
|
|
|
return;
|
|
|
}
|
|
|
clearTimeout(this.controlsTimeout);
|
|
|
this.container.classList.remove(CONTROLS_SELECTOR);
|
|
|
delete this.controlsTimeout;
|
|
|
- },
|
|
|
- _resetMouseScrollState: function PDFPresentationMode_resetMouseScrollState() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_resetMouseScrollState',
|
|
|
+ value: function _resetMouseScrollState() {
|
|
|
this.mouseScrollTimeStamp = 0;
|
|
|
this.mouseScrollDelta = 0;
|
|
|
- },
|
|
|
- _touchSwipe: function PDFPresentationMode_touchSwipe(evt) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_touchSwipe',
|
|
|
+ value: function _touchSwipe(evt) {
|
|
|
if (!this.active) {
|
|
|
return;
|
|
|
}
|
|
|
- var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
|
|
|
- var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
|
|
|
if (evt.touches.length > 1) {
|
|
|
this.touchSwipeState = null;
|
|
|
return;
|
|
@@ -269,8 +313,10 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- },
|
|
|
- _addWindowListeners: function PDFPresentationMode_addWindowListeners() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_addWindowListeners',
|
|
|
+ value: function _addWindowListeners() {
|
|
|
this.showControlsBind = this._showControls.bind(this);
|
|
|
this.mouseDownBind = this._mouseDown.bind(this);
|
|
|
this.mouseWheelBind = this._mouseWheel.bind(this);
|
|
@@ -285,8 +331,10 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
window.addEventListener('touchstart', this.touchSwipeBind);
|
|
|
window.addEventListener('touchmove', this.touchSwipeBind);
|
|
|
window.addEventListener('touchend', this.touchSwipeBind);
|
|
|
- },
|
|
|
- _removeWindowListeners: function PDFPresentationMode_removeWindowListeners() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_removeWindowListeners',
|
|
|
+ value: function _removeWindowListeners() {
|
|
|
window.removeEventListener('mousemove', this.showControlsBind);
|
|
|
window.removeEventListener('mousedown', this.mouseDownBind);
|
|
|
window.removeEventListener('wheel', this.mouseWheelBind);
|
|
@@ -301,29 +349,42 @@ var PDFPresentationMode = function PDFPresentationModeClosure() {
|
|
|
delete this.resetMouseScrollStateBind;
|
|
|
delete this.contextMenuBind;
|
|
|
delete this.touchSwipeBind;
|
|
|
- },
|
|
|
- _fullscreenChange: function PDFPresentationMode_fullscreenChange() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_fullscreenChange',
|
|
|
+ value: function _fullscreenChange() {
|
|
|
if (this.isFullscreen) {
|
|
|
this._enter();
|
|
|
} else {
|
|
|
this._exit();
|
|
|
}
|
|
|
- },
|
|
|
- _addFullscreenChangeListeners: function PDFPresentationMode_addFullscreenChangeListeners() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_addFullscreenChangeListeners',
|
|
|
+ value: function _addFullscreenChangeListeners() {
|
|
|
this.fullscreenChangeBind = this._fullscreenChange.bind(this);
|
|
|
window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
|
|
|
window.addEventListener('mozfullscreenchange', this.fullscreenChangeBind);
|
|
|
window.addEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
|
|
|
window.addEventListener('MSFullscreenChange', this.fullscreenChangeBind);
|
|
|
- },
|
|
|
- _removeFullscreenChangeListeners: function PDFPresentationMode_removeFullscreenChangeListeners() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_removeFullscreenChangeListeners',
|
|
|
+ value: function _removeFullscreenChangeListeners() {
|
|
|
window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
|
|
|
window.removeEventListener('mozfullscreenchange', this.fullscreenChangeBind);
|
|
|
window.removeEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
|
|
|
window.removeEventListener('MSFullscreenChange', this.fullscreenChangeBind);
|
|
|
delete this.fullscreenChangeBind;
|
|
|
}
|
|
|
- };
|
|
|
+ }, {
|
|
|
+ key: 'isFullscreen',
|
|
|
+ get: function get() {
|
|
|
+ return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
return PDFPresentationMode;
|
|
|
}();
|
|
|
+
|
|
|
exports.PDFPresentationMode = PDFPresentationMode;
|