diff options
Diffstat (limited to 'pointless/viewer/viewer.js')
-rw-r--r-- | pointless/viewer/viewer.js | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/pointless/viewer/viewer.js b/pointless/viewer/viewer.js index 00c6f76..1c651fc 100644 --- a/pointless/viewer/viewer.js +++ b/pointless/viewer/viewer.js | |||
@@ -16,8 +16,41 @@ var params = function() { | |||
16 | return queryDict; | 16 | return queryDict; |
17 | }(); | 17 | }(); |
18 | 18 | ||
19 | if (window.opener == null) { | 19 | function isController() { |
20 | pdfjsLib.getDocument(params["file"]).then(function(pdf) { | 20 | return window.opener == null || window.opener.location.href != window.location.href; |
21 | var presentation = new Presentation(pdf); | 21 | } |
22 | }); | 22 | |
23 | class Viewer { | ||
24 | constructor() { | ||
25 | this.fileInput = document.getElementById("fileInput"); | ||
26 | this.fileInput.style.display = "block"; | ||
27 | |||
28 | var self = this; | ||
29 | fileInput.addEventListener("change", function(event) { | ||
30 | var callback = function(file) { self._load(file) }; | ||
31 | self._readFile(event.target.files[0], callback); | ||
32 | }); | ||
33 | |||
34 | if ("file" in params) | ||
35 | this._load(params["file"]); | ||
36 | } | ||
37 | |||
38 | _load(source) { | ||
39 | this.fileInput.style.display = "none"; | ||
40 | pdfjsLib.getDocument(source).then(function(pdf) { | ||
41 | var presentation = new Presentation(pdf); | ||
42 | }); | ||
43 | } | ||
44 | |||
45 | _readFile(file, callback) { | ||
46 | var fileReader = new FileReader(); | ||
47 | fileReader.onload = function() { | ||
48 | var byteArray = new Uint8Array(this.result); | ||
49 | callback(byteArray); | ||
50 | } | ||
51 | |||
52 | fileReader.readAsArrayBuffer(file); | ||
53 | } | ||
23 | } | 54 | } |
55 | |||
56 | if (isController()) new Viewer(); | ||