ui: propose modal 2-steps + clean local urls

This commit is contained in:
s-FunIA
2026-01-19 11:31:32 +01:00
parent b13aa10f69
commit aece8c5526
2 changed files with 153 additions and 39 deletions

View File

@@ -70,6 +70,11 @@ const GITEA_REPO = import.meta.env.PUBLIC_GITEA_REPO ?? "";
<!-- IMPORTANT: define:vars injecte les constantes dans le JS sans templating fragile -->
<script is:inline define:vars={{ GITEA_BASE, GITEA_OWNER, GITEA_REPO }}>
(() => {
// Nettoyage si un ancien bug a injecté ?body=... dans l'URL
if (window.location.search.includes("body=")) {
history.replaceState(null, "", window.location.pathname + window.location.hash);
}
const title = document.body.dataset.docTitle || document.title;
const version = document.body.dataset.docVersion || "";
@@ -79,7 +84,11 @@ const GITEA_REPO = import.meta.env.PUBLIC_GITEA_REPO ?? "";
const base = String(GITEA_BASE).replace(/\/+$/, "");
const issue = new URL(`${base}/${GITEA_OWNER}/${GITEA_REPO}/issues/new`);
const local = new URL(window.location.href);
// URL locale "propre" : on ignore totalement query-string (?body=...)
const local = new URL(window.location.origin + window.location.pathname);
// évite dembarquer des paramètres parasites (ex: ?body=... issus de tests)
local.searchParams.delete("body");
local.searchParams.delete("title");
local.hash = anchorId;
const path = local.pathname;
@@ -127,7 +136,7 @@ const GITEA_REPO = import.meta.env.PUBLIC_GITEA_REPO ?? "";
citeBtn.textContent = "Citer";
citeBtn.addEventListener("click", async () => {
const url = new URL(window.location.href);
const url = new URL(window.location.origin + window.location.pathname);
url.hash = p.id;
const cite = `${title}${version ? ` (v${version})` : ""} — ${url.toString()}`;
@@ -145,16 +154,34 @@ const GITEA_REPO = import.meta.env.PUBLIC_GITEA_REPO ?? "";
tools.appendChild(citeBtn);
if (giteaReady) {
const propose = document.createElement("a");
propose.className = "para-propose";
propose.href = "#";
propose.textContent = "Proposer";
propose.setAttribute("aria-label", "Proposer une correction sur Gitea");
const propose = document.createElement("a");
propose.className = "para-propose";
propose.href = "#";
propose.textContent = "Proposer";
propose.setAttribute("aria-label", "Proposer une correction sur Gitea");
propose.setAttribute("data-propose","1");
propose.setAttribute("data-propose","1");
propose.addEventListener("click", (e) => {
e.preventDefault();
const raw = (p.textContent || "").trim().replace(/\s+/g, " ");
const excerpt = raw.length > 420 ? (raw.slice(0, 420) + "…") : raw;
const url = buildIssueURL(p.id, excerpt);
tools.appendChild(propose);
// on stocke l'URL pour le modal
propose.dataset.url = url.toString();
// fallback: si le modal n'existe pas -> ouverture directe
const dlg = document.getElementById("propose-modal");
if (!dlg || typeof dlg.showModal !== "function") {
window.open(propose.dataset.url, "_blank", "noopener,noreferrer");
return;
}
// si modal existe, il va intercepter le click globalement
// donc on ne fait rien ici de plus.
});
tools.appendChild(propose);
}
p.appendChild(tools);
}