mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-07 10:04:22 +00:00
25 lines
1008 B
JavaScript
25 lines
1008 B
JavaScript
// Script to move all embedded toast messages into a container with id 'toast-container'. The container ensures multiple
|
|
// toast messages are stacked properly. The script targets all elements specified by a 'data-toast-target' and ensures
|
|
// the click event of the origin is linked as well.
|
|
|
|
const container = document.getElementById('toast-container')
|
|
if (container !== null) {
|
|
// process all data-toast-target elements
|
|
document.querySelectorAll('[data-toast-target]').forEach(trigger => {
|
|
const target = document.getElementById(trigger.getAttribute('data-toast-target'))
|
|
if (target !== null) {
|
|
// move the element to the toast containr
|
|
container.appendChild(target)
|
|
|
|
// eslint-disable-next-line no-undef
|
|
const toast = bootstrap.Toast.getOrCreateInstance(target)
|
|
if (toast !== null) {
|
|
// associate the click event of the origin with the toast element
|
|
trigger.addEventListener('click', () => {
|
|
toast.show()
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|