mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
This ensures morphed flashes hide like other flashes (eg in bulk order actions). I wanted to write a spec to prove it, but Capybara doesn't support mocking setTimeout and I didn't want to use sleep.
I've made it optional because this controller is shared with the shop frontend ([supposedly](5ef34347a3), although angular seems to override it).
29 lines
569 B
JavaScript
29 lines
569 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() {
|
|
// Fade out
|
|
this.element.classList.remove("animate-show");
|
|
this.element.classList.add("animate-hide-500");
|
|
setTimeout(this.remove.bind(this), 500);
|
|
}
|
|
|
|
remove() {
|
|
this.element.remove();
|
|
}
|
|
}
|