Update web/templates/entry_view.html
This commit is contained in:
@@ -467,7 +467,7 @@ function showToast(message, duration = 3000) {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Highlighter with localStorage fallback + session/template support -->
|
<!-- Highlighter: strict (only highlight exactly the selected fields) -->
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
const FIELD_TO_SELECTOR = {
|
const FIELD_TO_SELECTOR = {
|
||||||
@@ -480,7 +480,7 @@ function showToast(message, duration = 3000) {
|
|||||||
talk_number: "#talk_title-text"
|
talk_number: "#talk_title-text"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run under all scenarios (fresh load, bfcache, soft nav)
|
// Run on fresh load + 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);
|
||||||
@@ -495,26 +495,24 @@ function showToast(message, duration = 3000) {
|
|||||||
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" });
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const prefs = await res.json();
|
const prefs = await res.json();
|
||||||
if (typeof prefs.highlight_search_hits !== "undefined") {
|
if (typeof prefs.highlight_search_hits !== "undefined") enabled = !!prefs.highlight_search_hits;
|
||||||
enabled = !!prefs.highlight_search_hits;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(_) {}
|
} catch(_) {}
|
||||||
if (!enabled) { ran = true; return; }
|
if (!enabled) { ran = true; return; }
|
||||||
|
|
||||||
// 2) Obtain q + fields (prefer localStorage to avoid session timing issues)
|
// 2) Load the last search (STRICT: no defaulting to "subject")
|
||||||
let q = (localStorage.getItem('lastSearchQ') || '').trim();
|
let q = (localStorage.getItem('lastSearchQ') || '').trim();
|
||||||
let fields = [];
|
let fields = [];
|
||||||
try { fields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]'); } catch(_) {}
|
try { fields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]'); } catch(_) {}
|
||||||
|
|
||||||
// If LS empty, fall back to template/session values
|
// Fallback to template/session only if LS missing
|
||||||
if (!q || !fields.length) {
|
if ((!q || !fields.length)) {
|
||||||
q = (window.__lastSearchQ || '').trim();
|
q = (window.__lastSearchQ || '').trim();
|
||||||
if (!fields.length && Array.isArray(window.__lastSearchFields)) fields = window.__lastSearchFields;
|
if (Array.isArray(window.__lastSearchFields)) fields = window.__lastSearchFields.slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final fallback: JSON script tag
|
// Final fallback: JSON script tag
|
||||||
if (!q || !fields.length) {
|
if ((!q || !fields.length)) {
|
||||||
const dataEl = document.getElementById("last-search-data");
|
const dataEl = document.getElementById("last-search-data");
|
||||||
if (dataEl) {
|
if (dataEl) {
|
||||||
try {
|
try {
|
||||||
@@ -525,13 +523,14 @@ function showToast(message, duration = 3000) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If nothing was selected, highlight nothing (matches user intent)
|
||||||
if (!q || !fields.length) { ran = true; return; }
|
if (!q || !fields.length) { ran = true; return; }
|
||||||
|
|
||||||
// 3) Tokenize like your search: keep quoted phrases; strip wildcards
|
// 3) Tokenize query (keep quoted phrases; strip wildcards)
|
||||||
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; }
|
||||||
|
|
||||||
// 4) Highlight in the exact fields that were searched
|
// 4) Highlight only in the fields 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;
|
||||||
@@ -543,7 +542,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;
|
||||||
@@ -569,7 +568,6 @@ function showToast(message, duration = 3000) {
|
|||||||
function highlightAll(root, needle) {
|
function highlightAll(root, needle) {
|
||||||
if (!needle) return;
|
if (!needle) return;
|
||||||
const re = new RegExp(escapeRegExp(needle), "gi");
|
const re = new RegExp(escapeRegExp(needle), "gi");
|
||||||
|
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
|
||||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||||
@@ -600,4 +598,5 @@ function showToast(message, duration = 3000) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user