From 5c30b8700e16323b3af7d27369818c7a02fdefee Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 19 Jul 2018 02:44:18 +0200 Subject: Read local file --- pointless/viewer/viewer.css | 10 +++++++--- pointless/viewer/viewer.js | 41 +++++++++++++++++++++++++++++++++++++---- viewer.html | 3 ++- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/pointless/viewer/viewer.css b/pointless/viewer/viewer.css index 14db376..bea73e6 100644 --- a/pointless/viewer/viewer.css +++ b/pointless/viewer/viewer.css @@ -8,10 +8,15 @@ body { background-color: black; color: white; + font-family: sans-serif; overflow: hidden; } -#screen { +#fileInput { + display: none; +} + +.centered { position: absolute; top: 50%; left: 50%; @@ -19,14 +24,13 @@ body { } .notification { - position: absolute; + position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); padding: 0.5rem 1rem; border-radius: 1rem 1rem 0 0; background-color: black; - font-family: sans-serif; font-size: 1.6rem; } 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() { return queryDict; }(); -if (window.opener == null) { - pdfjsLib.getDocument(params["file"]).then(function(pdf) { - var presentation = new Presentation(pdf); - }); +function isController() { + return window.opener == null || window.opener.location.href != window.location.href; +} + +class Viewer { + constructor() { + this.fileInput = document.getElementById("fileInput"); + this.fileInput.style.display = "block"; + + var self = this; + fileInput.addEventListener("change", function(event) { + var callback = function(file) { self._load(file) }; + self._readFile(event.target.files[0], callback); + }); + + if ("file" in params) + this._load(params["file"]); + } + + _load(source) { + this.fileInput.style.display = "none"; + pdfjsLib.getDocument(source).then(function(pdf) { + var presentation = new Presentation(pdf); + }); + } + + _readFile(file, callback) { + var fileReader = new FileReader(); + fileReader.onload = function() { + var byteArray = new Uint8Array(this.result); + callback(byteArray); + } + + fileReader.readAsArrayBuffer(file); + } } + +if (isController()) new Viewer(); diff --git a/viewer.html b/viewer.html index f4c6dde..943bbce 100644 --- a/viewer.html +++ b/viewer.html @@ -15,7 +15,8 @@ - + +
-- cgit v1.2.3