From 3af33091d66197d2b14ab0ed7962d79b3a17d6e1 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 23 Oct 2023 21:58:06 +0200 Subject: presentation,stage: split object init and start --- beamer/viewer/presentation.js | 4 ++++ beamer/viewer/stage/stage.js | 17 ++++++++++------- beamer/viewer/viewer.js | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/beamer/viewer/presentation.js b/beamer/viewer/presentation.js index 222a6d4..8934dda 100644 --- a/beamer/viewer/presentation.js +++ b/beamer/viewer/presentation.js @@ -25,6 +25,10 @@ class Presentation { this.stage = this._setupStage(); } + start() { + this.stage.start(); + } + _setupStage() { const self = this; const onStageReadyCallback = function() { self._onStageReady(); }; diff --git a/beamer/viewer/stage/stage.js b/beamer/viewer/stage/stage.js index 201f7b4..cb94231 100644 --- a/beamer/viewer/stage/stage.js +++ b/beamer/viewer/stage/stage.js @@ -23,6 +23,15 @@ class Stage { this.audienceScreen = null; this.presenterScreen = null; + this.onReady = onReady; + this.eventHandlers = [ + new KeyboardEventHandler(onNext, onPrevious), + new MouseClickEventHandler(onNext, onPrevious), + new TouchSwipeEventHandler(onNext, onPrevious) + ]; + } + + start() { this.projector = window.open(window.location.href, "_blank", "toolbar=0,location=0,menubar=0"); if (this.projector == null) alert("Please allow pop-ups, then refresh this page."); @@ -32,15 +41,9 @@ class Stage { self.audienceScreen = new Screen(self.projector, false, false); self.presenterScreen = new Screen(window, true, true); self._watchDetach(); - onReady(); + self.onReady(); }); - this.eventHandlers = [ - new KeyboardEventHandler(onNext, onPrevious), - new MouseClickEventHandler(onNext, onPrevious), - new TouchSwipeEventHandler(onNext, onPrevious) - ]; - this._registerEventHandler(window); this._registerEventHandler(this.projector); } diff --git a/beamer/viewer/viewer.js b/beamer/viewer/viewer.js index 065298a..ee79d47 100644 --- a/beamer/viewer/viewer.js +++ b/beamer/viewer/viewer.js @@ -29,6 +29,7 @@ class Viewer { load(source) { pdfjsLib.getDocument(source).then(function(pdf) { const presentation = new Presentation(pdf); + presentation.start(); }).catch(function(error) { console.error(error); window.alert("Error while loading presentation:\n\n" + error.message); -- cgit v1.2.3