Update web/templates/entry_view.html

This commit is contained in:
Joshua Laymon 2025-08-24 00:34:24 +00:00
parent 9f625fe833
commit 443e44ea79

View File

@ -467,7 +467,7 @@ function showToast(message, duration = 3000) {
}
</script>
<!-- Highlighter: strict (only highlight exactly the selected fields) -->
<!-- Highlighter: prefer template/session over localStorage; sync LS to avoid stale "subject only" -->
<script>
(function(){
const FIELD_TO_SELECTOR = {
@ -480,7 +480,6 @@ function showToast(message, duration = 3000) {
talk_number: "#talk_title-text"
};
// Run on fresh load + bfcache restores
if (document.readyState === "complete" || document.readyState === "interactive") run();
else document.addEventListener("DOMContentLoaded", run, { once: true });
window.addEventListener("pageshow", run);
@ -500,37 +499,44 @@ function showToast(message, duration = 3000) {
} catch(_) {}
if (!enabled) { ran = true; return; }
// 2) Load the last search (STRICT: no defaulting to "subject")
let q = (localStorage.getItem('lastSearchQ') || '').trim();
let fields = [];
try { fields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]'); } catch(_) {}
// Fallback to template/session only if LS missing
if ((!q || !fields.length)) {
q = (window.__lastSearchQ || '').trim();
if (Array.isArray(window.__lastSearchFields)) fields = window.__lastSearchFields.slice();
}
// Final fallback: JSON script tag
if ((!q || !fields.length)) {
// 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 || "{}");
q = (payload.q || "").trim();
fields = Array.isArray(payload.fields) ? payload.fields : [];
tmplQ = (payload.q || "").trim();
tmplFields = Array.isArray(payload.fields) ? payload.fields : tmplFields;
} catch(_) {}
}
}
// 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 nothing was selected, highlight nothing (matches user intent)
if (!q || !fields.length) { ran = true; return; }
// 3) Tokenize query (keep quoted phrases; strip wildcards)
// 4) SYNC localStorage to what we actually used (prevents stale "subject" sticking)
try {
localStorage.setItem('lastSearchQ', q);
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
} catch(_) {}
// 5) Tokenize query (keep quoted phrases; strip wildcards)
const tokens = tokenize(q).map(t => t.replaceAll("*","").replaceAll("?","")).filter(Boolean);
if (!tokens.length) { ran = true; return; }
// 4) Highlight only in the fields actually selected
// 6) Highlight only the fields actually selected
for (const f of fields) {
const sel = FIELD_TO_SELECTOR[f];
if (!sel) continue;
@ -599,4 +605,5 @@ function showToast(message, duration = 3000) {
{% endblock %}