notice but without the t
This commit is contained in:
@ -1,22 +1,15 @@
|
||||
export function createNotification(text, timer = 3000) {
|
||||
export function createNotification(title = 'New notification', content, delay = 3000) {
|
||||
|
||||
if (!createNotification.templateToast) {
|
||||
createNotification.templateToast = new DOMParser().parseFromString(`
|
||||
<div class='toast' role='alert' data-bs-delay='${timer}'>
|
||||
<div class='toast-header'>
|
||||
<strong class='me-auto'>Notification</strong>
|
||||
<button type='button' class='btn-close' data-bs-dismiss='toast'></button>
|
||||
</div>
|
||||
<div class='toast-body'>
|
||||
</div>
|
||||
</div>
|
||||
`, 'text/html')
|
||||
.querySelector('body')
|
||||
.firstChild;
|
||||
}
|
||||
|
||||
const toastElement = createNotification.templateToast.cloneNode(true);
|
||||
toastElement.getElementsByClassName('toast-body')[0].innerHTML = text;
|
||||
const toastElement = document.createElement('div');
|
||||
toastElement.classList.add('toast');
|
||||
toastElement.role = 'alert';
|
||||
toastElement.setAttribute('data-bs-delay', delay);
|
||||
toastElement.innerHTML =
|
||||
`<div class='toast-header'>
|
||||
<strong class='me-auto'>${title}</strong>
|
||||
<button type='button' class='btn-close' data-bs-dismiss='toast'></button>
|
||||
</div>
|
||||
<div class='toast-body'>${content}</div>`
|
||||
toastElement.addEventListener('hidden.bs.toast', e => e.target.remove());
|
||||
new bootstrap.Toast(toastElement).show();
|
||||
|
||||
|
Reference in New Issue
Block a user