- Sam Minton
- Nov. 12, 2024
- JavaScript
- JavaScript Doing It
This is how you do it
Paleo offal blog vinyl dreamcatcher, four dollar toast commode dolour ullamco labor sent fashion axe. Williamsburg selfies deletes, dis organic mlkshk audio laborious neutral master cleanse. Vice master cleanse red labor sartorial. Leggings mixtape narwhal, jean shorts easy slow-carb vero franzen direct trade laborious qui limo norm core. Street art seitan flexitarian, brooklyn try-hard occaecat excepteur brunch. Locavore tilde tempo readymade, eiusmod williamsburg minim cold-pressed non. Aliquippa before they sold out XOXO, pariatur yucca tousled viral.
- Do this furst
- Then this one next
- After that, do this too.
;(function () {
const toastOptions = { delay: 2000 }
function createToast(message) {
// Clone the template
const element = htmx.find("[data-toast-template]").cloneNode(true)
// Remove the data-toast-template attribute
delete element.dataset.toastTemplate
// Set the CSS class
element.className += " " + message.tags
// Set the text
htmx.find(element, "[data-toast-body]").innerText = message.message
// Add the new element to the container
htmx.find("[data-toast-container]").appendChild(element)
// Show the toast using Bootstrap's API
const toast = new bootstrap.Toast(element, toastOptions)
toast.show()
}
htmx.on("messages", (event) => {
event.detail.value.forEach(createToast)
})
// Show all existsing toasts, except the template
htmx.findAll(".toast:not([data-toast-template])").forEach((element) => {
const toast = new bootstrap.Toast(element, toastOptions)
toast.show()
})
})()