diff options
author | pacien | 2023-10-23 22:42:46 +0200 |
---|---|---|
committer | pacien | 2023-10-23 22:42:46 +0200 |
commit | f1351788ee5d3be634462fea24e6057f9c74e428 (patch) | |
tree | 31f707a859231cef8dbcfc070612010df0470c5a | |
parent | f044095b70bbc56b17332f9fb3dde85e2de40222 (diff) | |
download | beamer-viewer-f1351788ee5d3be634462fea24e6057f9c74e428.tar.gz |
viewer: fix loading from URL (for demo file)
-rw-r--r-- | beamer/viewer/init.js | 2 | ||||
-rw-r--r-- | beamer/viewer/viewer.js | 19 |
2 files changed, 16 insertions, 5 deletions
diff --git a/beamer/viewer/init.js b/beamer/viewer/init.js index 18269cd..6190386 100644 --- a/beamer/viewer/init.js +++ b/beamer/viewer/init.js | |||
@@ -45,7 +45,7 @@ function init() { | |||
45 | const viewer = new Viewer(); | 45 | const viewer = new Viewer(); |
46 | 46 | ||
47 | if ("file" in params) | 47 | if ("file" in params) |
48 | viewer.load(params["file"]); | 48 | viewer.loadFromUrl(params["file"]); |
49 | } | 49 | } |
50 | 50 | ||
51 | function load(file) { | 51 | function load(file) { |
diff --git a/beamer/viewer/viewer.js b/beamer/viewer/viewer.js index 8101b02..e9c6d65 100644 --- a/beamer/viewer/viewer.js +++ b/beamer/viewer/viewer.js | |||
@@ -29,7 +29,7 @@ class Viewer { | |||
29 | this._listenForInput(); | 29 | this._listenForInput(); |
30 | } | 30 | } |
31 | 31 | ||
32 | load(source) { | 32 | _preparePresentation(source) { |
33 | const self = this; | 33 | const self = this; |
34 | pdfjsLib.getDocument(source).then(function(pdf) { | 34 | pdfjsLib.getDocument(source).then(function(pdf) { |
35 | self.presentation = new Presentation(pdf); | 35 | self.presentation = new Presentation(pdf); |
@@ -43,18 +43,29 @@ class Viewer { | |||
43 | _readFile(file) { | 43 | _readFile(file) { |
44 | const self = this; | 44 | const self = this; |
45 | this.fileReader.onload = function() { | 45 | this.fileReader.onload = function() { |
46 | self._onFileLoaded(new Uint8Array(this.result)); | 46 | self._setPresentation(new Uint8Array(this.result)); |
47 | } | 47 | } |
48 | 48 | ||
49 | this.fileReader.abort(); | 49 | this.fileReader.abort(); |
50 | this.fileReader.readAsArrayBuffer(file); | 50 | this.fileReader.readAsArrayBuffer(file); |
51 | } | 51 | } |
52 | 52 | ||
53 | _onFileLoaded(bytes) { | 53 | _setPresentation(presentation) { |
54 | this.load(bytes); | 54 | this._preparePresentation(presentation); |
55 | this.startButton.disabled = false; | 55 | this.startButton.disabled = false; |
56 | } | 56 | } |
57 | 57 | ||
58 | _setFileName(name) { | ||
59 | const dummy = new DataTransfer(); | ||
60 | dummy.items.add(new File([], name)); | ||
61 | this.fileInput.files = dummy.files; | ||
62 | } | ||
63 | |||
64 | loadFromUrl(url) { | ||
65 | this._setFileName(url); | ||
66 | this._setPresentation(url); | ||
67 | } | ||
68 | |||
58 | _listenForInput() { | 69 | _listenForInput() { |
59 | const self = this; | 70 | const self = this; |
60 | fileInput.addEventListener("change", function(event) { | 71 | fileInput.addEventListener("change", function(event) { |