-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
158 lines (144 loc) · 4.47 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
<!DOCTYPE html>
<html>
<head>
<title>Scrum Poker</title>
<meta name="theme-color" content="#BB8FCE">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link rel="manifest" href="./manifest.json">
<style>
html, *, *::before, *::after {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: sans-serif;
line-height: 1.5em;
}
button {
padding: 14px 28px;
background: #BB8FCE;
color: #ffffff;
text-transform: uppercase;
border: none;
border-radius: 4px;
}
.button--block {
display: block;
width: 100%;
}
.sticky {
position: absolute;
bottom: 16px;
right: 0;
left: 0;
}
.drawer.is-open::before {
content: ' ';
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #222;
opacity: 0.9;
}
.drawer__inner {
position: fixed;
top: 100px;
bottom:0;
width: 100%;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
padding: 16px;
background-color: #fff;
transform: translateY(150%);
transition: transform 0.25s ease-in-out;
}
.drawer__content {
position: relative;
height: 100%;
}
.drawer.is-open .drawer__inner {
transform: translateY(0);
}
</style>
<link rel="shortcut icon" type="image/x-icon" href="./images/favicon.ico">
<link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32" />
<link rel="stylesheet" type="text/css" href="./dist/index.css">
<script>
const updateDrawerId = 'updateDrawer';
function toggleDrawer(id, show) {
const drawer = document.getElementById(id);
if (drawer) {
drawer.className = show ? 'drawer is-open' : 'drawer';
}
}
function attachUpdateDrawer() {
const drawer = document.createElement('div');
const drawerInner = document.createElement('div');
const drawerContent = document.createElement('div');
const updateTitle = document.createElement('h3');
const updateContent = document.createElement('div');
const updateButtonWrapper = document.createElement('div');
const updateButton = document.createElement('button');
drawer.id = updateDrawerId;
drawer.className = 'drawer';
drawerInner.className = 'drawer__inner';
drawerContent.className = 'drawer__content';
updateTitle.textContent = 'Yay! App Updated';
updateContent.textContent = 'New update already arrived! Your app will be reloaded.';
updateButtonWrapper.className = 'sticky';
updateButton.className = 'button--block';
updateButton.textContent = 'Reload App';
updateButton.addEventListener('click', () => {
toggleDrawer(updateDrawerId, false)
window.location.reload();
});
updateButtonWrapper.append(updateButton);
drawerContent.append(
updateTitle,
updateContent,
updateButtonWrapper,
);
drawerInner.append(drawerContent);
drawer.append(drawerInner);
document.body.append(drawer);
}
function notifyUpdate(worker) {
toggleDrawer(updateDrawerId, true);
worker.postMessage('skipWaiting');
}
function trackSwInstallation(worker) {
worker.addEventListener('statechange', function() {
if (worker.state === 'installed') {
notifyUpdate(worker);
}
});
}
window.onload = function() {
attachUpdateDrawer();
};
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function(reg) {
if (!navigator.serviceWorker.controller) {
return;
}
if (reg.waiting) {
notifyUpdate(reg.waiting);
}
if (reg.installing) {
trackSwInstallation(reg.installing);
}
reg.addEventListener('updatefound', function() {
trackSwInstallation(reg.installing);
});
});
}
</script>
</head>
<body id="app">
</body>
<script src="./dist/index.js"></script>
</html>