]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - js/bs-toast.js
2 /* Popup notifications */
4 function generate_notif(title
, body
)
6 /* generate a random number between 1000 and 90000 to use as an id */
9 const id
= Math
.floor(Math
.random() * (max
- min
+ 1)) + min
;
11 const toast
= document
.createElement('div');
12 toast
.classList
.add('toast', 'hide');
13 toast
.id
= 'toast' + id
;
15 toast
.ariaLive
= 'assertive';
16 toast
.ariaAtomic
= 'true';
17 toast
.setAttribute('data-delay', '10000');
19 const header
= document
.createElement('div');
20 header
.classList
.add('toast-header');
22 const theTitle
= document
.createElement('strong');
23 theTitle
.classList
.add('mr-auto');
24 theTitle
.textContent
= title
;
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
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';
36 const closebuttonspan
= document
.createElement('span');
37 closebuttonspan
.ariaHidden
= 'true';
38 closebuttonspan
.innerHTML
= "×";
40 const toastbody
= document
.createElement('div');
41 toastbody
.classList
.add('toast-body');
42 toastbody
.textContent
= body
;
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
);
54 $('#' + toast
.id
).toast('show');