]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | /* Popup notifications */ | |
3 | ||
4 | function generate_notif(title, body) | |
5 | { | |
6 | /* generate a random number between 1000 and 90000 to use as an id */ | |
7 | const min = 1000; | |
8 | const max = 90000; | |
9 | const id = Math.floor(Math.random() * (max - min + 1)) + min; | |
10 | ||
11 | const toast = document.createElement('div'); | |
12 | toast.classList.add('toast', 'hide'); | |
13 | toast.id = 'toast' + id; | |
14 | toast.role = 'alert'; | |
15 | toast.ariaLive = 'assertive'; | |
16 | toast.ariaAtomic = 'true'; | |
17 | toast.setAttribute('data-delay', '10000'); | |
18 | ||
19 | const header = document.createElement('div'); | |
20 | header.classList.add('toast-header'); | |
21 | ||
22 | const theTitle = document.createElement('strong'); | |
23 | theTitle.classList.add('mr-auto'); | |
24 | theTitle.textContent = title; | |
25 | ||
26 | const notiftime = document.createElement('div'); | |
27 | notiftime.classList.add('badge', 'rounded-pill', 'badge-primary', 'ml-1'); | |
28 | notiftime.textContent = 'Just now'; // always just now I think right :D | |
29 | ||
30 | const closebutton = document.createElement('button'); | |
31 | closebutton.type = 'button'; | |
32 | closebutton.classList.add('ml-2', 'mb-1', 'close'); | |
33 | closebutton.setAttribute('data-dismiss', 'toast'); | |
34 | closebutton.ariaLabel = 'Close'; | |
35 | ||
36 | const closebuttonspan = document.createElement('span'); | |
37 | closebuttonspan.ariaHidden = 'true'; | |
38 | closebuttonspan.innerHTML = "×"; | |
39 | ||
40 | const toastbody = document.createElement('div'); | |
41 | toastbody.classList.add('toast-body'); | |
42 | toastbody.textContent = body; | |
43 | ||
44 | ||
45 | /* put it all together */ | |
46 | closebutton.appendChild(closebuttonspan); | |
47 | header.appendChild(theTitle); | |
48 | header.appendChild(notiftime); | |
49 | header.appendChild(closebutton); | |
50 | toast.appendChild(header); | |
51 | toast.appendChild(toastbody); | |
52 | document.getElementById('toaster').append(toast); | |
53 | ||
54 | $('#' + toast.id).toast('show'); | |
55 | } |