MediaWiki:Common.js: Difference between revisions
Draft summary: use Biography section wording |
Pretty-case ALL-CAPS surnames in search suggestions and Special:Search results. |
||
| Line 384: | Line 384: | ||
return prettyNamePhrase(m[1], true) + ' (' + m[2] + ')'; | return prettyNamePhrase(m[1], true) + ' (' + m[2] + ')'; | ||
} | } | ||
if ( | function maybePrettySoldierTitle(label) { | ||
var text = $.trim(label || ''); | |||
if (!text || text.indexOf(',') === -1) { | |||
return text; | |||
} | |||
var sur = text.split(',')[0]; | |||
var letters = lettersOnly(sur); | |||
if (!(letters.length >= 2 && letters === letters.toUpperCase())) { | |||
return text; | |||
} | |||
return prettySoldierLabel(text); | |||
} | |||
function applyPrettySoldierLabels($links) { | |||
$links.each(function () { | |||
var $a = $(this); | var $a = $(this); | ||
var label = $a.text(); | var label = $a.text(); | ||
var pretty = maybePrettySoldierTitle(label); | |||
var pretty = | |||
if (pretty && pretty !== label) { | if (pretty && pretty !== label) { | ||
$a.text(pretty); | $a.text(pretty); | ||
$a.attr('title', pretty); | if ($a.attr('title') === label || !$a.attr('title')) { | ||
$a.attr('title', pretty); | |||
} | |||
} | } | ||
}); | }); | ||
} | } | ||
if (mw.config.get('wgNamespaceNumber') === 14) { | |||
applyPrettySoldierLabels($('.mw-category-group li a')); | |||
} | |||
if (mw.config.get('wgCanonicalSpecialPageName') === 'Search') { | |||
applyPrettySoldierLabels($('.mw-search-result-heading a')); | |||
} | |||
// Search box suggestions use the real page title; pretty-case ALL-CAPS surnames as they appear. | |||
(function watchSearchSuggestions() { | |||
function polish() { | |||
applyPrettySoldierLabels( | |||
$('.suggestions-result a, .suggestions-special a, .cdx-menu-item__text__label, .mw-searchSuggest-link') | |||
); | |||
$('.suggestions-result, .cdx-menu-item__text__label').each(function () { | |||
var $el = $(this); | |||
if ($el.is('a')) { | |||
return; | |||
} | |||
var label = $el.text(); | |||
var pretty = maybePrettySoldierTitle(label); | |||
if (pretty && pretty !== label) { | |||
$el.text(pretty); | |||
} | |||
}); | |||
} | |||
var root = document.body; | |||
if (!root || !window.MutationObserver) { | |||
return; | |||
} | |||
var obs = new MutationObserver(function () { | |||
polish(); | |||
}); | |||
obs.observe(root, { childList: true, subtree: true }); | |||
}()); | |||
$('.infobox th, .soldier-infobox th, table.wikitable td').each(function () { | $('.infobox th, .soldier-infobox th, table.wikitable td').each(function () { | ||