MediaWiki:Common.js: Difference between revisions
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 | // Ribbon racks belong in the main column after Biography (like Wikipedia's | ||
// | // 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 | if (!$out.length) { | ||
return; | return; | ||
} | } | ||
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 () { | |||
if ($awards.length && !$awards.data('rbAwardsPlaced')) { | |||
$awards.data('rbAwardsPlaced', 1); | |||
var $bio = $out.find('h2').filter(function () { | |||
var t = $(this).find('.mw-headline').text() || $(this).text(); | |||
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 $ | |||
var | // Contents box belongs near the top (after lead), never under Biography. | ||
var $toc = $out.find('#toc, .toc, .mw-table-of-contents').first(); | |||
if ($toc.length && !$toc.data('rbTocPlaced')) { | |||
$toc.data('rbTocPlaced', 1); | |||
var $lead = $out.find('.soldier-lead').first(); | |||
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); | |||
} | |||
} | |||
} | } | ||
}()); | }()); | ||