mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
22 lines
668 B
JavaScript
22 lines
668 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
connect() {
|
|
// open the modal before rendering the html to avoid opening a blank modal
|
|
// TODO other option is having a controller in the stream html that would dispatch the open element on connect
|
|
window.addEventListener("turbo:before-stream-render", this.#open.bind(this));
|
|
}
|
|
|
|
disconnect() {
|
|
window.removeEventListener("turbo:before-stream-render", this.#open.bind(this));
|
|
}
|
|
|
|
// private
|
|
|
|
#open() {
|
|
// dispatch "product-preview:open" event to trigger modal->open action
|
|
// see views/admin/product_v3/index.html.haml
|
|
this.dispatch("open");
|
|
}
|
|
}
|