ui: fix propose modal script + category injection
This commit is contained in:
@@ -35,8 +35,6 @@
|
|||||||
.grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:.5rem; }
|
.grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:.5rem; }
|
||||||
.grid button { padding: .75rem .8rem; border-radius: 12px; border: 1px solid rgba(0,0,0,.18); background: rgba(255,255,255,.96); color: #111; cursor: pointer; text-align: left; }
|
.grid button { padding: .75rem .8rem; border-radius: 12px; border: 1px solid rgba(0,0,0,.18); background: rgba(255,255,255,.96); color: #111; cursor: pointer; text-align: left; }
|
||||||
.grid button:hover { background: #fff; }
|
.grid button:hover { background: #fff; }
|
||||||
.grid button:hover { background: #fff; }
|
|
||||||
.ft { margin-top:.75rem; opacity:.85; }
|
|
||||||
kbd { padding:0 .35rem; border:1px solid rgba(0,0,0,.2); border-radius:6px; }
|
kbd { padding:0 .35rem; border:1px solid rgba(0,0,0,.2); border-radius:6px; }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -50,41 +48,47 @@
|
|||||||
|
|
||||||
const upsertLine = (text, key, value) => {
|
const upsertLine = (text, key, value) => {
|
||||||
const re = new RegExp(`^${key}:\\s*.*$`, "mi");
|
const re = new RegExp(`^${key}:\\s*.*$`, "mi");
|
||||||
if (!value) return text; // "continuer sans préciser"
|
// Si "continuer sans préciser" : on ne touche pas au body
|
||||||
|
if (!value) return text;
|
||||||
if (re.test(text)) return text.replace(re, `${key}: ${value}`);
|
if (re.test(text)) return text.replace(re, `${key}: ${value}`);
|
||||||
const sep = text && !text.endsWith("\n") ? "\n" : "";
|
const sep = text && !text.endsWith("\n") ? "\n" : "";
|
||||||
return text + sep + `${key}: ${value}\n`;
|
return text + sep + `${key}: ${value}\n`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const openWith = (url) => {
|
const openModalFor = (url) => {
|
||||||
pending = url;
|
pending = url;
|
||||||
if (typeof dlg.showModal === "function") dlg.showModal();
|
if (typeof dlg.showModal === "function") dlg.showModal();
|
||||||
else window.location.href = url.toString(); // fallback robuste
|
else window.open(url.toString(), "_blank", "noopener,noreferrer");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Intercepte UNIQUEMENT les liens marqués data-propose
|
// Interception des clics sur "Proposer"
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const a = e.target?.closest?.("a[data-propose]");
|
const a = e.target?.closest?.("a[data-propose]");
|
||||||
if (!a) return;
|
if (!a) return;
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// URL réelle stockée par EditionLayout (propose.dataset.url)
|
||||||
|
const rawUrl = a.dataset.url || a.getAttribute("href") || "";
|
||||||
|
if (!rawUrl || rawUrl === "#") return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
openWith(new URL(a.href, window.location.origin));
|
openModalFor(new URL(rawUrl, window.location.origin));
|
||||||
} catch {
|
} catch {
|
||||||
window.location.href = a.href;
|
window.open(rawUrl, "_blank", "noopener,noreferrer");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Choix d’une catégorie -> injection "Category:" + ouverture Gitea
|
||||||
dlg.addEventListener("click", (e) => {
|
dlg.addEventListener("click", (e) => {
|
||||||
const btn = e.target?.closest?.("button[data-category]");
|
const btn = e.target?.closest?.("button[data-category]");
|
||||||
if (!btn || !pending) return;
|
if (!btn || !pending) return;
|
||||||
|
|
||||||
const cat = btn.getAttribute("data-category") || "";
|
const cat = btn.getAttribute("data-category") || "";
|
||||||
let body = pending.searchParams.get("body") || "";
|
const body = pending.searchParams.get("body") || "";
|
||||||
body = upsertLine(body, "Category", cat); // clé stable (sans accents)
|
pending.searchParams.set("body", upsertLine(body, "Category", cat));
|
||||||
|
|
||||||
pending.searchParams.set("body", body);
|
|
||||||
dlg.close();
|
dlg.close();
|
||||||
|
|
||||||
window.open(pending.toString(), "_blank", "noopener,noreferrer");
|
window.open(pending.toString(), "_blank", "noopener,noreferrer");
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user