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.
docuseal/app/javascript/elements/turbo_modal.js

38 lines
897 B

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)
document.addEventListener('turbo:submit-end', this.onSubmit)
document.addEventListener('turbo:before-cache', this.close)
}
disconnectedCallback () {
document.body.classList.remove('overflow-hidden')
document.removeEventListener('keyup', this.onEscKey)
document.removeEventListener('turbo:submit-end', this.handleSubmit)
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()
}
})