-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.js
48 lines (43 loc) · 1.85 KB
/
alert.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
function initialiseAlert() {
document.getElementById('alert-close').onclick = hideAlert();
}
function createAlert(title, body, mode, callback, callbackLabel) {
// setting mask's display to flex makes every child visible
document.getElementById('mask').style.display = 'flex';
let close = document.getElementById('alert-close')
// close button is only hidden in case of an error dialog, so we set this to block by default
close.style.display = 'block';
if (mode === 'error') {
close.style.display = 'none'; // no point letting user continue on a broken site
if (!callback) {
// if no callback is supplied, this means there's no action and thus no buttons are present.
// in such a case, we hide the footer
document.getElementById('alert-footer').style.display = 'none';
}
} else if (mode === 'completion') {
close.innerHTML = 'Stop it';
close.onclick = function() { // override close button's functionality if this is a completion alert
let audio = document.querySelector("#audio");
audio.pause();
audio.currentTime = 0; // stop and reset the music
hideAlert();
}
} else {
close.onclick = hideAlert;
}
let action = document.getElementById('alert-action');
if (callback) { // if callback exists, enable the button for it and set the click action
action.style.display = 'block';
action.innerHTML = callbackLabel;
action.onclick = function() {
callback();
}
} else {
action.style.display = 'none';
}
document.getElementById('alert-header').innerHTML = title; // set dialog title
document.getElementById('alert-body').innerHTML = body; // set dialog body
}
function hideAlert() {
document.getElementById('mask').style.display = 'none';
}