From 0ad536869d15221d5f6ba74e62ced97b62d7e751 Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Thu, 4 Sep 2025 03:14:24 +0000 Subject: [PATCH] Update web/static/js/subject-actions.v1.js --- web/static/js/subject-actions.v1.js | 116 +++++++++++++++++++++------- 1 file changed, 86 insertions(+), 30 deletions(-) diff --git a/web/static/js/subject-actions.v1.js b/web/static/js/subject-actions.v1.js index 63ac38f..18cbaf2 100644 --- a/web/static/js/subject-actions.v1.js +++ b/web/static/js/subject-actions.v1.js @@ -1,14 +1,14 @@ /* subject-actions.v1.js Popup for .subject-pill anchors with: - - WOL Search (uses current href) - - Insight Book (only if subject exists in Insight index) - - Wikipedia Search - - Google Search - - Database Search (only for 1–2 word subjects) + - Search in Insight Book (only if subject exists in Insight index) + - Search in WOL (uses current href if present) + - Search in Database (only for 1–2 word subjects) + - Search on Google + - Search on Wikipedia Insight index: - The script merges a small built-in seed with (optional) /static/data/insight-index.v1.json - - JSON format: { "abraham": "120000001", "babel": "1200000456", ... } + - JSON format: { "abraham": "1200000060", "babel": "1200000613", ... } */ (function(){ @@ -22,7 +22,7 @@ // ---- Helpers function norm(s){ return String(s||'').toLowerCase().replace(/[^\p{L}\p{N}\s'-]/gu,'').replace(/\s+/g,' ').trim(); } function isOneOrTwoWords(s){ return norm(s).split(' ').filter(Boolean).length <= 2; } - function getSearchBase(){ + function getSearchBase(){ var el = document.getElementById('subject-list'); return el ? el.getAttribute('data-search-url') || '/search' : '/search'; } @@ -45,7 +45,7 @@ return getSearchBase()+"?q="+encodeURIComponent(q)+"&fields=subject"; } - // ---- Built-in tiny seed (now with ~20 common, verified entries) + // ---- Built-in tiny seed (~20 common, verified entries). External JSON will merge/override. var INSIGHT_INDEX = { "abraham": "1200000060", "adam": "1200000089", @@ -80,7 +80,7 @@ try { var data = JSON.parse(xhr.responseText || '{}'); if (data && typeof data === 'object'){ - for (var k in data){ if (data.hasOwnProperty(k)) INSIGHT_INDEX[norm(k)] = String(data[k]); } + for (var k in data){ if (Object.prototype.hasOwnProperty.call(data,k)) INSIGHT_INDEX[norm(k)] = String(data[k]); } } } catch(_){} } @@ -89,34 +89,79 @@ } catch(_){} })(); - // ---- Popup (reuses same visual style as scripture-actions; inject if not present) + // ---- Popup (injects minimal CSS + HTML with icons) var popupEl; function ensurePopup(){ if (popupEl) return popupEl; - // Minimal CSS (skip if scripture-actions already injected it — harmless to duplicate) + + // Minimal CSS (safe if injected twice) var style = document.createElement('style'); style.textContent = - ".subject-actions-pop{position:absolute;z-index:9999;background:#fff;border:1px solid #e5e7eb;border-radius:.5rem;box-shadow:0 10px 20px rgba(0,0,0,.1);padding:.5rem;min-width:220px;display:none}" + + ".subject-actions-pop{position:absolute;z-index:9999;background:#fff;border:1px solid #e5e7eb;border-radius:.5rem;box-shadow:0 10px 20px rgba(0,0,0,.1);padding:.5rem;min-width:240px;display:none}" + ".subject-actions-pop .hdr{display:flex;justify-content:space-between;align-items:center;font-weight:600;font-size:.9rem;color:#1f2937;margin-bottom:.25rem}" + ".subject-actions-pop .close-x{cursor:pointer;padding:.1rem .4rem;border-radius:.375rem}" + ".subject-actions-pop .close-x:hover{background:#f3f4f6}" + ".subject-actions-pop .btn-row{display:grid;gap:.4rem;margin-top:.25rem}" + - ".subject-actions-pop a.action{display:block;text-decoration:none;padding:.45rem .55rem;border:1px solid #e5e7eb;border-radius:.45rem;color:#1f2937}" + + ".subject-actions-pop a.action{display:flex;align-items:center;gap:6px;text-decoration:none;padding:.45rem .55rem;border:1px solid #e5e7eb;border-radius:.45rem;color:#1f2937}" + ".subject-actions-pop a.action:hover{background:#f9fafb}" + - ".subject-actions-pop a.action[hidden]{display:none}"; + ".subject-actions-pop a.action[hidden]{display:none}" + + ".subject-actions-pop a.action svg{flex:0 0 auto}"; document.head.appendChild(style); popupEl = document.createElement('div'); popupEl.className = 'subject-actions-pop'; + + // Order: Insight, WOL, Database, Google, Wikipedia — with inline SVG icons popupEl.innerHTML = '
Open subject
' + '
' + - 'WOL Search' + - 'Insight Book' + - 'Wikipedia' + - 'Google' + - 'Database Search' + + // Insight Book (green book) + '' + + '' + + 'Search in Insight Book' + + '' + + + // WOL (watchtower-ish emblem) + '' + + '' + + 'Search in WOL' + + '' + + + // Database (stacked cylinders) + '' + + '' + + 'Search in Database' + + '' + + + // Google (colored G) + '' + + '' + + 'Search on Google' + + '' + + + // Wikipedia (W) + '' + + '' + + 'Search on Wikipedia' + + '' + '
'; + document.body.appendChild(popupEl); popupEl.querySelector('.close-x').addEventListener('click', hidePopup); @@ -127,28 +172,39 @@ return popupEl; } + function showPopup(x,y,links,options){ var el = ensurePopup(); el.style.left = x + 'px'; el.style.top = y + 'px'; - el.querySelector('.act-wol').href = links.wol; - el.querySelector('.act-wiki').href = links.wiki; - el.querySelector('.act-google').href = links.google; - el.querySelector('.act-db').href = links.db; + // Assign hrefs + var aInsight = el.querySelector('.act-insight'); + var aWol = el.querySelector('.act-wol'); + var aDb = el.querySelector('.act-db'); + var aGoogle = el.querySelector('.act-google'); + var aWiki = el.querySelector('.act-wiki'); + + if (aWol) aWol.href = links.wol; + if (aWiki) aWiki.href = links.wiki; + if (aGoogle) aGoogle.href = links.google; + if (aDb) aDb.href = links.db; // Insight visibility - var ins = el.querySelector('.act-insight'); - if (links.insight) { ins.removeAttribute('hidden'); ins.href = links.insight; } - else { ins.setAttribute('hidden',''); } + if (aInsight) { + if (links.insight) { aInsight.removeAttribute('hidden'); aInsight.href = links.insight; } + else { aInsight.setAttribute('hidden',''); } + } // DB visibility for >2 words - var db = el.querySelector('.act-db'); - if (options && options.enableDB) db.removeAttribute('hidden'); - else db.setAttribute('hidden',''); + if (aDb) { + if (options && options.enableDB) aDb.removeAttribute('hidden'); + else aDb.setAttribute('hidden',''); + } el.style.display = 'block'; } + function hidePopup(){ if (popupEl) popupEl.style.display = 'none'; } // ---- Click handler @@ -175,7 +231,7 @@ var insight = insightId ? insightURL(insightId) : null; var rect = pill.getBoundingClientRect(); - var x = rect.left + window.scrollX + rect.width/2 - 110; + var x = rect.left + window.scrollX + rect.width/2 - 120; // center-ish var y = rect.top + window.scrollY + rect.height + 6; showPopup(x, y, { wol:wol, wiki:wiki, google:goog, db:db, insight:insight }, { enableDB: dbEnabled });