1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* stage.js
* Part of Pointless Viewer, a Beamer presentation viewer
* Copyright 2018 Pacien TRAN-GIRARD
* License: GNU GPL v3
*/
"use strict";
class Stage {
constructor(onReady, onNext, onPrevious) {
this.onNext = onNext;
this.onPrevious = onPrevious;
this.projector = window.open(window.location.href);
this.audienceScreen = null;
this.presenterScreen = null;
this._setMessage(window, "Please allow pop-ups on this page");
var self = this;
this.projector.addEventListener("load", function() {
self.audienceScreen = new Screen(self.projector, false, false);
self.presenterScreen = new Screen(window, true, true);
self._setMessage(window, null);
self._watchDetach();
onReady();
});
this._registerEventHandler(window);
this._registerEventHandler(this.projector);
}
setPage(page) {
this.audienceScreen.setPage(page);
this.presenterScreen.setPage(page);
}
_registerEventHandler(window) {
var self = this;
window.addEventListener("keydown", function(event) {
self._onCommand(event);
})
}
_onCommand(keyboardEvent) {
switch (keyboardEvent.key) {
case "Enter":
case " ":
case "ArrowRight":
case "n":
return this.onNext();
case "ArrowLeft":
case "p":
return this.onPrevious();
}
}
_watchDetach() {
var self = this;
window.addEventListener("beforeunload", function() {
self._setMessage(self.projector, "Controller detached");
});
this.projector.addEventListener("beforeunload", function() {
self._setMessage(window, "Viewer detached");
});
}
_setMessage(window, message) {
var messageBar = window.document.getElementById("message");
messageBar.textContent = message;
}
}
|