Initial commit
This commit is contained in:
33
Groceries/wwwroot/js/controllers/modal.js
Normal file
33
Groceries/wwwroot/js/controllers/modal.js
Normal file
@ -0,0 +1,33 @@
|
||||
import { Controller } from "/lib/hotwired/stimulus/dist/stimulus.js";
|
||||
|
||||
export default class ModalController extends Controller {
|
||||
static targets = ["frame"];
|
||||
|
||||
open() {
|
||||
if (!this.element.open) {
|
||||
this.element.showModal();
|
||||
}
|
||||
}
|
||||
|
||||
close(event) {
|
||||
if (!this.element.open) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
this.element.close();
|
||||
this.frameTarget.src = undefined;
|
||||
this.frameTarget.innerHTML = "";
|
||||
|
||||
switch (event.type) {
|
||||
case "turbo:submit-end":
|
||||
Turbo.visit(location.href, { action: "replace" });
|
||||
break;
|
||||
case "popstate":
|
||||
event.stopImmediatePropagation();
|
||||
history.go(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user