MediaWiki:Common.js: Difference between revisions
Hide (merged duplicate) titles from find/search suggestions and results |
Books filters, Still needed checklist, related-media wrap |
||
| Line 2,996: | Line 2,996: | ||
}); | }); | ||
}); | }); | ||
(function rbBooksFilters() { | |||
var $filters = $('.books-filters'); | |||
if (!$filters.length) return; | |||
$filters.on('click', '.books-filter', function () { | |||
var kind = $(this).data('filter'); | |||
$filters.find('.books-filter').removeClass('is-active'); | |||
$(this).addClass('is-active'); | |||
$('.notable-slides .notable-slide-card[data-book-kind]').each(function () { | |||
var k = $(this).attr('data-book-kind'); | |||
var show = kind === 'all' || k === kind; | |||
$(this).toggleClass('is-book-hidden', !show); | |||
}); | |||
}); | |||
}()); | |||
(function rbSoldierNeeds() { | |||
var $out = $('.mw-parser-output').first(); | |||
if (!$out.length || !$out.find('table.soldier-infobox, table.infobox').length) return; | |||
if ($out.find('.soldier-needs').length) return; | |||
var bioText = ''; | |||
$out.find('h2').each(function () { | |||
var t = $.trim($(this).find('.mw-headline').text() || $(this).text()); | |||
if (!/^Biography\b/i.test(t)) return; | |||
var $n = $(this).next(); | |||
while ($n.length && !$n.is('h2')) { | |||
bioText += ' ' + $n.text(); | |||
$n = $n.next(); | |||
} | |||
}); | |||
bioText = $.trim(bioText); | |||
var thinBio = !bioText || bioText.length < 280 || /add a biography|placeholder|coming soon/i.test(bioText); | |||
var hasPhoto = $out.find('table.soldier-infobox img, table.infobox img').length > 0; | |||
var needs = []; | |||
if (!hasPhoto) needs.push('A confirmed portrait for the profile photo'); | |||
if (thinBio) needs.push('A short sourced Biography paragraph (and Sources bullet)'); | |||
var box = ($out.find('table.soldier-infobox, table.infobox').first().text() || ''); | |||
if (!/\b\d{1,2} (January|February|March|April|May|June|July|August|September|October|November|December) \d{4}\b/.test(box)) { | |||
needs.push('Full birth and/or death dates when publicly known'); | |||
} | |||
if (!/Team|IPW/i.test(box)) { | |||
needs.push('Team / IPW assignment if known from a roster'); | |||
} | |||
if (!needs.length) return; | |||
var $lead = $out.find('.soldier-lead, .page-lead').first(); | |||
var $box = $('<div class="soldier-needs"></div>'); | |||
$box.append($('<div class="soldier-needs-title"></div>').text('Still needed for this profile')); | |||
var $ul = $('<ul></ul>'); | |||
needs.forEach(function (n) { $ul.append($('<li></li>').text(n)); }); | |||
$box.append($ul); | |||
$box.append($('<p></p>').html('Families: see <a href="/index.php?title=For_families">For families</a>. Editors: <a href="/index.php?title=Contribute">Contribute</a>.')); | |||
if ($lead.length) $lead.after($box); | |||
else $out.prepend($box); | |||
}()); | |||
(function rbRelatedMediaWrap() { | |||
var $out = $('.mw-parser-output').first(); | |||
if (!$out.length) return; | |||
var $cues = $out.find('.soldier-story-cue, .soldier-media-cue'); | |||
if ($cues.length < 1) return; | |||
if ($out.find('.soldier-related-media').length) return; | |||
var $wrap = $('<div class="soldier-related-media"><div class="soldier-needs-title">Related media</div></div>'); | |||
$cues.first().before($wrap); | |||
$cues.appendTo($wrap); | |||
}()); | |||