a11yist/app/javascript/controllers/toast_controller.js

15 lines
488 B
JavaScript
Raw Permalink Normal View History

2024-11-12 23:55:00 +01:00
import { Controller } from "@hotwired/stimulus"
import * as bootstrap from "bootstrap"
// Connects to data-controller="toast"
export default class extends Controller {
connect() {
2025-05-16 19:02:33 +02:00
const shownKey = `toastsShown[${this.element.getAttribute("data-ts")}]`
if(!window.sessionStorage.getItem(shownKey)) {
window.sessionStorage.setItem(shownKey, Date.now());
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(this.element)
toastBootstrap.show()
}
2024-11-12 23:55:00 +01:00
}
}