MediaWiki:ShowHide/code.js

/* */

/** Collapsible tables using jQuery * * Description: Allows tables to be collapsed, showing only the header. */ var autoCollapse; if( autoCollapse == undefined ) autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show";

function collapseTable( node ) { var $table = $(node); var $button = $table.find(".collapseButton"); if (!$table.length || !$button.length) { return false; }	var hidden = $table.find('tr:not(:first)').toggle.is(':hidden'); $button.text( hidden ? expandCaption : collapseCaption ); }

function createCollapseButtons { var NavigationBoxes = []; $("table.collapsible").each(function {		NavigationBoxes.push(this);		var $buttonLink = $(' ').text( collapseCaption )			.bind('click keypress', function(e) { if ( e.type === 'click' || ( e.type === 'keypress' && ( e.keyCode === 13 || e.charCode === 32 ) ) ) collapseTable( $(this).closest('table')[0] ); });		var $button = $(" ").css({ float: "right", textAlign: "right", fontWeight: "normal", width: "6em", marginLeft: "-100%" });		$button.append( '[' );		$button.append( $buttonLink[0] );		$button.append( ']' );

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

$( createCollapseButtons );

/* */

/* */

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

// set up the words in your language var NavigationBarHide = '[' + collapseCaption + ']'; var NavigationBarShow = '[' + expandCaption + ']';

// set up max count of Navigation Bars on page, // if there are more, all will be hidden // NavigationBarShowDefault = 0; // all bars will be hidden // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden var NavigationBarShowDefault = autoCollapse;

// shows and hides content and picture (if available) of navigation bars function toggleNavigationBar( node ) { var $navFrame = $(node); var $navToggle = $navFrame.find(".NavToggle"); if (!$navFrame.length || !$navToggle.length) { return false; }	var hidden = $navFrame.find('.NavPic, .NavContent').toggle.is(':hidden'); $navToggle.text( hidden ? NavigationBarShow : NavigationBarHide ); }

// adds show/hide-button to navigation bars function createNavigationBarToggleButton { var NavFrames = $('.NavFrame').each(function {		var $navHead = $(this).find('.NavHead:first');		$navHead.filter('legend').append(' - ');		$(" ").text(NavigationBarHide)			.bind('click keypress', function(e) { if ( e.type === 'click' || ( e.type === 'keypress' && ( e.keyCode === 13 || e.charCode === 32 ) ) ) toggleNavigationBar( $(this).closest('.NavFrame')[0] ); }).appendTo($navHead);	}); // if more Navigation Bars found than Default: hide all if (NavFrames.length >= NavigationBarShowDefault) NavFrames.not('.noautocollapse').each(function { toggleNavigationBar(this); }); else NavFrames.filter('.collapsed').each(function { toggleNavigationBar(this); }); }

$( createNavigationBarToggleButton );

/* */