Place awards section after biography
Place TOC after lead; awards after biography
Line 29: Line 29:


(function placeSoldierAwardsSection() {
(function placeSoldierAwardsSection() {
// Ribbon racks belong in the main column (like Wikipedia), not beside the
// Ribbon racks belong in the main column after Biography (like Wikipedia's
// floated infobox. Move after Biography / Life, else before Gallery/Sources.
// Awards section). Do not use a wiki == heading here — that stole the TOC.
var $out = $('.mw-parser-output').first();
var $out = $('.mw-parser-output').first();
var $awards = $out.find('.soldier-awards-section').first();
var $awards = $out.find('.soldier-awards-section').first();
if (!$out.length || !$awards.length || $awards.data('rbAwardsPlaced')) {
if (!$out.length) {
return;
return;
}
}
$awards.data('rbAwardsPlaced', 1);
 
function sectionAfter($h) {
function sectionAfter($h) {
var $nodes = $h.nextUntil('h2');
var $nodes = $h.nextUntil('h2');
Line 44: Line 44:
return $h;
return $h;
}
}
var $bio = $out.find('h2').filter(function () {
 
var t = $(this).find('.mw-headline').text() || $(this).text();
if ($awards.length && !$awards.data('rbAwardsPlaced')) {
return /^(Biography|Life)\b/i.test($.trim(t));
$awards.data('rbAwardsPlaced', 1);
}).first();
var $bio = $out.find('h2').filter(function () {
if ($bio.length) {
var t = $(this).find('.mw-headline').text() || $(this).text();
sectionAfter($bio).after($awards);
return /^(Biography|Life)\b/i.test($.trim(t));
return;
}).first();
if ($bio.length) {
sectionAfter($bio).after($awards);
} else {
var $before = $out.find('h2').filter(function () {
var t = $(this).find('.mw-headline').text() || $(this).text();
return /^(Gallery|Research notes|Sources|Technical record)\b/i.test($.trim(t));
}).first();
if ($before.length) {
$before.before($awards);
} else {
$out.append($awards);
}
}
}
}
var $before = $out.find('h2').filter(function () {
 
var t = $(this).find('.mw-headline').text() || $(this).text();
// Contents box belongs near the top (after lead), never under Biography.
return /^(Gallery|Research notes|Sources|Technical record)\b/i.test($.trim(t));
var $toc = $out.find('#toc, .toc, .mw-table-of-contents').first();
}).first();
if ($toc.length && !$toc.data('rbTocPlaced')) {
if ($before.length) {
$toc.data('rbTocPlaced', 1);
$before.before($awards);
var $lead = $out.find('.soldier-lead').first();
return;
if ($lead.length) {
$lead.after($toc);
} else {
var $ibox = $out.find('table.soldier-infobox, table.infobox').first();
if ($ibox.length) {
$ibox.after($toc);
} else {
$out.prepend($toc);
}
}
}
}
$out.append($awards);
}());
}());