aboutsummaryrefslogtreecommitdiff
path: root/pointless/viewer/init.js
blob: 5f04eacd7881a9f01106dfc24051867266b0cb86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * init.js
 * Part of Pointless Viewer, a Beamer presentation viewer
 * Copyright 2018 Pacien TRAN-GIRARD
 * License: GNU GPL v3
 */

"use strict";

const params = function() {
  const queryDict = {};
  location.search.substr(1).split("&").forEach(function(item) {
    const pair = item.split("=");
    queryDict[pair[0]] = pair[1];
  });
  return queryDict;
}();

function isController() {
  return window.opener == null || window.opener.location.href != window.location.href;
}

function initCache() {
  if (!navigator.serviceWorker) return;
  navigator.serviceWorker.register("appcache.js");
  
  const offlineCapableIndicator = document.getElementById("offlineCapable");
  offlineCapableIndicator.style.visibility = "visible";
}

function checkPopupPermission() {
  const popup = window.open("popup.html");

  if (popup == null) {
    const warningMessage = document.getElementById("warning");
    warningMessage.textContent = "A pop-up blocker is active. Make sure to allow pop-ups on this website.";
  }
}

function init() {
  initCache();
  checkPopupPermission();

  const viewer = new Viewer();

  if ("file" in params)
    viewer.load(params["file"]);
}

if (isController())
  init();