Update web/templates/entry_view.html
This commit is contained in:
parent
443e44ea79
commit
bdaef505a2
@ -467,7 +467,7 @@ function showToast(message, duration = 3000) {
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Highlighter: prefer template/session over localStorage; sync LS to avoid stale "subject only" -->
|
||||
<!-- Highlighter: choose the best field source (most fields wins), then sync LS -->
|
||||
<script>
|
||||
(function(){
|
||||
const FIELD_TO_SELECTOR = {
|
||||
@ -480,6 +480,7 @@ function showToast(message, duration = 3000) {
|
||||
talk_number: "#talk_title-text"
|
||||
};
|
||||
|
||||
// Fire on first paint and on bfcache restores
|
||||
if (document.readyState === "complete" || document.readyState === "interactive") run();
|
||||
else document.addEventListener("DOMContentLoaded", run, { once: true });
|
||||
window.addEventListener("pageshow", run);
|
||||
@ -488,7 +489,7 @@ function showToast(message, duration = 3000) {
|
||||
async function run(){
|
||||
if (ran) return;
|
||||
|
||||
// 1) Respect per-user toggle
|
||||
// 1) Respect per-user toggle (defaults ON if flag missing)
|
||||
let enabled = true;
|
||||
try {
|
||||
const res = await fetch("/api/get-prefs/", { cache: "no-store", credentials: "same-origin" });
|
||||
@ -499,34 +500,49 @@ function showToast(message, duration = 3000) {
|
||||
} catch(_) {}
|
||||
if (!enabled) { ran = true; return; }
|
||||
|
||||
// 2) GATHER CANDIDATES
|
||||
// Template/session (authoritative for THIS navigation)
|
||||
let tmplQ = (window.__lastSearchQ || '').trim();
|
||||
let tmplFields = Array.isArray(window.__lastSearchFields) ? window.__lastSearchFields.slice() : [];
|
||||
// JSON script fallback
|
||||
if (!tmplQ || !tmplFields.length) {
|
||||
const dataEl = document.getElementById("last-search-data");
|
||||
if (dataEl) {
|
||||
try {
|
||||
const payload = JSON.parse(dataEl.textContent || "{}");
|
||||
tmplQ = (payload.q || "").trim();
|
||||
tmplFields = Array.isArray(payload.fields) ? payload.fields : tmplFields;
|
||||
} catch(_) {}
|
||||
// 2) Gather candidates from all sources
|
||||
const cand = { tmpl: {q:"", fields:[]}, json: {q:"", fields:[]}, ls: {q:"", fields:[]} };
|
||||
|
||||
// 2a) Template/script-literal variables (set by view)
|
||||
cand.tmpl.q = (window.__lastSearchQ || '').trim();
|
||||
cand.tmpl.fields = Array.isArray(window.__lastSearchFields) ? window.__lastSearchFields.slice() : [];
|
||||
|
||||
// 2b) JSON <script> block (if present)
|
||||
const dataEl = document.getElementById("last-search-data");
|
||||
if (dataEl) {
|
||||
try {
|
||||
const payload = JSON.parse(dataEl.textContent || "{}");
|
||||
cand.json.q = (payload.q || "").trim();
|
||||
cand.json.fields = Array.isArray(payload.fields) ? payload.fields.slice() : [];
|
||||
} catch(_){}
|
||||
}
|
||||
|
||||
// 2c) localStorage (may be stale)
|
||||
cand.ls.q = (localStorage.getItem('lastSearchQ') || '').trim();
|
||||
try { cand.ls.fields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]') || []; } catch(_) { cand.ls.fields = []; }
|
||||
|
||||
// 3) Pick the best candidate: longest non-empty "fields" wins (ties: prefer template, then JSON, then LS)
|
||||
const order = ["tmpl","json","ls"];
|
||||
let bestKey = "";
|
||||
let best = { q:"", fields:[] };
|
||||
|
||||
for (const k of order) {
|
||||
const item = cand[k];
|
||||
// prefer any candidate with more fields
|
||||
if (item.fields && item.fields.length > (best.fields ? best.fields.length : 0)) {
|
||||
bestKey = k;
|
||||
best = item;
|
||||
} else if (item.fields.length === (best.fields ? best.fields.length : 0)) {
|
||||
// tie-breaker: keep earlier (tmpl > json > ls)
|
||||
}
|
||||
}
|
||||
// localStorage (may be stale; use only if template/session absent)
|
||||
let lsQ = (localStorage.getItem('lastSearchQ') || '').trim();
|
||||
let lsFields = [];
|
||||
try { lsFields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]'); } catch(_) {}
|
||||
|
||||
// 3) CHOOSE SOURCE (template/session wins if present)
|
||||
let q = tmplQ || lsQ || '';
|
||||
let fields = (tmplQ && tmplFields.length) ? tmplFields
|
||||
: (lsQ && lsFields.length ? lsFields : []);
|
||||
|
||||
// If still empty, nothing to do
|
||||
const q = (best.q || "").trim();
|
||||
const fields = Array.isArray(best.fields) ? best.fields.filter(Boolean) : [];
|
||||
if (!q || !fields.length) { ran = true; return; }
|
||||
|
||||
// 4) SYNC localStorage to what we actually used (prevents stale "subject" sticking)
|
||||
// 4) Sync LS to the chosen "best" so stale subject-only arrays don't keep overriding
|
||||
try {
|
||||
localStorage.setItem('lastSearchQ', q);
|
||||
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
|
||||
@ -536,7 +552,7 @@ function showToast(message, duration = 3000) {
|
||||
const tokens = tokenize(q).map(t => t.replaceAll("*","").replaceAll("?","")).filter(Boolean);
|
||||
if (!tokens.length) { ran = true; return; }
|
||||
|
||||
// 6) Highlight only the fields actually selected
|
||||
// 6) Highlight only in the fields that were actually selected
|
||||
for (const f of fields) {
|
||||
const sel = FIELD_TO_SELECTOR[f];
|
||||
if (!sel) continue;
|
||||
@ -548,7 +564,7 @@ function showToast(message, duration = 3000) {
|
||||
ran = true;
|
||||
}
|
||||
|
||||
// helpers
|
||||
// --- helpers ---
|
||||
function tokenize(s) {
|
||||
const out = [];
|
||||
let i = 0, buf = "", inQ = false;
|
||||
@ -606,4 +622,5 @@ function showToast(message, duration = 3000) {
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user