-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
287 lines (234 loc) · 6.29 KB
/
index.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App loading...</title>
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="theme-color" content="#1976d2">
<link rel="icon" href="data:,">
<style>
*, :after, :before {
box-sizing: border-box;
user-select: text;
}
body {
font-family: -apple-system, BlinkMacSystemFont, Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
html, body, #splash, #root {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.none {
display: none;
}
.hidden {
visibility: hidden;
}
.middle {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
text-align: center;
}
#splash {
position: absolute;
top: 0; left: 0;
background: #fff;
z-index: 999;
}
#splash .logo {
--width: 80px;
}
.pwa #splash .logo {
display: none;
}
#splash .logo img {
display: inline-flex;
flex-direction: column;
width: var(--width);
height: var(--width);
}
#splash .loading, #splash noscript {
position: absolute;
bottom: 40px;
width: 100%;
text-align: center;
}
#splash noscript {
color: red;
}
</style>
<script>
(function() {
//config vars
var config = {
basePath: location.href.replace(/\/$/, ''), //set basePath to the absolute URL to this file
loadingDelay: 2000,
isHybrid: !!window._cordovaNative,
isPwa: !!(window.matchMedia && window.matchMedia('(display-mode: standalone)').matches),
assets: function() {
return [
config.basePath + "/js/config.mjs",
config.basePath + "/js/app.mjs",
config.basePath + "/css/app.css"
];
}
};
//is hybrid?
if(config.isHybrid) {
document.documentElement.classList.add('hybrid');
}
//is pwa?
if(config.isPwa) {
document.documentElement.classList.add('pwa');
}
//process after window loaded
window.addEventListener('load', function() {
//non-blocking
setTimeout(function() {
//browser supported?
if(!window.fetch) {
return alert('Your browser is out of date and not supported. Please use a different browser to continue.');
}
//can use service worker?
if('serviceWorker' in window.navigator) {
//worker event dispatcher
var swEvent = function(name, args = {}) {
var done = false;
var callback = function() {
if(!done && document.readyState === 'complete') {
var e = new CustomEvent(name, { detail: args });
window.dispatchEvent(e);
done = true;
}
};
callback();
document.addEventListener('readystatechange', callback);
};
//register service worker
navigator.serviceWorker.register('sw.js', { type: 'module' }).then(function(reg) {
//set vars
var isNew = !navigator.serviceWorker.controller;
//callback
var callback = function() {
swEvent('swUpdate', { reg: reg, isNew: isNew });
};
//state change listener
var stateChangeListener = function() {
reg.installing.postMessage('skipWaiting');
reg.installing.addEventListener('statechange', function(e) {
if(this.state === 'installed') {
callback();
}
});
};
//is waiting?
if(reg.waiting) {
reg.waiting.postMessage('skipWaiting');
return callback();
}
//is installing?
if(reg.installing) {
return stateChangeListener();
}
//ask for notification?
if(reg.active && location.hash.indexOf('#push=') === 0) {
var id = location.hash.split('=')[1];
reg.active.postMessage({ action: 'getNotification', id: id });
location.hash = '';
}
//listen for state change
reg.addEventListener('updatefound', stateChangeListener);
}).catch(function(error) {
//log error
console.error(error.message);
//dispatch event
swEvent('swFailed', error);
});
//listen for messages
navigator.serviceWorker.addEventListener('message', function(e) {
//force refresh?
if(e.data === 'forceRefresh') {
location.reload();
return;
}
});
} else {
//log error
console.error('Service worker not supported');
}
//load core assets
config.assets().forEach(function(url) {
//set vars
var el, type = url.split('?')[0].split('.').pop();
//is css?
if(type === 'css') {
el = document.createElement('link');
el.rel = "stylesheet";
el.href = url;
}
//is js?
if(type === 'js' || type === 'mjs') {
el = document.createElement('script');
el.type = (type === 'mjs') ? 'module' : '';
el.async = false;
el.src = url;
}
//load asset?
if(el) {
document.documentElement.firstChild.appendChild(el);
}
});
//load pwa assets?
if(!config.isHybrid) {
//manifest
var manifest = document.createElement('link');
manifest.rel = "manifest";
manifest.href = "manifest.json";
document.documentElement.firstChild.appendChild(manifest);
//favicon
var favicon = document.querySelector('[rel="icon"]');
favicon.type = "image/png";
favicon.sizes = "any";
favicon.href = "img/icons/icon-48x48.png";
//apple touch icon
var apple = document.createElement('link');
apple.rel = 'apple-touch-icon';
apple.href = "img/icons/icon-144x144.png";
document.documentElement.firstChild.appendChild(apple);
}
//loading message
setTimeout(function() {
//display loading message
var loading = document.querySelector('#splash .loading');
loading.classList.remove('hidden');
}, config.loadingDelay);
}, 0);
});
})();
</script>
</head>
<body>
<div id="splash">
<div class="logo middle">
<img src="img/icons/icon-144x144.png" alt="Logo" width="80" height="80">
</div>
<div class="loading hidden">
App loading...
</div>
<noscript>
Please enable javascript to continue
</noscript>
</div>
<div id="root"></div>
</body>
</html>