mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
therefore we can compose any controller from it - simplify `help-modal-controller` then - + create a simple `modal-controller` that close on `modal:close` event
32 lines
932 B
JavaScript
32 lines
932 B
JavaScript
export const useOpenAndCloseAsAModal = (controller) => {
|
|
Object.assign(controller, {
|
|
open: function () {
|
|
this.backgroundTarget.style.display = "block";
|
|
this.modalTarget.style.display = "block";
|
|
|
|
setTimeout(() => {
|
|
this.modalTarget.classList.add("in");
|
|
this.backgroundTarget.classList.add("in");
|
|
document.querySelector("body").classList.add("modal-open");
|
|
});
|
|
}.bind(controller),
|
|
|
|
close: function () {
|
|
this.modalTarget.classList.remove("in");
|
|
this.backgroundTarget.classList.remove("in");
|
|
document.querySelector("body").classList.remove("modal-open");
|
|
|
|
setTimeout(() => {
|
|
this.backgroundTarget.style.display = "none";
|
|
this.modalTarget.style.display = "none";
|
|
}, 200);
|
|
}.bind(controller),
|
|
|
|
closeIfEscapeKey: function (e) {
|
|
if (e.code == "Escape") {
|
|
this.close();
|
|
}
|
|
}.bind(controller),
|
|
});
|
|
};
|