Files
docuseal/app/javascript/application.js
T

90 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-07-02 17:56:14 +03:00
import '@hotwired/turbo'
import { encodeMethodIntoRequestBody } from '@hotwired/turbo-rails/app/javascript/turbo/fetch_requests'
2023-05-21 17:59:36 +03:00
2023-06-24 22:50:12 +03:00
import { createApp, reactive } from 'vue'
import TemplateBuilder from './template_builder/builder'
2023-05-21 17:59:36 +03:00
import ToggleVisible from './elements/toggle_visible'
import DisableHidden from './elements/disable_hidden'
import TurboModal from './elements/turbo_modal'
2023-05-28 23:20:48 +03:00
import FileDropzone from './elements/file_dropzone'
2023-05-30 00:55:14 +03:00
import MenuActive from './elements/menu_active'
2023-06-03 21:22:03 +03:00
import ClipboardCopy from './elements/clipboard_copy'
2023-06-17 20:22:21 +00:00
import DynamicList from './elements/dynamic_list'
2023-06-20 22:38:38 +03:00
import DownloadButton from './elements/download_button'
import SetOriginUrl from './elements/set_origin_url'
2023-06-30 01:26:13 +03:00
import SetTimezone from './elements/set_timezone'
2023-07-01 01:09:44 +03:00
import AutoresizeTextarea from './elements/autoresize_textarea'
2023-05-21 17:59:36 +03:00
2023-07-02 17:56:14 +03:00
import * as TurboInstantClick from './lib/turbo_instant_click'
2023-07-03 23:37:16 +03:00
import './images/preview.png'
2023-07-02 17:56:14 +03:00
TurboInstantClick.start()
2023-05-29 23:08:55 +03:00
document.addEventListener('turbo:before-cache', () => {
window.flash?.remove()
})
2023-06-04 01:08:45 +03:00
document.addEventListener('keyup', (e) => {
if (e.code === 'Escape') {
document.activeElement?.blur()
}
})
2023-05-21 17:59:36 +03:00
window.customElements.define('toggle-visible', ToggleVisible)
window.customElements.define('disable-hidden', DisableHidden)
window.customElements.define('turbo-modal', TurboModal)
2023-05-28 23:20:48 +03:00
window.customElements.define('file-dropzone', FileDropzone)
2023-05-30 00:55:14 +03:00
window.customElements.define('menu-active', MenuActive)
2023-06-03 21:22:03 +03:00
window.customElements.define('clipboard-copy', ClipboardCopy)
2023-06-17 20:22:21 +00:00
window.customElements.define('dynamic-list', DynamicList)
2023-06-20 22:38:38 +03:00
window.customElements.define('download-button', DownloadButton)
window.customElements.define('set-origin-url', SetOriginUrl)
2023-06-30 01:26:13 +03:00
window.customElements.define('set-timezone', SetTimezone)
2023-07-01 01:09:44 +03:00
window.customElements.define('autoresize-textarea', AutoresizeTextarea)
2023-05-21 17:59:36 +03:00
2023-07-02 17:56:14 +03:00
document.addEventListener('turbo:before-fetch-request', encodeMethodIntoRequestBody)
2023-08-20 15:18:15 +03:00
document.addEventListener('turbo:submit-end', async (event) => {
const resp = event.detail?.formSubmission?.result?.fetchResponse?.response
if (!resp?.headers?.get('content-disposition')?.includes('attachment')) {
return
}
const url = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
link.href = url
link.setAttribute('download', decodeURIComponent(resp.headers.get('content-disposition').split('"')[1]))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
})
2023-07-02 17:56:14 +03:00
2023-05-31 23:19:20 +03:00
window.customElements.define('template-builder', class extends HTMLElement {
2023-06-24 22:50:12 +03:00
connectedCallback () {
this.appElem = document.createElement('div')
2023-08-19 21:05:54 +03:00
this.appElem.classList.add('max-h-screen')
2023-05-21 17:59:36 +03:00
2023-05-31 23:19:20 +03:00
this.app = createApp(TemplateBuilder, {
template: reactive(JSON.parse(this.dataset.template)),
isDirectUpload: this.dataset.isDirectUpload === 'true'
2023-05-21 17:59:36 +03:00
})
this.app.mount(this.appElem)
this.appendChild(this.appElem)
}
disconnectedCallback () {
this.app?.unmount()
2023-06-24 22:50:12 +03:00
this.appElem?.remove()
2023-05-21 17:59:36 +03:00
}
})