User:Inductiveload/InlinePagenums.js

/* Javascript to show page numbers of transcluded text in the text
 * itself. This is common in come legal works
 */
function setInlinePagenumsButton() {
	if(mw.config.get('wgNamespaceNumber') !== 0 && mw.config.get('wgNamespaceNumber') != 2 )
		return;

	if (!$('#optlist').length || !$('.pagenum').length )
		return; //we don't have any layout menu or we don't have pages

	enabledNow = $.cookie("showInlinePagenums") === '1';

	text = enabledNow ? 'Hide inline page numbers' : 'Show inline page numbers' ;
	link = 'javascript:showInlinePagenums('+!enabledNow+');';

	if (!$('#option-inlinePagenums').length )
		$('#optlist').append( '<li id="option-inlinePagenums"><a href="'+link+'">'+text+'</a></li>');
	else
		$('#option-inlinePagenums>a').text(text).attr('href', link);
}

function showInlinePagenums(show) {
	if (show === undefined)
	show = $.cookie("showInlinePagenums") === '1';

	$.cookie("showInlinePagenums", show ? '1' : 0);

	$.each($('.pagenum'), function(index, num) {
		$(num).text(show ? ' ['+$(num).attr('id')+'] ' : '');
	});

	setInlinePagenumsButton();
}

$(function() { setTimeout(showInlinePagenums, 100) }); //hacky hacky