From afd82dc38510c6a47cfa227f40f1dae76e1a526c Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Mon, 16 Feb 2026 01:42:50 -0500 Subject: refactor: move to src/ --- src/static/main.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/static/main.js (limited to 'src/static') 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(); +}); -- cgit v1.2.3