MediaWiki:Common.js: Difference between revisions
OCR clear ready queue button |
Hide (merged duplicate) titles from find/search suggestions and results |
||
| Line 7: | Line 7: | ||
* with live title suggestions (same idea as the header search box). | * with live title suggestions (same idea as the header search box). | ||
* Reorder Special:Search hits so title matches and site pages rank above research-notes noise. | * Reorder Special:Search hits so title matches and site pages rank above research-notes noise. | ||
* Hide retired “(merged duplicate)” roster pages from find/search suggestions and results. | |||
*/ | */ | ||
function rbIsMergedDuplicateTitle(title) { | |||
return /\(merged duplicate\)\s*$/i.test(String(title || '')); | |||
} | |||
$(function () { | $(function () { | ||
(function buildHomeFind() { | (function buildHomeFind() { | ||
| Line 111: | Line 116: | ||
function rankTitles(query, hits) { | function rankTitles(query, hits) { | ||
var q = String(query || '').trim().toLowerCase(); | var q = String(query || '').trim().toLowerCase(); | ||
var scored = (hits || []).map(function (h) { | var scored = (hits || []).filter(function (h) { | ||
return !rbIsMergedDuplicateTitle(h.title || ''); | |||
}).map(function (h) { | |||
var t = h.title || ''; | var t = h.title || ''; | ||
var low = t.toLowerCase(); | var low = t.toLowerCase(); | ||
| Line 284: | Line 291: | ||
function resort(siteTitles) { | function resort(siteTitles) { | ||
var items = $list.children('li').get(); | var items = $list.children('li').get(); | ||
items.forEach(function (el) { | |||
if (rbIsMergedDuplicateTitle(titleFromItem(el))) { | |||
$(el).remove(); | |||
} | |||
}); | |||
items = $list.children('li').get(); | |||
if (items.length < 2) { | if (items.length < 2) { | ||
return; | return; | ||
| Line 780: | Line 793: | ||
(function watchSearchSuggestions() { | (function watchSearchSuggestions() { | ||
function polish() { | function polish() { | ||
$('.suggestions-result, .suggestions-result a, .suggestions-special a, .cdx-menu-item, .mw-searchSuggest-link').each(function () { | |||
var $el = $(this); | |||
var label = $.trim($el.text() || ''); | |||
if (rbIsMergedDuplicateTitle(label)) { | |||
$el.closest('li, .cdx-menu-item, .suggestions-result').addBack().filter('li, .cdx-menu-item, .suggestions-result').first().hide(); | |||
} | |||
}); | |||
applyPrettySoldierLabels( | applyPrettySoldierLabels( | ||
$('.suggestions-result a, .suggestions-special a, .cdx-menu-item__text__label, .mw-searchSuggest-link') | $('.suggestions-result a, .suggestions-special a, .cdx-menu-item__text__label, .mw-searchSuggest-link') | ||
| Line 1,702: | Line 1,722: | ||
redirects: 'resolve' | redirects: 'resolve' | ||
}).then(function (data) { | }).then(function (data) { | ||
var titles = (data && data[1]) || []; | var titles = ((data && data[1]) || []).filter(function (t) { | ||
return !rbIsMergedDuplicateTitle(t); | |||
}); | |||
$suggest.empty(); | $suggest.empty(); | ||
if (!titles.length) { | if (!titles.length) { | ||