User:Inductiveload/InlinePagenums.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/* 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