Advanced Search/Preview

From Bodhicitta
< Advanced Search
Revision as of 18:59, 2 October 2026 by Jeremi (talk | contribs) (Preview page for the new site search)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Preview of the new site search. The current form is still at Advanced Search.
Search
Everything on the Bodhicitta website

Try tonglen, Santideva (accents optional), 9.1 (a verse), "bodhicitta of aspiration" (exact phrase) or བྱང་ཆུབ་སེམས.
Search tips
' : '
') + '
' + link(h.title, esc(title)) + '
' + (cit ? '
' + link(h.title, cit) + '
' : '') + '
' + (cls ? '' + esc(cls) + '' : '') + (date ? '' + esc(date) + '' : '') + '
' + (h.snippet ? '
…' + h.snippet + '…
' : '') + '
'; }).join(''); } // Where a passage sits in its bilingual layout: the same rules as the // citations panel (Module:SscCitations bilingualLink). var SINGLE_PAGE_BILINGUAL = { '013-Tsadra-BCA-Com-Minyak-Ch9': 1, '011-Tsadra-BCA-Com-Pawo': 1 }; var NAMED_BILINGUAL_SUBPAGE = { '020-Tsadra-BC-Root-Bhavanakrama-1': 'Bhavanakrama-1', '020-Tsadra-BC-Root-Bhavanakrama-2': 'Bhavanakrama-2', '020-Tsadra-BC-Root-Bhavanakrama-3': 'Bhavanakrama-3' }; function bilingual(po, title) { var tm = first(po, 'TransMemID') || title.split('/')[0].replace('Translation Memory:', ''); var base = first(po, 'TranslationWikiPage'), ch = first(po, 'TranslationChapter'); var ord = String(first(po, 'SegmentOrder') || first(po, 'SourceSegmentOrder') || '').replace(/,/g, ''); if (!base) { base = first(po, 'SourceWikiPage'); return base ? mw.util.getUrl(base) : ''; } if (!ord) return mw.util.getUrl(base + '/Bilingual'); if (NAMED_BILINGUAL_SUBPAGE[tm]) return mw.util.getUrl(base + '/Bilingual/' + NAMED_BILINGUAL_SUBPAGE[tm]) + '#seg-' + ord; if (SINGLE_PAGE_BILINGUAL[tm] || !ch) return mw.util.getUrl(base + '/Bilingual') + '#seg-' + ord; return mw.util.getUrl(base + '/Bilingual/' + ch) + '#seg-' + ord; } function renderPassages(hits, data) { return hits.map(function (h) { var po = (data[h.title] || {}).printouts || {}; var work = first(po, 'TranslationWikiPage') || h.title.split('/')[0].replace('Translation Memory:', ''); var ch = first(po, 'TranslationChapter'), href = bilingual(po, h.title); return '
' + '
' + (ch ? 'Chapter ' + esc(ch) + '' : '') + 'passage ' + esc(h.title.split('/').pop()) + '' + (href ? 'bilingual view' : '') + '
' + (h.snippet ? '
…' + h.snippet + '…
' : '') + '
'; }).join(''); } function renderPlain(hits) { return hits.map(function (h) { var name = h.title.replace(/^(Topics|People|Explore|Study|Discover|Practice)\//, ''); return '
' + link(h.title, esc(name)) + '
' + (h.snippet ? '
…' + h.snippet + '…
' : '') + '
'; }).join(''); } function renderTabs() { var html = GROUPS.map(function (g) { return ''; }).join(''); $('#bcas-tabs').html(html).prop('hidden', false); } function renderPills(classCounts) { if (state.tab !== 'library') { $('#bcas-pills').prop('hidden', true); return; } var html = 'All ' + fmt(counts.library) + ''; CLASSES.forEach(function (c) { var n = classCounts[c]; if (!n) return; html += '' + esc(c) + ' ' + fmt(n) + ''; }); $('#bcas-pills').html(html).prop('hidden', false); } function shortcut() { var m = state.q.trim().match(/^(\d{1,2})\.(\d{1,3})$/); if (!m) { $('#bcas-shortcut').empty(); return; } var v = m[1] + '.' + m[2]; $('#bcas-shortcut').html('
Looking for Bodhicaryāvatāra verse ' + esc(v) + '? ' + link('Texts/Bodhicaryāvatāra/Verses/' + v, 'Open the verse page') + ' (sources, translations, commentaries) or the ' + link('Topics/BCA ' + v, 'topic page for BCA ' + v) + ' (works on this verse).
'); } function writeUrl() { var u = new URL(location.href); ['q', 'tab', 'class'].forEach(function (k) { u.searchParams.delete(k); }); if (state.q) u.searchParams.set('q', state.q); if (state.q && state.tab !== 'library') u.searchParams.set('tab', state.tab); if (state.cls) u.searchParams.set('class', state.cls); history.replaceState(null, '', u.toString()); } function loadList(append) { var my = ++token; var g = GROUPS.filter(function (x) { return x.id === state.tab; })[0]; if (!append) { state.offset = 0; $('#bcas-list').empty(); } $('#bcas-more').prop('hidden', true); $('#bcas-status').text('Searching…'); var key = state.q + '|' + state.cls; var cached = (g.id === 'library' && state.cls && state.offset === 0 && firstPages[key]); return (cached ? $.Deferred().resolve(cached).promise() : search(g, g.id === 'library' ? state.cls : '', state.offset, PAGE)).then(function (r) { if (my !== token) return; var hits = r.search || []; if (g.id === 'passages') hits = hits.filter(function (h) { return h.title.indexOf('/') > -1; }); var total = r.searchinfo ? r.searchinfo.totalhits : hits.length; var titles = hits.map(function (h) { return h.title; }); var p; if (g.id === 'library') { // Covers load lazily from Special:Redirect, so the rows do not wait on an // image lookup (the files live on Commons, which can be slow). p = ask(titles, '|?Citation|?Class|?Pubdate|?Title|?FrontCoverImg').then(function (data) { var th = {}; titles.forEach(function (t) { var f = first(((data[t] || {}).printouts) || {}, 'FrontCoverImg'); if (f) th[f] = mw.util.getUrl('Special:Redirect/file/' + f.replace(/^File:/, ''), { width: 120 }); }); return renderLibrary(hits, data, th); }); } else if (g.id === 'passages') { p = ask(titles, '|?TranslationWikiPage|?TranslationChapter|?SegmentOrder|?SourceSegmentOrder|?TransMemID|?SourceWikiPage').then(function (data) { return renderPassages(hits, data); }); } else { p = $.Deferred().resolve(renderPlain(hits)).promise(); } return p.then(function (html) { if (my !== token) return; if (!total) { $('#bcas-list').html('
Nothing found in ' + esc(g.label.toLowerCase()) + '. Try another group above, fewer words, or a different spelling.
'); $('#bcas-status').text(''); return; } $('#bcas-list').append(html); state.offset += PAGE; window.setTimeout(refine, 0); var shown = Math.min(state.offset, total); $('#bcas-status').text('Showing ' + fmt(shown) + ' of ' + fmt(total) + ' in ' + g.label.toLowerCase() + (state.cls ? ' · ' + state.cls : '') + '.'); $('#bcas-more').prop('hidden', state.offset >= total); }); }).fail(function () { if (my !== token) return; $('#bcas-status').text('The search could not run just now. Please try again in a moment.'); }); } // Narrow the rows already shown, without a new search (accents ignored). function fold(s) { return String(s).normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(); } function refine() { var v = fold($('#bcas-filter').val().trim()), shown = 0, all = 0; $('#bcas-list').children('.topic-biblio-row, .bcas__hit').each(function () { var ok = !v || fold($(this).text()).indexOf(v) > -1; $(this).toggle(ok); all++; if (ok) shown++; }); $('#bcas-filtered').remove(); if (v) $('#bcas-status').append(' ' + fmt(shown) + ' of the ' + fmt(all) + ' shown match the filter.'); } function run() { state.q = $('#bcas-q').val().trim(); writeUrl(); shortcut(); if (!state.q) { $('#bcas-tabs,#bcas-pills,#bcas-more,#bcas-refine').prop('hidden', true); $('#bcas-list,#bcas-status').empty(); $('#bcas-hint, #bcas-start').show(); return; } $('#bcas-hint, #bcas-start').hide(); $('#bcas-refine').prop('hidden', false); $('#bcas-filter').val(''); counts = {}; renderTabs(); // The results come first; the counts follow once they are on screen, so the // first page is not queued behind eleven count searches (and a class button // clicked early does not wait behind them either). var listDone = loadList(false) || $.Deferred().resolve().promise(); listDone.always(function () { $.when.apply($, GROUPS.map(function (g) { return search(g, '', 0, 1).then(function (r) { counts[g.id] = r.searchinfo.totalhits; }, function () { counts[g.id] = 0; }); })).always(function () { renderTabs(); if (state.tab === 'library') { var cc = {}; $.when.apply($, CLASSES.map(function (c) { return search(GROUPS[0], c, 0, PAGE).then(function (r) { cc[c] = r.searchinfo.totalhits; firstPages[state.q + '|' + c] = r; }, function () {}); })).always(function () { renderPills(cc); }); } }); }); } $(function () { var params = new URL(location.href).searchParams; state.tab = params.get('tab') || 'library'; state.cls = params.get('class') || ''; $('#bcas-q').val(params.get('q') || ''); $('#bcas-form').on('submit', function (e) { e.preventDefault(); state.cls = ''; run(); }); // Clearing the box (its x, or deleting the text) returns to the browse panels. $('#bcas-q').on('input search', function () { if (!this.value.trim() && state.q) { state.cls = ''; state.tab = 'library'; run(); } }); $('.bcas__tips').on('click', 'a[data-q]', function () { $('#bcas-q').val($(this).attr('data-q')); state.cls = ''; run(); }); $('#bcas-hint').on('click', 'a[data-q]', function () { $('#bcas-q').val($(this).attr('data-q')); state.cls = ''; run(); }); $('#bcas-tabs').on('click', '.bcas__tab', function () { state.tab = $(this).data('tab'); state.cls = ''; writeUrl(); renderTabs(); $('#bcas-pills').prop('hidden', true); if (state.tab === 'library') run(); else loadList(false); }); $('#bcas-pills').on('click', '.topic-biblio-pill', function () { state.cls = $(this).attr('data-cls') || ''; $('#bcas-pills .topic-biblio-pill').removeClass('is-active'); $(this).addClass('is-active'); writeUrl(); loadList(false); }); $('#bcas-more').on('click', function () { loadList(true); }); $('#bcas-filter').on('input', refine); // Whole row opens its first link, unless a link inside it was clicked or text selected. $('#bcas-list').on('click', '.topic-biblio-row, .bcas__hit', function (e) { if ($(e.target).closest('a').length || String(window.getSelection())) return; var a = $(this).find('a').get(0); if (!a) return; if (e.metaKey || e.ctrlKey) window.open(a.href, '_blank'); else location.href = a.href; }); // The start panel (in the page) can launch searches too. $(document).on('click', '#bcas-start [data-q]', function (e) { e.preventDefault(); $('#bcas-q').val($(this).attr('data-q')); state.cls = $(this).attr('data-class') || ''; state.tab = $(this).attr('data-tab') || 'library'; run(); window.scrollTo({ top: $('#bcas').offset().top - 90, behavior: 'smooth' }); }); if ($('#bcas-q').val()) run(); else { $('#bcas-start').show(); $('#bcas-q').trigger('focus'); } }); }]);