Files
docuseal/app/javascript/elements/turbo_modal.js
T

42 lines
956 B
JavaScript
Raw Normal View History

2023-05-21 17:59:36 +03:00
import { actionable } from '@github/catalyst/lib/actionable'
export default actionable(class extends HTMLElement {
connectedCallback () {
document.body.classList.add('overflow-hidden')
document.addEventListener('keyup', this.onEscKey)
2023-08-20 15:18:15 +03:00
2023-05-21 17:59:36 +03:00
document.addEventListener('turbo:before-cache', this.close)
2023-08-20 15:18:15 +03:00
if (this.dataset.closeAfterSubmit !== 'false') {
document.addEventListener('turbo:submit-end', this.onSubmit)
}
2023-05-21 17:59:36 +03:00
}
disconnectedCallback () {
document.body.classList.remove('overflow-hidden')
document.removeEventListener('keyup', this.onEscKey)
2023-07-31 00:48:51 +03:00
document.removeEventListener('turbo:submit-end', this.onSubmit)
2023-05-21 17:59:36 +03:00
document.removeEventListener('turbo:before-cache', this.close)
}
onSubmit = (e) => {
if (e.detail.success) {
this.close()
}
}
onEscKey = (e) => {
if (e.code === 'Escape') {
this.close()
}
}
close = (e) => {
e?.preventDefault()
this.remove()
}
})