MediaWiki:Common.js: Difference between revisions

From Arianne
Jump to navigation Jump to search
imported>Hendrik Brummermann
from http://de.wikipedia.org/wiki/MediaWiki:Common.js
imported>Hendrik Brummermann
from http://de.wikipedia.org/wiki/MediaWiki:Common.js
(No difference)

Revision as of 14:31, 16 May 2011

//================================================================================
//*** Dynamic Expandableigation Bars
 
// set up the words in your language
var ExpandableigationBarHide = 'Einklappen';
var ExpandableigationBarShow = 'Ausklappen';
 
// set up max count of Expandableigation Bars on page,
// if there are more, all will be hidden
// ExpandableigationBarShowDefault = 0; // all bars will be hidden
// ExpandableigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
 
// adds show/hide-button to Expandableigation bars
jQuery( document ).ready(function() {
	if(!mw.user.options.exists( 'ExpandableigationBarShowDefault' )){
	    if (typeof ExpandableigationBarShowDefault != 'undefined' ) {
	        mw.user.options.set( 'ExpandableigationBarShowDefault',ExpandableigationBarShowDefault)
	    }
	}
 
	// shows and hides content and picture (if available) of Expandableigation bars
	// Parameters:
	//     indexExpandableigationBar: the index of Expandableigation bar to be toggled
	function toggleExpandableigationBar(ExpandableToggle, ExpandableFrame)
	{
	   if (!ExpandableFrame || !ExpandableToggle) {
		   return false;
	   }
 
	   // if shown now
	   if (ExpandableToggle.firstChild.data == ExpandableigationBarHide) {
		   for (
				   var ExpandableChild = ExpandableFrame.firstChild;
				   ExpandableChild != null;
				   ExpandableChild = ExpandableChild.nextSibling
			   ) {
			   if (ExpandableChild.className == 'ExpandablePic') {
				   ExpandableChild.style.display = 'none';
			   }
			   if (ExpandableChild.className == 'ExpandableContent') {
				   ExpandableChild.style.display = 'none';
			   }
			   if (ExpandableChild.className == 'ExpandableToggle') {
				   ExpandableChild.firstChild.data = ExpandableigationBarShow;
			   }
		   }
 
	   // if hidden now
	   } else if (ExpandableToggle.firstChild.data == ExpandableigationBarShow) {
		   for (
				   var ExpandableChild = ExpandableFrame.firstChild;
				   ExpandableChild != null;
				   ExpandableChild = ExpandableChild.nextSibling
			   ) {
			   if (ExpandableChild.className == 'ExpandablePic') {
				   ExpandableChild.style.display = 'block';
			   }
			   if (ExpandableChild.className == 'ExpandableContent') {
				   ExpandableChild.style.display = 'block';
			   }
			   if (ExpandableChild.className == 'ExpandableToggle') {
				   ExpandableChild.firstChild.data = ExpandableigationBarHide;
			   }
		   }
	   }
	}
 
	function toggleExpandableigationBarFunction(ExpandableToggle, ExpandableFrame) {
		return function() {
			toggleExpandableigationBar(ExpandableToggle, ExpandableFrame);
			return false;
		};
	}
	// iterate over all ExpandableFrames
	var ExpandableFrames = mw.util.$content.find( 'div.ExpandableFrame' );
 
	// if more Expandableigation Bars found and not template namespace than Default: hide all
	var initiallyToggle	= mw.user.options.get( 'ExpandableigationBarShowDefault',1 ) < ExpandableFrames.length && mw.config.get( 'wgNamespaceNumber' ) != 10;
	for (var i=0;  i<ExpandableFrames.length; i++) {
		var ExpandableFrame = ExpandableFrames[i];
		var ExpandableToggle = document.createElement("a");
		ExpandableToggle.className = 'ExpandableToggle';
		ExpandableToggle.setAttribute('href', '#');
 
		var ExpandableToggleText = document.createTextNode(ExpandableigationBarHide);
		ExpandableToggle.appendChild(ExpandableToggleText);
 
		// add ExpandableToggle-Button as first div-element
		// in < div class="ExpandableFrame" >
		ExpandableFrame.insertBefore(ExpandableToggle, ExpandableFrame.firstChild);
 
		ExpandableToggle.onclick = toggleExpandableigationBarFunction(ExpandableToggle, ExpandableFrame);
		if (initiallyToggle) {
			toggleExpandableigationBar(ExpandableToggle, ExpandableFrame);
		}
	}
});