Update web/templates/entry_view.html

This commit is contained in:
2025-08-23 16:04:04 +00:00
parent 37d2531364
commit fd12a809de
+27 -15
View File
@@ -467,9 +467,30 @@ function showToast(message, duration = 3000) {
}
</script>
<!-- Highlighter: uses exact DB field names -->
<!-- Highlighter: robust triggers (DOMContentLoaded + pageshow + readyState) -->
<script>
document.addEventListener("DOMContentLoaded", async () => {
(function(){
// EXACT field -> selector mapping for your template IDs
const fieldToSelector = {
subject: "#subject-list",
illustration: "#illustration-text",
application: "#application-text",
scripture_raw: "#scripture-text",
source: "#source-text",
talk_title: "#talk_title-text",
talk_number: "#talk_title-text",
};
// Kickoff with multiple safety nets so it also runs after bfcache restores
if (document.readyState === "complete" || document.readyState === "interactive") {
run();
} else {
document.addEventListener("DOMContentLoaded", run, { once: true });
}
// pageshow fires on bfcache restores and some soft navigations
window.addEventListener("pageshow", run);
async function run() {
// Respect per-user toggle
let enabled = true;
try {
@@ -497,17 +518,6 @@ document.addEventListener("DOMContentLoaded", async () => {
}
if (!q || !fields.length) return;
// Exact field -> selector mapping for your template IDs
const fieldToSelector = {
subject: "#subject-list",
illustration: "#illustration-text",
application: "#application-text",
scripture_raw: "#scripture-text",
source: "#source-text",
talk_title: "#talk_title-text",
talk_number: "#talk_title-text",
};
// Tokenize like your search (keep quoted phrases, strip * and ?)
const tokens = tokenize(q).map(t => t.replaceAll("*","").replaceAll("?","")).filter(Boolean);
if (!tokens.length) return;
@@ -515,11 +525,12 @@ document.addEventListener("DOMContentLoaded", async () => {
// Highlight only within fields that were searched
for (const f of fields) {
const sel = fieldToSelector[f];
if (!sel) continue; // ignore fields not shown on page
if (!sel) continue;
const container = document.querySelector(sel);
if (!container) continue;
for (const tok of tokens) highlightAll(container, tok);
}
}
// ---- helpers ----
function tokenize(s) {
@@ -572,7 +583,8 @@ document.addEventListener("DOMContentLoaded", async () => {
while (walker.nextNode()) nodes.push(walker.currentNode);
nodes.forEach(cb);
}
});
})();
</script>
{% endblock %}