From 4ea6886a06cef46193f4101d84ebb3dcc7928d84 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Fri, 20 Feb 2026 11:56:35 -0500 Subject: feat: extra options --- src/static/main.js | 62 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'src/static') diff --git a/src/static/main.js b/src/static/main.js index f3f4f71..68d36ad 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -1,41 +1,77 @@ const convertButton = document.getElementById("convert-button"); const uploadButton = document.getElementById("upload-button"); const markdownInput = document.getElementById("markdown"); +const imageInput = document.getElementById("image"); +const mdFileInput = document.getElementById("md-file"); -function sourceForm(event) { - const sourceElement = event.detail?.elt; - if (!sourceElement) { - return null; +document.body.addEventListener("htmx:beforeRequest", (event) => { + const elt = event.detail?.elt; + if (!elt) { + return; } - return sourceElement.closest("form"); -} -document.body.addEventListener("htmx:beforeRequest", (event) => { - const form = sourceForm(event); - if (form?.id === "convert-form" && convertButton) { + if (elt.id === "convert-form" && convertButton) { convertButton.disabled = true; convertButton.textContent = "generating..."; } - if (form?.id === "upload-form" && uploadButton) { + if (elt.id === "upload-button" && uploadButton) { uploadButton.disabled = true; uploadButton.textContent = "uploading..."; } }); document.body.addEventListener("htmx:afterRequest", (event) => { - const form = sourceForm(event); - if (form?.id === "convert-form" && convertButton) { + const elt = event.detail?.elt; + if (!elt) { + return; + } + + if (elt.id === "convert-form" && convertButton) { convertButton.disabled = false; convertButton.textContent = "generate pdf"; } - if (form?.id === "upload-form" && uploadButton) { + if (elt.id === "upload-button" && uploadButton) { uploadButton.disabled = false; uploadButton.textContent = "upload image"; } }); +if (mdFileInput) { + mdFileInput.addEventListener("change", () => { + const file = mdFileInput.files?.[0]; + + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + if (markdownInput) { + markdownInput.value = /** @type {string} */ (e.target.result); + markdownInput.readOnly = true; + } + if (imageInput) { + imageInput.disabled = true; + } + if (uploadButton) { + uploadButton.disabled = true; + } + }; + reader.readAsText(file); + } else { + if (markdownInput) { + markdownInput.value = ""; + markdownInput.readOnly = false; + } + if (imageInput) { + imageInput.disabled = false; + } + if (uploadButton) { + uploadButton.disabled = false; + } + } + }); +} + document.body.addEventListener("click", (event) => { const target = event.target; if (!(target instanceof HTMLElement)) { -- cgit v1.2.3