Update web/templates/entry_view.html
This commit is contained in:
parent
c64e8d0b30
commit
9f625fe833
@ -467,7 +467,7 @@ function showToast(message, duration = 3000) {
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Highlighter with localStorage fallback + session/template support -->
|
||||
<!-- Highlighter: strict (only highlight exactly the selected fields) -->
|
||||
<script>
|
||||
(function(){
|
||||
const FIELD_TO_SELECTOR = {
|
||||
@ -480,7 +480,7 @@ function showToast(message, duration = 3000) {
|
||||
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();
|
||||
else document.addEventListener("DOMContentLoaded", run, { once: true });
|
||||
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" });
|
||||
if (res.ok) {
|
||||
const prefs = await res.json();
|
||||
if (typeof prefs.highlight_search_hits !== "undefined") {
|
||||
enabled = !!prefs.highlight_search_hits;
|
||||
}
|
||||
if (typeof prefs.highlight_search_hits !== "undefined") enabled = !!prefs.highlight_search_hits;
|
||||
}
|
||||
} catch(_) {}
|
||||
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 fields = [];
|
||||
try { fields = JSON.parse(localStorage.getItem('lastSearchFields') || '[]'); } catch(_) {}
|
||||
|
||||
// If LS empty, fall back to template/session values
|
||||
if (!q || !fields.length) {
|
||||
// Fallback to template/session only if LS missing
|
||||
if ((!q || !fields.length)) {
|
||||
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
|
||||
if (!q || !fields.length) {
|
||||
if ((!q || !fields.length)) {
|
||||
const dataEl = document.getElementById("last-search-data");
|
||||
if (dataEl) {
|
||||
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; }
|
||||
|
||||
// 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);
|
||||
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) {
|
||||
const sel = FIELD_TO_SELECTOR[f];
|
||||
if (!sel) continue;
|
||||
@ -543,7 +542,7 @@ function showToast(message, duration = 3000) {
|
||||
ran = true;
|
||||
}
|
||||
|
||||
// ---- helpers ----
|
||||
// helpers
|
||||
function tokenize(s) {
|
||||
const out = [];
|
||||
let i = 0, buf = "", inQ = false;
|
||||
@ -569,7 +568,6 @@ function showToast(message, duration = 3000) {
|
||||
function highlightAll(root, needle) {
|
||||
if (!needle) return;
|
||||
const re = new RegExp(escapeRegExp(needle), "gi");
|
||||
|
||||
const nodes = [];
|
||||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
|
||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||
@ -600,4 +598,5 @@ function showToast(message, duration = 3000) {
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user