rails8-memoapp/app/javascript/controllers/modal_controller.js

24 lines
477 B
JavaScript

import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
connect() {
this.element.style.display = "none";
}
open() {
this.element.style.display = "block";
}
close() {
this.element.style.display = "none";
const frame = document.getElementById("modal");
frame.removeAttribute("src");
frame.innerHTML = "";
}
clickOutside(event) {
if (event.target === this.element) {
this.close();
}
}
}