1
0
postdoc/app/javascript/controllers/modal_controller.js

38 lines
677 B
JavaScript
Raw Normal View History

2020-12-06 20:49:03 +01:00
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "modal" ]
connect() {
}
closeClickedOutside(event) {
if (this.mouseClickDownTarget != this.mouseClickUpTarget) {
return;
}
if (event.srcElement == this.modalTarget) {
this.close();
}
}
close(event) {
this.modalTarget.remove();
}
error() {
this.modalTarget.classList.add("shake");
setTimeout(() => {
this.modalTarget.classList.remove("shake");
}, 1000)
}
trackMouseDown(event) {
this.mouseClickDownTarget = event.target
}
trackMouseUp(event) {
this.mouseClickUpTarget = event.target
}
}