MediaWiki:Gadget-Tabs.js

/*	Simple but flexible javascript tabs Author: Abdullah A. Abduldayem Contact: http://www.zeldawiki.org/User:Abdullah See http://www.zeldawiki.org/MediaWiki_talk:Tabs.js for examples and documentation

$(document).ready(function{ // When a tab is clicked  $(".tab").click(function  {

var $alltabs = $(this).parent; var $content = $alltabs.parent.find('.tabcontents');

// switch all tabs off $alltabs.children.removeClass("active");

// switch this tab on   $(this).addClass("active");

// hide all content $content.children.css("display","none");

// show content corresponding to the tab var index = $alltabs.children.index(this); $content.children.eq(index).css("display","block"); });	});

function ShowTab(id,num,total) { document.getElementById('_'+id+num).style.display='block'; if (document.getElementById(id+num).className != 'tab tabselected') document.getElementById(id+num).className+=' tabselected';

for(var i=0;i<=total;i++) {		if(i!=num) {			document.getElementById('_'+id+i).style.display='none' document.getElementById(id+i).className = document.getElementById(id+i).className.replace(/\b tabselected\b/,'') }	} }

function tabstart { tabcontainer = getElementsByClassName(document, '*', 'tabcontainer'); tabcontents = getElementsByClassName(document, '*', 'tabcontents');

for(var x=0; x<=tabcontainer.length -1; x++) { tabcontainer[x].id = "tab-" + x + "-"; tabs = getElementsByClassName(tabcontainer[x], '*', 'tab'); contents = tabcontents[x].childNodes;

var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)); if(is_ie){ for(var y=0; y<=tabs.length -1; y++) { tabs[y].setAttribute('id', tabcontainer[x].id + y); tabs[y].setAttribute('onclick', "ShowTab('" + tabcontainer[x].id + "'," + y + "," + (tabs.length -1) + ");"); contents[y].setAttribute('id', '_' + tabcontainer[x].id + y); if (!contents[y].style.display) {contents[y].setAttribute('style', "display:none;");} }		}		else{ for(var y=0; y<=tabs.length -1; y++) { tabs[y].setAttribute('id', tabcontainer[x].id + y); tabs[y].setAttribute('onclick', "ShowTab('" + tabcontainer[x].id + "'," + y + "," + (tabs.length -1) + ");"); contents[y*2 +1].setAttribute('id', '_' + tabcontainer[x].id + y); if (!contents[y*2 +1].style.display) {contents[y*2 +1].setAttribute('style', "display:none;");} }		}

} } addOnloadHook(tabstart);