aboutsummaryrefslogtreecommitdiff
path: root/beamer/viewer/presentation.js
diff options
context:
space:
mode:
Diffstat (limited to 'beamer/viewer/presentation.js')
-rw-r--r--beamer/viewer/presentation.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/beamer/viewer/presentation.js b/beamer/viewer/presentation.js
new file mode 100644
index 0000000..222a6d4
--- /dev/null
+++ b/beamer/viewer/presentation.js
@@ -0,0 +1,57 @@
1/*
2 * Beamer Viewer, a web-based PDF presentation viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19"use strict";
20
21class Presentation {
22 constructor(pdf) {
23 this.pdf = pdf;
24 this.currentPageIndex = 1;
25 this.stage = this._setupStage();
26 }
27
28 _setupStage() {
29 const self = this;
30 const onStageReadyCallback = function() { self._onStageReady(); };
31 const onNextCallback = function() { self._onNext(); };
32 const onPreviousCallback = function() { self._onPrevious(); };
33 return new Stage(onStageReadyCallback, onNextCallback, onPreviousCallback);
34 }
35
36 _onStageReady() {
37 this._setPage(this.currentPageIndex);
38 }
39
40 _onNext() {
41 if (this.currentPageIndex === this.pdf.numPages) return;
42 this._setPage(this.currentPageIndex + 1);
43 }
44
45 _onPrevious() {
46 if (this.currentPageIndex === 1) return;
47 this._setPage(this.currentPageIndex - 1);
48 }
49
50 _setPage(pageIndex) {
51 const self = this;
52 this.currentPageIndex = pageIndex;
53 this.pdf.getPage(this.currentPageIndex).then(function(page) {
54 self.stage.setPage(page);
55 })
56 }
57}