aboutsummaryrefslogtreecommitdiff
path: root/beamer/viewer/stage
diff options
context:
space:
mode:
Diffstat (limited to 'beamer/viewer/stage')
-rw-r--r--beamer/viewer/stage/actions.js46
-rw-r--r--beamer/viewer/stage/stage.js60
2 files changed, 39 insertions, 67 deletions
diff --git a/beamer/viewer/stage/actions.js b/beamer/viewer/stage/actions.js
index 601a441..818e970 100644
--- a/beamer/viewer/stage/actions.js
+++ b/beamer/viewer/stage/actions.js
@@ -1,19 +1,7 @@
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 2018-2024 Pacien TRAN-GIRARD
4 * 4 * SPDX-License-Identifier: EUPL-1.2
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 */ 5 */
18 6
19"use strict"; 7"use strict";
@@ -27,10 +15,7 @@ class ActionEventHandler {
27 15
28class KeyboardEventHandler extends ActionEventHandler { 16class KeyboardEventHandler extends ActionEventHandler {
29 register(window) { 17 register(window) {
30 const self = this; 18 window.addEventListener("keydown", event => this._onCommand(event));
31 window.addEventListener("keydown", function(event) {
32 self._onCommand(event);
33 })
34 } 19 }
35 20
36 _onCommand(keyboardEvent) { 21 _onCommand(keyboardEvent) {
@@ -38,10 +23,14 @@ class KeyboardEventHandler extends ActionEventHandler {
38 case "Enter": 23 case "Enter":
39 case " ": 24 case " ":
40 case "ArrowRight": 25 case "ArrowRight":
26 case "ArrowDown":
27 case "PageDown":
41 case "n": 28 case "n":
42 return this.onNext(); 29 return this.onNext();
43 30
44 case "ArrowLeft": 31 case "ArrowLeft":
32 case "ArrowUp":
33 case "PageUp":
45 case "p": 34 case "p":
46 return this.onPrevious(); 35 return this.onPrevious();
47 } 36 }
@@ -50,10 +39,7 @@ class KeyboardEventHandler extends ActionEventHandler {
50 39
51class MouseClickEventHandler extends ActionEventHandler { 40class MouseClickEventHandler extends ActionEventHandler {
52 register(window) { 41 register(window) {
53 const self = this; 42 window.addEventListener("click", event => this._onCommand(event));
54 window.addEventListener("click", function(event) {
55 self._onCommand(event);
56 })
57 } 43 }
58 44
59 _onCommand(mouseEvent) { 45 _onCommand(mouseEvent) {
@@ -69,24 +55,22 @@ class TouchSwipeEventHandler extends ActionEventHandler {
69 } 55 }
70 56
71 register(window) { 57 register(window) {
72 const self = this; 58 window.addEventListener("touchstart", event => {
73
74 window.addEventListener("touchstart", function(event) {
75 event.preventDefault(); 59 event.preventDefault();
76 self._onTouchStart(event); 60 this._onTouchStart(event);
77 }); 61 });
78 62
79 window.addEventListener("touchmove", function(event) { 63 window.addEventListener("touchmove", event => {
80 event.preventDefault(); 64 event.preventDefault();
81 self._onTouchMove(event); 65 this._onTouchMove(event);
82 }); 66 });
83 67
84 window.addEventListener("touchend", function(event) { 68 window.addEventListener("touchend", event => {
85 event.preventDefault(); 69 event.preventDefault();
86 self._onTouchEnd(); 70 this._onTouchEnd();
87 }); 71 });
88 72
89 window.addEventListener("touchcancel", function(event) { 73 window.addEventListener("touchcancel", event => {
90 event.preventDefault(); 74 event.preventDefault();
91 }); 75 });
92 } 76 }
diff --git a/beamer/viewer/stage/stage.js b/beamer/viewer/stage/stage.js
index 201f7b4..763f3b2 100644
--- a/beamer/viewer/stage/stage.js
+++ b/beamer/viewer/stage/stage.js
@@ -1,19 +1,7 @@
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 2018-2024 Pacien TRAN-GIRARD
4 * 4 * SPDX-License-Identifier: EUPL-1.2
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 */ 5 */
18 6
19"use strict"; 7"use strict";
@@ -23,23 +11,25 @@ class Stage {
23 this.audienceScreen = null; 11 this.audienceScreen = null;
24 this.presenterScreen = null; 12 this.presenterScreen = null;
25 13
26 this.projector = window.open(window.location.href, "_blank", "toolbar=0,location=0,menubar=0"); 14 this.onReady = onReady;
27 if (this.projector == null)
28 alert("Please allow pop-ups, then refresh this page.");
29
30 const self = this;
31 this.projector.addEventListener("load", function() {
32 self.audienceScreen = new Screen(self.projector, false, false);
33 self.presenterScreen = new Screen(window, true, true);
34 self._watchDetach();
35 onReady();
36 });
37
38 this.eventHandlers = [ 15 this.eventHandlers = [
39 new KeyboardEventHandler(onNext, onPrevious), 16 new KeyboardEventHandler(onNext, onPrevious),
40 new MouseClickEventHandler(onNext, onPrevious), 17 new MouseClickEventHandler(onNext, onPrevious),
41 new TouchSwipeEventHandler(onNext, onPrevious) 18 new TouchSwipeEventHandler(onNext, onPrevious)
42 ]; 19 ];
20 }
21
22 start() {
23 this.projector = window.open(window.location.href, "_blank", "toolbar=0,location=0,menubar=0");
24 if (this.projector == null)
25 alert("Please allow pop-ups, then refresh this page.");
26
27 this.projector.addEventListener("load", () => {
28 this.audienceScreen = new Screen(this.projector, false, false);
29 this.presenterScreen = new Screen(window, true, true);
30 this._watchDetach();
31 this.onReady();
32 });
43 33
44 this._registerEventHandler(window); 34 this._registerEventHandler(window);
45 this._registerEventHandler(this.projector); 35 this._registerEventHandler(this.projector);
@@ -53,20 +43,18 @@ class Stage {
53 _registerEventHandler(window) { 43 _registerEventHandler(window) {
54 if (window == null) return; 44 if (window == null) return;
55 45
56 this.eventHandlers.forEach(function(eventHandler) { 46 this.eventHandlers
57 eventHandler.register(window); 47 .forEach(eventHandler => eventHandler.register(window));
58 });
59 } 48 }
60 49
61 _watchDetach() { 50 _watchDetach() {
62 const self = this; 51 window.addEventListener("beforeunload", () =>
63 window.addEventListener("beforeunload", function() { 52 this._setMessage(this.projector, "Controller detached")
64 self._setMessage(self.projector, "Controller detached"); 53 );
65 });
66 54
67 this.projector.addEventListener("beforeunload", function() { 55 this.projector.addEventListener("beforeunload", () =>
68 self._setMessage(window, "Viewer detached"); 56 this._setMessage(window, "Viewer detached")
69 }); 57 );
70 } 58 }
71 59
72 _setMessage(window, message) { 60 _setMessage(window, message) {