MediaWiki:Common.js

/** Collapsible tables using jQuery *	 * Description: Allows tables to be collapsed, showing only the header. */	function collapseTable( node, state ) { var $table = $(node); var $button = $table.find("tr:first > th:first .collapseLink"); if (!$table.length || !$button.length) { return false; }		if ( typeof state === 'boolean' ) $table.toggleClass('collapsed', !state); else $table.toggleClass('collapsed'); var hidden = $table.hasClass('collapsed'); $table.find('> * > tr:not(:first):not(.nocollapse)')[hidden?"hide":"show"]; $button.text( msg( hidden ? "show" : "hide" ) ); }

function createCollapseButtons { var NavigationBoxes = []; $("table.collapsible").each(function {			NavigationBoxes.push(this);			var $buttonLink = $(' ').text( msg("hide") )                               .css({ cursor: "pointer" })				.onLink(function(e) { collapseTable( $(this).closest('table') ); });			var $button = $(" ").css({ "float": "right", textAlign: "right", fontWeight: "normal", width: "6em", marginLeft: "-100%" });			$button.append( document.createTextNode(config.brackets.substr(0, config.brackets.length/2)), $buttonLink, config.brackets.substr(config.brackets.length/2) );

var $header = $(this).find('tr:first > th:first').prepend($button); });		// if more Navigation Bars found than Default: hide all		if ($(NavigationBoxes).filter('.autocollapse').length >= config.autoCollapse)			$(NavigationBoxes).filter('.autocollapse').each(function { collapseTable( this, false ); });		else			$(NavigationBoxes).filter('.collapsed').each(function { collapseTable( this, false ); });	}

$( createCollapseButtons );

/* */

/* */

/** Dynamic Navigation Bars with jQuery *	 * Base Description: See Wikipedia:Wikipedia:NavFrame. */

// shows and hides content and picture (if available) of navigation bars function toggleNavigationBar( node ) { var $navFrame = $(node); var $navToggle = $navFrame.find(".NavHead:first .collapseLink"); if (!$navFrame.length || !$navToggle.length) { return false; }		$navFrame.toggleClass('NavVisible'); $navFrame.find('.NavPic, .NavContent').not($navFrame.find('.NavFrame .NavPic, .NavFrame .NavContent')).slideToggle; $navToggle.text( msg( $navFrame.hasClass('NavVisible') ? "hide" : "show" ) ); }

// adds show/hide-button to navigation bars function createNavigationBarToggleButton { var NavFrames = $('.NavFrame').addClass('NavVisible').each(function {			var $navHead = $(this).find('.NavHead:first');			$navHead.filter('legend').append(' - ');			var $buttonLink = $(' ').text( msg("hide") )				.onLink(function(e) { toggleNavigationBar( $(this).closest('.NavFrame') ); });			var $button = $(' ')			if ( config.brackets )				$button.append( document.createTextNode(config.brackets.substr(0, config.brackets.length/2)), $buttonLink, config.brackets.substr(config.brackets.length/2) );			else				$button.append( $buttonLink );			$navHead[config.linkBefore?"prepend":"append"]($button);		}); // if more Navigation Bars found than Default: hide all if (NavFrames.length >= config.autoCollapse) NavFrames.not('.noautocollapse').each(function { toggleNavigationBar(this); }); else NavFrames.filter('.collapsed').each(function { toggleNavigationBar(this); }); }

$( createNavigationBarToggleButton );

$(function {		$('.NavGlobal').each(function { $(' ').append(				document.createTextNode('['),				$(' ').text( msg("showAll") ).onLink(function(e) { $('.NavFrame').each(function { if ( !$(this).hasClass('NavVisible') ) toggleNavigationBar(this); }); }),				']'			).appendTo(this); $(this).append(' '); $(' ').append(				document.createTextNode('['),				$(' ').text( msg("hideAll") ).onLink(function(e) { $('.NavFrame').each(function { if ( $(this).hasClass('NavVisible') ) toggleNavigationBar(this); }); }),				']'			).appendTo(this); });	}); })(jQuery);