-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialog.js
95 lines (80 loc) · 3.3 KB
/
dialog.js
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
// HTML Embed for cState
// Version 2.0
// ALERT – DIALOG STYLE
//
// github.com/cstate/html-embed
// CHANGE THIS:
var cStateRoot = 'https://flamboyant-shirley-6bc75e.netlify.app'
// Only change this if you are hacking around! :)
var cStateEmbedPrefix = '[cState HTML Embed v2.0] ';
var cStateEmbedDebugging = false;
var cStateAPIStatus = 'tryingToGetStatus';
var cStateAPIRoot = cStateRoot + '/index.json';
var cStateAlertFunc = fetch(cStateAPIRoot)
.then(
function(response) {
if (response.status !== 200) {
console.log(cStateEmbedPrefix + 'API not OK, it sent HTTP status code ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
cStateAPIStatus = data.summaryStatus;
// When debugging, this code should be run to see API response
if (cStateEmbedDebugging) {
console.log(cStateEmbedPrefix + 'API response: ', data);
console.log(cStateEmbedPrefix + 'API says status page is: ' + cStateAPIStatus);
}
// UI code
// You can change how the alert appears here
function cStateAlertIn() {
var cStateAlertTitle = 'Having issues?';
var cStateAlertDescription = 'It looks like there are service disruptions. We apologize for the inconvenience. For more updates, please check <a href="' + cStateRoot + '" style="text-decoration: none; border-bottom: 1px solid currentColor; color: #007bff">our status page</a>.';
document.body.insertAdjacentHTML("beforeend",
`<style>
#cStateAlertDiv {
position: fixed;
line-height: 1.5;
max-width: 320px;
bottom: 5vh;
left: 5vh;
animation: cstatein 1s;
padding: 40px;
background: #fff;
border-radius: 6px;
box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}
@keyframes cstatein {
0% { opacity: 0; transform: translateY(10%); }
70% { opacity: 0; transform: translateY(10%); }
100% { opacity: 100%; transform: translateY(0); }
}
</style>
<div id="cStateAlertDiv">
<div style="font-size: 20px">
<strong id="cStateAlertTitle">` + cStateAlertTitle + `</strong>
<span onclick="this.parentNode.parentNode.remove()" aria-label="button to close dialog" style="font-size: 24px; cursor: pointer; float: right">×</span>
</div>
<div id="cStateAlertDescription" style="margin-top: 20px">` + cStateAlertDescription + `</div>
</div>`);
}
// Sets color and accessible label
if (cStateAPIStatus === 'ok') {
return;
} else if (cStateAPIStatus === 'notice') {
cStateAlertIn(); // You MIGHT want to change this
} else if (cStateAPIStatus === 'disrupted') {
cStateAlertIn();
} else { // down
cStateAlertIn();
}
});
}
)
.catch(function(err) {
console.log('Status page is down? fetch error. aborting', err);
});
// function can be run programatically or only on page load
// e.g. setTimeout(cStateAlertFunc, 5000000);
cStateAlertFunc();