aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pointless/viewer/init.js31
-rw-r--r--pointless/viewer/viewer.css3
-rw-r--r--pointless/viewer/viewer.js50
-rw-r--r--viewer.html1
4 files changed, 57 insertions, 28 deletions
diff --git a/pointless/viewer/init.js b/pointless/viewer/init.js
new file mode 100644
index 0000000..9454a23
--- /dev/null
+++ b/pointless/viewer/init.js
@@ -0,0 +1,31 @@
1/*
2 * init.js
3 * Part of Pointless Viewer, a Beamer presentation viewer
4 * Copyright 2018 Pacien TRAN-GIRARD
5 * License: GNU GPL v3
6 */
7
8"use strict";
9
10var params = function() {
11 var queryDict = {};
12 location.search.substr(1).split("&").forEach(function(item) {
13 var pair = item.split("=");
14 queryDict[pair[0]] = pair[1];
15 });
16 return queryDict;
17}();
18
19function isController() {
20 return window.opener == null || window.opener.location.href != window.location.href;
21}
22
23function init() {
24 var viewer = new Viewer();
25
26 if ("file" in params)
27 viewer.load(params["file"]);
28}
29
30if (isController())
31 init();
diff --git a/pointless/viewer/viewer.css b/pointless/viewer/viewer.css
index bea73e6..be4f876 100644
--- a/pointless/viewer/viewer.css
+++ b/pointless/viewer/viewer.css
@@ -5,11 +5,12 @@
5 * License: GNU GPL v3 5 * License: GNU GPL v3
6 */ 6 */
7 7
8body { 8html, body {
9 background-color: black; 9 background-color: black;
10 color: white; 10 color: white;
11 font-family: sans-serif; 11 font-family: sans-serif;
12 overflow: hidden; 12 overflow: hidden;
13 height: 100%;
13} 14}
14 15
15#fileInput { 16#fileInput {
diff --git a/pointless/viewer/viewer.js b/pointless/viewer/viewer.js
index 1c651fc..78035ee 100644
--- a/pointless/viewer/viewer.js
+++ b/pointless/viewer/viewer.js
@@ -7,50 +7,46 @@
7 7
8"use strict"; 8"use strict";
9 9
10var params = function() {
11 var queryDict = {};
12 location.search.substr(1).split("&").forEach(function(item) {
13 var pair = item.split("=");
14 queryDict[pair[0]] = pair[1];
15 });
16 return queryDict;
17}();
18
19function isController() {
20 return window.opener == null || window.opener.location.href != window.location.href;
21}
22
23class Viewer { 10class Viewer {
24 constructor() { 11 constructor() {
25 this.fileInput = document.getElementById("fileInput"); 12 this.fileInput = document.getElementById("fileInput");
26 this.fileInput.style.display = "block"; 13 this.fileInput.style.display = "block";
27 14 this._listenForInput();
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 } 15 }
37 16
38 _load(source) { 17 load(source) {
39 this.fileInput.style.display = "none"; 18 this.fileInput.style.display = "none";
40 pdfjsLib.getDocument(source).then(function(pdf) { 19 pdfjsLib.getDocument(source).then(function(pdf) {
41 var presentation = new Presentation(pdf); 20 var presentation = new Presentation(pdf);
42 }); 21 });
43 } 22 }
44 23
45 _readFile(file, callback) { 24 _readFile(file) {
46 var fileReader = new FileReader(); 25 var fileReader = new FileReader();
26 var self = this;
47 fileReader.onload = function() { 27 fileReader.onload = function() {
48 var byteArray = new Uint8Array(this.result); 28 var byteArray = new Uint8Array(this.result);
49 callback(byteArray); 29 self.load(byteArray);
50 } 30 }
51 31
52 fileReader.readAsArrayBuffer(file); 32 fileReader.readAsArrayBuffer(file);
53 } 33 }
54}
55 34
56if (isController()) new Viewer(); 35 _listenForInput() {
36 var self = this;
37 fileInput.addEventListener("change", function(event) {
38 self._readFile(event.target.files[0]);
39 });
40
41 document.body.addEventListener("drop", function(event) {
42 event.preventDefault();
43 event.stopPropagation();
44 self._readFile(event.dataTransfer.files[0]);
45 });
46
47 document.body.addEventListener("dragover", function(event) {
48 event.preventDefault();
49 event.stopPropagation();
50 });
51 }
52}
diff --git a/viewer.html b/viewer.html
index 943bbce..df529ca 100644
--- a/viewer.html
+++ b/viewer.html
@@ -26,5 +26,6 @@
26 <script type="text/javascript" src="pointless/viewer/stage.js"></script> 26 <script type="text/javascript" src="pointless/viewer/stage.js"></script>
27 <script type="text/javascript" src="pointless/viewer/presentation.js"></script> 27 <script type="text/javascript" src="pointless/viewer/presentation.js"></script>
28 <script type="text/javascript" src="pointless/viewer/viewer.js"></script> 28 <script type="text/javascript" src="pointless/viewer/viewer.js"></script>
29 <script type="text/javascript" src="pointless/viewer/init.js"></script>
29 </body> 30 </body>
30</html> 31</html>