Files

48 lines
1.1 KiB
JavaScript
Raw Permalink 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
2026-07-24 21:58:55 +03:00
document.addEventListener('turbo:before-cache', this.onBeforeCache)
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)
2026-07-24 21:58:55 +03:00
document.removeEventListener('turbo:before-cache', this.onBeforeCache)
2023-05-21 17:59:36 +03:00
}
onSubmit = (e) => {
2024-09-06 19:30:49 +03:00
if (e.detail.success && e.detail?.formSubmission?.formElement?.dataset?.closeOnSubmit !== 'false') {
2023-05-21 17:59:36 +03:00
this.close()
}
}
onEscKey = (e) => {
if (e.code === 'Escape') {
this.close()
}
}
2026-07-24 21:58:55 +03:00
onBeforeCache = () => {
if (this.closest('turbo-frame')?.src) {
this.remove()
}
}
2023-05-21 17:59:36 +03:00
close = (e) => {
e?.preventDefault()
2026-07-30 17:40:54 +03:00
this.remove()
2023-05-21 17:59:36 +03:00
}
})