aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--beamer/viewer/presentation.js17
-rw-r--r--beamer/viewer/screen/screen.js14
-rw-r--r--beamer/viewer/stage/actions.js28
-rw-r--r--beamer/viewer/stage/stage.js29
-rw-r--r--beamer/viewer/viewer.js29
5 files changed, 49 insertions, 68 deletions
diff --git a/beamer/viewer/presentation.js b/beamer/viewer/presentation.js
index fd03288..753027b 100644
--- a/beamer/viewer/presentation.js
+++ b/beamer/viewer/presentation.js
@@ -30,11 +30,11 @@ class Presentation {
30 } 30 }
31 31
32 _setupStage() { 32 _setupStage() {
33 const self = this; 33 return new Stage(
34 const onStageReadyCallback = function() { self._onStageReady(); }; 34 () => this._onStageReady(),
35 const onNextCallback = function() { self._onNext(); }; 35 () => this._onNext(),
36 const onPreviousCallback = function() { self._onPrevious(); }; 36 () => this._onPrevious(),
37 return new Stage(onStageReadyCallback, onNextCallback, onPreviousCallback); 37 );
38 } 38 }
39 39
40 _onStageReady() { 40 _onStageReady() {
@@ -52,10 +52,9 @@ class Presentation {
52 } 52 }
53 53
54 _setPage(pageIndex) { 54 _setPage(pageIndex) {
55 const self = this;
56 this.currentPageIndex = pageIndex; 55 this.currentPageIndex = pageIndex;
57 this.pdf.getPage(this.currentPageIndex).then(function(page) { 56 this.pdf
58 self.stage.setPage(page); 57 .getPage(this.currentPageIndex)
59 }) 58 .then(page => this.stage.setPage(page))
60 } 59 }
61} 60}
diff --git a/beamer/viewer/screen/screen.js b/beamer/viewer/screen/screen.js
index c65ebc3..7cfc54b 100644
--- a/beamer/viewer/screen/screen.js
+++ b/beamer/viewer/screen/screen.js
@@ -1,6 +1,6 @@
1/* 1/*
2 * Beamer Viewer, a web-based PDF presentation viewer 2 * Beamer Viewer, a web-based PDF presentation viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD 3 * Copyright (C) 2018-2023 Pacien TRAN-GIRARD
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU Affero General Public License as
@@ -42,10 +42,7 @@ class Screen {
42 } 42 }
43 43
44 _registerListeners() { 44 _registerListeners() {
45 const self = this; 45 this.window.addEventListener("resize", () => this._repaint());
46 this.window.addEventListener("resize", function() {
47 self._repaint();
48 });
49 } 46 }
50 47
51 _hideWelcomeScreen() { 48 _hideWelcomeScreen() {
@@ -91,10 +88,9 @@ class Screen {
91 viewport: this.page.getViewport(scaleFactor) 88 viewport: this.page.getViewport(scaleFactor)
92 }; 89 };
93 90
94 const self = this; 91 this.page
95 this.page.render(renderContext).then(function() { 92 .render(renderContext)
96 self._showCanvas(canvas); 93 .then(() => this._showCanvas(canvas));
97 });
98 } 94 }
99 95
100 _repaint() { 96 _repaint() {
diff --git a/beamer/viewer/stage/actions.js b/beamer/viewer/stage/actions.js
index 30634ae..47eda60 100644
--- a/beamer/viewer/stage/actions.js
+++ b/beamer/viewer/stage/actions.js
@@ -1,6 +1,6 @@
1/* 1/*
2 * Beamer Viewer, a web-based PDF presentation viewer 2 * Beamer Viewer, a web-based PDF presentation viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD 3 * Copyright (C) 2018-2023 Pacien TRAN-GIRARD
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU Affero General Public License as
@@ -27,10 +27,7 @@ class ActionEventHandler {
27 27
28class KeyboardEventHandler extends ActionEventHandler { 28class KeyboardEventHandler extends ActionEventHandler {
29 register(window) { 29 register(window) {
30 const self = this; 30 window.addEventListener("keydown", event => this._onCommand(event));
31 window.addEventListener("keydown", function(event) {
32 self._onCommand(event);
33 })
34 } 31 }
35 32
36 _onCommand(keyboardEvent) { 33 _onCommand(keyboardEvent) {
@@ -52,10 +49,7 @@ class KeyboardEventHandler extends ActionEventHandler {
52 49
53class MouseClickEventHandler extends ActionEventHandler { 50class MouseClickEventHandler extends ActionEventHandler {
54 register(window) { 51 register(window) {
55 const self = this; 52 window.addEventListener("click", event => this._onCommand(event));
56 window.addEventListener("click", function(event) {
57 self._onCommand(event);
58 })
59 } 53 }
60 54
61 _onCommand(mouseEvent) { 55 _onCommand(mouseEvent) {
@@ -71,24 +65,22 @@ class TouchSwipeEventHandler extends ActionEventHandler {
71 } 65 }
72 66
73 register(window) { 67 register(window) {
74 const self = this; 68 window.addEventListener("touchstart", event => {
75
76 window.addEventListener("touchstart", function(event) {
77 event.preventDefault(); 69 event.preventDefault();
78 self._onTouchStart(event); 70 this._onTouchStart(event);
79 }); 71 });
80 72
81 window.addEventListener("touchmove", function(event) { 73 window.addEventListener("touchmove", event => {
82 event.preventDefault(); 74 event.preventDefault();
83 self._onTouchMove(event); 75 this._onTouchMove(event);
84 }); 76 });
85 77
86 window.addEventListener("touchend", function(event) { 78 window.addEventListener("touchend", event => {
87 event.preventDefault(); 79 event.preventDefault();
88 self._onTouchEnd(); 80 this._onTouchEnd();
89 }); 81 });
90 82
91 window.addEventListener("touchcancel", function(event) { 83 window.addEventListener("touchcancel", event => {
92 event.preventDefault(); 84 event.preventDefault();
93 }); 85 });
94 } 86 }
diff --git a/beamer/viewer/stage/stage.js b/beamer/viewer/stage/stage.js
index 3f1a5f5..4882c31 100644
--- a/beamer/viewer/stage/stage.js
+++ b/beamer/viewer/stage/stage.js
@@ -36,12 +36,11 @@ class Stage {
36 if (this.projector == null) 36 if (this.projector == null)
37 alert("Please allow pop-ups, then refresh this page."); 37 alert("Please allow pop-ups, then refresh this page.");
38 38
39 const self = this; 39 this.projector.addEventListener("load", () => {
40 this.projector.addEventListener("load", function() { 40 this.audienceScreen = new Screen(this.projector, false, false);
41 self.audienceScreen = new Screen(self.projector, false, false); 41 this.presenterScreen = new Screen(window, true, true);
42 self.presenterScreen = new Screen(window, true, true); 42 this._watchDetach();
43 self._watchDetach(); 43 this.onReady();
44 self.onReady();
45 }); 44 });
46 45
47 this._registerEventHandler(window); 46 this._registerEventHandler(window);
@@ -56,20 +55,18 @@ class Stage {
56 _registerEventHandler(window) { 55 _registerEventHandler(window) {
57 if (window == null) return; 56 if (window == null) return;
58 57
59 this.eventHandlers.forEach(function(eventHandler) { 58 this.eventHandlers
60 eventHandler.register(window); 59 .forEach(eventHandler => eventHandler.register(window));
61 });
62 } 60 }
63 61
64 _watchDetach() { 62 _watchDetach() {
65 const self = this; 63 window.addEventListener("beforeunload", () =>
66 window.addEventListener("beforeunload", function() { 64 this._setMessage(this.projector, "Controller detached")
67 self._setMessage(self.projector, "Controller detached"); 65 );
68 });
69 66
70 this.projector.addEventListener("beforeunload", function() { 67 this.projector.addEventListener("beforeunload", () =>
71 self._setMessage(window, "Viewer detached"); 68 this._setMessage(window, "Viewer detached")
72 }); 69 );
73 } 70 }
74 71
75 _setMessage(window, message) { 72 _setMessage(window, message) {
diff --git a/beamer/viewer/viewer.js b/beamer/viewer/viewer.js
index d8d7668..a10e6de 100644
--- a/beamer/viewer/viewer.js
+++ b/beamer/viewer/viewer.js
@@ -35,10 +35,9 @@ class Viewer {
35 } 35 }
36 36
37 _preparePresentation(source) { 37 _preparePresentation(source) {
38 const self = this; 38 pdfjsLib.getDocument(source).then(pdf => {
39 pdfjsLib.getDocument(source).then(function(pdf) { 39 this.presentation = new Presentation(pdf);
40 self.presentation = new Presentation(pdf); 40 }).catch(error => {
41 }).catch(function(error) {
42 console.error(error); 41 console.error(error);
43 window.alert("Error while loading presentation:\n\n" + error.message); 42 window.alert("Error while loading presentation:\n\n" + error.message);
44 window.location.href = window.location.pathname; // reload without "?file=..." 43 window.location.href = window.location.pathname; // reload without "?file=..."
@@ -46,9 +45,8 @@ class Viewer {
46 } 45 }
47 46
48 _readFile(file) { 47 _readFile(file) {
49 const self = this; 48 this.fileReader.onload = () => {
50 this.fileReader.onload = function() { 49 this._setPresentation(new Uint8Array(this.result));
51 self._setPresentation(new Uint8Array(this.result));