fix(ui): document viewer back button returns to the page you came from (chat or sources)
This commit is contained in:
+13
-6
@@ -65,14 +65,21 @@ const reducedMotion =
|
||||
typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
const SCROLL = reducedMotion ? "auto" : "smooth";
|
||||
|
||||
/* ---------- document viewer link (phase 10) ----------
|
||||
* Every cited document opens in the viewer, in a NEW tab. Both query
|
||||
/* ---------- document viewer link (phase 10; phase 13 adds `back`) ----------
|
||||
* Every cited document opens in the viewer, in a NEW tab. All query
|
||||
* values are percent-encoded: real paths contain slashes and sometimes
|
||||
* spaces, which would otherwise corrupt the query string. (The renderer
|
||||
* spaces, which would otherwise corrupt the query string. `back` tells the
|
||||
* viewer which page to return to when its back button is clicked — the
|
||||
* chips live in the chat, so chat passes "/" (the viewer validates it:
|
||||
* only same-origin relative URLs are honored; Sources links omit it and
|
||||
* get the viewer's /sources.html default). (The renderer
|
||||
* renderMarkdown/escapeHtml now lives in assets/markdown.js — a classic
|
||||
* script loaded by index.html and document.html before these modules.) */
|
||||
export function documentUrl(source, path) {
|
||||
return "/document.html?source=" + encodeURIComponent(source) + "&path=" + encodeURIComponent(path);
|
||||
export function documentUrl(source, path, back = "/") {
|
||||
let url =
|
||||
"/document.html?source=" + encodeURIComponent(source) + "&path=" + encodeURIComponent(path);
|
||||
if (back) url += "&back=" + encodeURIComponent(back);
|
||||
return url;
|
||||
}
|
||||
|
||||
/* ---------- avatar glyphs (phase 08: emoji-free chrome) ----------
|
||||
@@ -291,7 +298,7 @@ function appendSources(wrap, sources) {
|
||||
const chip = document.createElement("a");
|
||||
chip.className = "source-chip";
|
||||
chip.setAttribute("role", "listitem");
|
||||
chip.href = documentUrl(s.source, s.path);
|
||||
chip.href = documentUrl(s.source, s.path, "/"); // back → the chat page
|
||||
chip.target = "_blank"; // open the full document in a new tab
|
||||
chip.rel = "noopener";
|
||||
chip.textContent = label;
|
||||
|
||||
Reference in New Issue
Block a user