UNPKG

2.08 kBJavaScriptView Raw
1/* eslint strict: 0 */
2"use strict";
3
4/*
5 * This is a separate file for two reasons:
6 * 1. CSP policy does not allow inline javascript
7 * 2. It has to be a small javascript executed before all other scripts,
8 * so that the timeout can be triggered while slow JS is loading
9 */
10
11(function() {
12 var displayReload = function displayReload() {
13 var loadingReload = document.getElementById("loading-reload");
14 if (loadingReload) {
15 loadingReload.style.display = "block";
16 }
17 };
18
19 var loadingSlowTimeout = setTimeout(function() {
20 var loadingSlow = document.getElementById("loading-slow");
21
22 // The parent element, #loading, is being removed when the app is loaded.
23 // Since the timer is not cancelled, `loadingSlow` can be not found after
24 // 5s. Wrap everything in this block to make sure nothing happens if the
25 // element does not exist (i.e. page has loaded).
26 if (loadingSlow) {
27 loadingSlow.style.display = "block";
28 displayReload();
29 }
30 }, 5000);
31
32 document.getElementById("loading-reload").addEventListener("click", function() {
33 location.reload();
34 });
35
36 window.g_LoungeErrorHandler = function LoungeErrorHandler(e) {
37 var title = document.getElementById("loading-title");
38 title.textContent = "An error has occured";
39
40 var message = document.getElementById("loading-page-message");
41 message.textContent = "An error has occured that prevented the client from loading correctly.";
42
43 var summary = document.createElement("summary");
44 summary.textContent = "More details";
45
46 var data = document.createElement("pre");
47 data.textContent = e.message; // e is an ErrorEvent
48
49 var info = document.createElement("p");
50 info.textContent = "Open the developer tools of your browser for more information.";
51
52 var details = document.createElement("details");
53 details.appendChild(summary);
54 details.appendChild(data);
55 details.appendChild(info);
56 message.parentNode.insertBefore(details, message.nextSibling);
57
58 window.clearTimeout(loadingSlowTimeout);
59 displayReload();
60 };
61
62 window.addEventListener("error", window.g_LoungeErrorHandler);
63})();