diff options
Diffstat (limited to 'beamer/viewer/init.js')
-rw-r--r-- | beamer/viewer/init.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/beamer/viewer/init.js b/beamer/viewer/init.js new file mode 100644 index 0000000..9192834 --- /dev/null +++ b/beamer/viewer/init.js | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Beamer Viewer, a web-based PDF presentation viewer | ||
3 | * Copyright (C) 2018 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | "use strict"; | ||
20 | |||
21 | const params = function() { | ||
22 | const queryDict = {}; | ||
23 | location.hash.substr(1).split("&").forEach(item => { | ||
24 | const pair = item.split("="); | ||
25 | queryDict[pair[0]] = pair[1]; | ||
26 | }); | ||
27 | return queryDict; | ||
28 | }(); | ||
29 | |||
30 | function isController() { | ||
31 | return window.opener == null || window.opener.location.href != window.location.href; | ||
32 | } | ||
33 | |||
34 | function initCache() { | ||
35 | if (!navigator.serviceWorker) return; | ||
36 | navigator.serviceWorker.register("appcache.js"); | ||
37 | |||
38 | const offlineCapableIndicator = document.getElementById("offlineCapable"); | ||
39 | offlineCapableIndicator.style.visibility = "visible"; | ||
40 | } | ||
41 | |||
42 | function checkPopupPermission() { | ||
43 | const popup = window.open("popup.html"); | ||
44 | |||
45 | if (popup == null) { | ||
46 | const warningMessage = document.getElementById("warning"); | ||
47 | warningMessage.textContent = "A pop-up blocker is active. Make sure to allow pop-ups on this website."; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | function init() { | ||
52 | initCache(); | ||
53 | checkPopupPermission(); | ||
54 | |||
55 | const viewer = new Viewer(); | ||
56 | |||
57 | if ("file" in params) | ||
58 | viewer.load(params["file"]); | ||
59 | } | ||
60 | |||
61 | function load(file) { | ||
62 | location.hash = "file=" + file; | ||
63 | location.reload(); | ||
64 | } | ||
65 | |||
66 | if (isController()) | ||
67 | init(); | ||