diff options
| author | kj_sh604 | 2026-02-16 01:42:50 -0500 |
|---|---|---|
| committer | kj_sh604 | 2026-02-16 01:42:50 -0500 |
| commit | afd82dc38510c6a47cfa227f40f1dae76e1a526c (patch) | |
| tree | 6182294363a0599e2b07e5d0675fc1a8ccf5fc01 /src/static | |
| parent | 94c6fdd12c8352f26df112f1c21592b020bb7c06 (diff) | |
refactor: move to src/
Diffstat (limited to 'src/static')
| -rw-r--r-- | src/static/main.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/static/main.js b/src/static/main.js new file mode 100644 index 0000000..f3f4f71 --- /dev/null +++ b/src/static/main.js @@ -0,0 +1,59 @@ +const convertButton = document.getElementById("convert-button"); +const uploadButton = document.getElementById("upload-button"); +const markdownInput = document.getElementById("markdown"); + +function sourceForm(event) { + const sourceElement = event.detail?.elt; + if (!sourceElement) { + return null; + } + return sourceElement.closest("form"); +} + +document.body.addEventListener("htmx:beforeRequest", (event) => { + const form = sourceForm(event); + if (form?.id === "convert-form" && convertButton) { + convertButton.disabled = true; + convertButton.textContent = "generating..."; + } + + if (form?.id === "upload-form" && uploadButton) { + uploadButton.disabled = true; + uploadButton.textContent = "uploading..."; + } +}); + +document.body.addEventListener("htmx:afterRequest", (event) => { + const form = sourceForm(event); + if (form?.id === "convert-form" && convertButton) { + convertButton.disabled = false; + convertButton.textContent = "generate pdf"; + } + + if (form?.id === "upload-form" && uploadButton) { + uploadButton.disabled = false; + uploadButton.textContent = "upload image"; + } +}); + +document.body.addEventListener("click", (event) => { + const target = event.target; + if (!(target instanceof HTMLElement)) { + return; + } + + const button = target.closest("[data-insert-markdown]"); + if (!(button instanceof HTMLElement) || !markdownInput) { + return; + } + + const snippet = button.dataset.insertMarkdown; + if (!snippet) { + return; + } + + const needsLeadingNewline = markdownInput.value && !markdownInput.value.endsWith("\n"); + const prefix = needsLeadingNewline ? "\n" : ""; + markdownInput.value += `${prefix}${snippet}\n`; + markdownInput.focus(); +}); |
