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>
|
</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>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
const FIELD_TO_SELECTOR = {
|
const FIELD_TO_SELECTOR = {
|
||||||
@ -480,6 +480,7 @@ function showToast(message, duration = 3000) {
|
|||||||
talk_number: "#talk_title-text"
|
talk_number: "#talk_title-text"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fire on first paint and on bfcache restores
|
||||||
if (document.readyState === "complete" || document.readyState === "interactive") run();
|
if (document.readyState === "complete" || document.readyState === "interactive") run();
|
||||||
else document.addEventListener("DOMContentLoaded", run, { once: true });
|
else document.addEventListener("DOMContentLoaded", run, { once: true });
|
||||||
window.addEventListener("pageshow", run);
|
window.addEventListener("pageshow", run);
|
||||||
@ -488,7 +489,7 @@ function showToast(message, duration = 3000) {
|
|||||||
async function run(){
|
async function run(){
|
||||||
if (ran) return;
|
if (ran) return;
|
||||||
|
|
||||||
// 1) Respect per-user toggle
|
// 1) Respect per-user toggle (defaults ON if flag missing)
|
||||||
let enabled = true;
|
let enabled = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/get-prefs/", { cache: "no-store", credentials: "same-origin" });
|
const res = await fetch("/api/get-prefs/", { cache: "no-store", credentials: "same-origin" });
|
||||||
@ -499,34 +500,49 @@ function showToast(message, duration = 3000) {
|
|||||||
} catch(_) {}
|
} catch(_) {}
|
||||||
if (!enabled) { ran = true; return; }
|
if (!enabled) { ran = true; return; }
|
||||||
|
|
||||||
// 2) GATHER CANDIDATES
|
// 2) Gather candidates from all sources
|
||||||
// Template/session (authoritative for THIS navigation)
|
const cand = { tmpl: {q:"", fields:[]}, json: {q:"", fields:[]}, ls: {q:"", fields:[]} };
|
||||||
let tmplQ = (window.__lastSearchQ || '').trim();
|
|
||||||
let tmplFields = Array.isArray(window.__lastSearchFields) ? window.__lastSearchFields.slice() : [];
|
// 2a) Template/script-literal variables (set by view)
|
||||||
// JSON script fallback
|
cand.tmpl.q = (window.__lastSearchQ || '').trim();
|
||||||
if (!tmplQ || !tmplFields.length) {
|
cand.tmpl.fields = Array.isArray(window.__lastSearchFields) ? window.__lastSearchFields.slice() : [];
|
||||||
const dataEl = document.getElementById("last-search-data");
|
|
||||||
if (dataEl) {
|
// 2b) JSON <script> block (if present)
|
||||||
try {
|
const dataEl = document.getElementById("last-search-data");
|
||||||
const payload = JSON.parse(dataEl.textContent || "{}");
|
if (dataEl) {
|
||||||
tmplQ = (payload.q || "").trim();
|
try {
|
||||||
tmplFields = Array.isArray(payload.fields) ? payload.fields : tmplFields;
|
const payload = JSON.parse(dataEl.textContent || "{}");
|
||||||
} catch(_) {}
|
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; }
|
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 {
|
try {
|
||||||
localStorage.setItem('lastSearchQ', q);
|
localStorage.setItem('lastSearchQ', q);
|
||||||
localStorage.setItem('lastSearchFields', JSON.stringify(fields));
|
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);
|
const tokens = tokenize(q).map(t => t.replaceAll("*","").replaceAll("?","")).filter(Boolean);
|
||||||
if (!tokens.length) { ran = true; return; }
|
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) {
|
for (const f of fields) {
|
||||||
const sel = FIELD_TO_SELECTOR[f];
|
const sel = FIELD_TO_SELECTOR[f];
|
||||||
if (!sel) continue;
|
if (!sel) continue;
|
||||||
@ -548,7 +564,7 @@ function showToast(message, duration = 3000) {
|
|||||||
ran = true;
|
ran = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpers
|
// --- helpers ---
|
||||||
function tokenize(s) {
|
function tokenize(s) {
|
||||||
const out = [];
|
const out = [];
|
||||||
let i = 0, buf = "", inQ = false;
|
let i = 0, buf = "", inQ = false;
|
||||||
@ -606,4 +622,5 @@ function showToast(message, duration = 3000) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user