aboutsummaryrefslogtreecommitdiff
path: root/beamer/viewer/viewer.js
diff options
context:
space:
mode:
Diffstat (limited to 'beamer/viewer/viewer.js')
-rw-r--r--beamer/viewer/viewer.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/beamer/viewer/viewer.js b/beamer/viewer/viewer.js
index ee79d47..85f4a91 100644
--- a/beamer/viewer/viewer.js
+++ b/beamer/viewer/viewer.js
@@ -23,13 +23,16 @@ class Viewer {
23 this.fileInput = document.getElementById("fileInput"); 23 this.fileInput = document.getElementById("fileInput");
24 this.startButton = document.getElementById("startButton"); 24 this.startButton = document.getElementById("startButton");
25 25
26 this.fileReader = new FileReader();
27 this.presentation = null;
28
26 this._listenForInput(); 29 this._listenForInput();
27 } 30 }
28 31
29 load(source) { 32 load(source) {
33 const self = this;
30 pdfjsLib.getDocument(source).then(function(pdf) { 34 pdfjsLib.getDocument(source).then(function(pdf) {
31 const presentation = new Presentation(pdf); 35 self.presentation = new Presentation(pdf);
32 presentation.start();
33 }).catch(function(error) { 36 }).catch(function(error) {
34 console.error(error); 37 console.error(error);
35 window.alert("Error while loading presentation:\n\n" + error.message); 38 window.alert("Error while loading presentation:\n\n" + error.message);
@@ -38,24 +41,30 @@ class Viewer {
38 } 41 }
39 42
40 _readFile(file) { 43 _readFile(file) {
41 const fileReader = new FileReader();
42 const self = this; 44 const self = this;
43 fileReader.onload = function() { 45 this.fileReader.onload = function() {
44 const byteArray = new Uint8Array(this.result); 46 self._onFileLoaded(new Uint8Array(this.result));
45 self.load(byteArray);
46 } 47 }
47 48
48 fileReader.readAsArrayBuffer(file); 49 this.fileReader.abort();
50 this.fileReader.readAsArrayBuffer(file);
51 }
52
53 _onFileLoaded(bytes) {
54 this.load(bytes);
55 this.startButton.disabled = false;
49 } 56 }
50 57
51 _listenForInput() { 58 _listenForInput() {
52 const self = this; 59 const self = this;
53 fileInput.addEventListener("change", function(_event) { 60 fileInput.addEventListener("change", function(event) {
54 self.startButton.disabled = false; 61 self._readFile(event.target.files[0]);
55 }); 62 });
56 63
57 startButton.addEventListener("click", function(_event) { 64 startButton.addEventListener("click", function(event) {
58 self._readFile(self.fileInput.files[0]); 65 event.preventDefault();
66 event.stopPropagation();
67 self.presentation.start();
59 }); 68 });
60 69
61 document.body.addEventListener("drop", function(event) { 70 document.body.addEventListener("drop", function(event) {