diff options
Diffstat (limited to 'beamer/viewer/viewer.js')
-rw-r--r-- | beamer/viewer/viewer.js | 29 |
1 files changed, 13 insertions, 16 deletions
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)); | ||
52 | } | 50 | } |
53 | 51 | ||
54 | this.fileReader.abort(); | 52 | this.fileReader.abort(); |
@@ -72,25 +70,24 @@ class Viewer { | |||
72 | } | 70 | } |
73 | 71 | ||
74 | _listenForInput() { | 72 | _listenForInput() { |
75 | const self = this; | 73 | fileInput.addEventListener("change", event => { |
76 | fileInput.addEventListener("change", function(event) { | 74 | this._readFile(event.target.files[0]); |
77 | self._readFile(event.target.files[0]); | ||
78 | }); | 75 | }); |
79 | 76 | ||
80 | startButton.addEventListener("click", function(event) { | 77 | startButton.addEventListener("click", event => { |
81 | event.preventDefault(); | 78 | event.preventDefault(); |
82 | event.stopPropagation(); | 79 | event.stopPropagation(); |
83 | self.presentation.start(); | 80 | this.presentation.start(); |
84 | }); | 81 | }); |
85 | 82 | ||
86 | document.body.addEventListener("drop", function(event) { | 83 | document.body.addEventListener("drop", event => { |
87 | event.preventDefault(); | 84 | event.preventDefault(); |
88 | event.stopPropagation(); | 85 | event.stopPropagation(); |
89 | self.fileInput.files = event.dataTransfer.files; | 86 | this.fileInput.files = event.dataTransfer.files; |
90 | self._readFile(event.dataTransfer.files[0]); | 87 | this._readFile(event.dataTransfer.files[0]); |
91 | }); | 88 | }); |
92 | 89 | ||
93 | document.body.addEventListener("dragover", function(event) { | 90 | document.body.addEventListener("dragover", event => { |
94 | event.preventDefault(); | 91 | event.preventDefault(); |
95 | event.stopPropagation(); | 92 | event.stopPropagation(); |
96 | }); | 93 | }); |