You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
789 B

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["dialog"]
confirm(event) {
// The second pass — after the player confirmed — falls through to Turbo.
if (this.confirmed) return
event.preventDefault()
this.pendingForm = event.target
this.dialogTarget.showModal()
}
ok() {
this.dialogTarget.close()
// requestSubmit(), not submit(): the native call skips the submit event, so
// Turbo would miss it and navigate the whole page out of the game frame.
this.confirmed = true
this.pendingForm?.requestSubmit()
}
cancel() {
this.dialogTarget.close()
this.pendingForm = null
}
backdropClick(event) {
if (event.target === this.dialogTarget) this.cancel()
}
}