mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-20 19:56:48 +00:00
30 lines
645 B
JavaScript
30 lines
645 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
document.addEventListener("turbolinks:before-cache", () =>
|
|
document.getElementById("flash").remove(),
|
|
);
|
|
|
|
export default class extends Controller {
|
|
static values = {
|
|
autoClose: Boolean,
|
|
};
|
|
|
|
connect() {
|
|
if (this.autoCloseValue) {
|
|
setTimeout(this.close.bind(this), 5000);
|
|
}
|
|
}
|
|
|
|
close(e) {
|
|
// Fade out
|
|
this.element.classList.remove("animate-show");
|
|
this.element.classList.add("animate-hide-500");
|
|
setTimeout(this.remove.bind(this), 500);
|
|
e && e.preventDefault(); // Prevent submitting if we're inside a form
|
|
}
|
|
|
|
remove() {
|
|
this.element.remove();
|
|
}
|
|
}
|