MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
K Änderung 83227 von Hessentotal (Diskussion) rückgängig gemacht.
Markierung: Rückgängigmachung
KKeine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/**
//================================================================================
* Dynamic Navigation Bars. See [[Wikipedia:NavFrame]]
//*** Dynamic Navigation Bars
*
* Based on script from en.wikipedia.org, 2008-09-15.
*
* @source www.mediawiki.org/wiki/MediaWiki:Gadget-NavFrame.js
* @maintainer Helder.wiki, 2012–2013
* @maintainer Krinkle, 2013
*/
( function () {


// Set up the words in your language
// set up max count of Navigation Bars on page,
var autoCollapse = 0;
// if there are more, all will be hidden
var collapseCaption = 'Einklappen';
// mw.user.options.set( 'NavigationBarShowDefault', 0 ); // all bars will be hidden
var expandCaption = 'Ausklappen';
// mw.user.options.set( 'NavigationBarShowDefault', 1 ); // on pages with more than 1 bar all bars will be hidden


var navigationBarHide = '[' + collapseCaption + ']';
// adds show/hide-button to navigation bars
var navigationBarShow = '[' + expandCaption + ']';
// using 'jquery.makeCollapsible': for messages
// using 'user', 'mediawiki.user', 'user.options': wait for overrides in user.js
mw.loader.using( [ 'jquery.makeCollapsible', 'user', 'mediawiki.user', 'user.options' ], function() { mw.hook( 'wikipage.content' ).add( function( $content ) {
// allow setting NavigationBarShowDefault
var showDefaultCount = mw.user.options.get( 'NavigationBarShowDefault',
typeof NavigationBarShowDefault !== 'undefined' ? NavigationBarShowDefault : 1 );
// allow user overrides for b/c
var textHide = typeof NavigationBarHide === 'string' ? NavigationBarHide : mw.msg( 'collapsible-collapse' );
var textShow = typeof NavigationBarShow === 'string' ? NavigationBarShow : mw.msg( 'collapsible-expand' );


/**
// shows and hides content and picture (if available) of navigation bars
* Shows and hides content and picture (if available) of navigation bars.
// Parameters:
*
//    indexNavigationBar: the index of navigation bar to be toggled
* @param {number} indexNavigationBar The index of navigation bar to be toggled
function toggleNavigationBar(NavToggle, NavFrame)
* @param {jQuery.Event} e Event object
{
*/
if (!NavFrame || !NavToggle) {
function toggleNavigationBar( indexNavigationBar, e ) {
return false;
var navChild,
}
navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),
navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );


// Prevent browser from jumping to href "#"
// if shown now
e.preventDefault();
if (NavToggle.firstChild.data === textHide) {
for (
var NavChild = NavFrame.firstChild;
NavChild !== null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = textShow;


if ( !navFrame || !navToggle ) {
// if hidden now
return false;
} else if (NavToggle.firstChild.data === textShow) {
}
for (
 
var NavChild = NavFrame.firstChild;
// If shown now
NavChild !== null;
if ( navToggle.firstChild.data === navigationBarHide ) {
NavChild = NavChild.nextSibling
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
) {
if ( $( navChild ).hasClass( 'NavContent' ) || $( navChild ).hasClass( 'NavPic' ) ) {
if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
navChild.style.display = 'none';
NavChild.style.display = 'block';
}
}
}
NavToggle.firstChild.data = textHide;
}
}
navToggle.firstChild.data = navigationBarShow;
}


// If hidden now
function toggleNavigationBarFunction(NavToggle, NavFrame) {
} else if ( navToggle.firstChild.data === navigationBarShow ) {
return function() {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
toggleNavigationBar(NavToggle, NavFrame);
if ( $( navChild ).hasClass( 'NavContent' ) || $( navChild ).hasClass( 'NavPic' ) ) {
return false;
navChild.style.display = 'block';
};
}
}
navToggle.firstChild.data = navigationBarHide;
}
}
}
// iterate over all NavFrames
var NavFrames = $content.find( 'div.NavFrame' );
 
// if more Navigation Bars found and not template namespace than Default: hide all
var initiallyToggle = showDefaultCount < NavFrames.length && mw.config.get( 'wgNamespaceNumber' ) !== 10;
for (var i=0; i<NavFrames.length; i++) {
var NavFrame = NavFrames[i];
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('href', '#');
 
var NavToggleText = document.createTextNode(textHide);
NavToggle.appendChild(NavToggleText);


/**
// add NavToggle-Button as first div-element
* Adds show/hide-button to navigation bars.
// in < div class="NavFrame" >
*
NavFrame.insertBefore(NavToggle, NavFrame.firstChild);
* @param {jQuery} $content
*/
function createNavigationBarToggleButton( $content ) {
var i, j, navChild, navToggle, navToggleText, isCollapsed,
indexNavigationBar = 0;
// iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame' );
$divs.each( function ( i, navFrame ) {
indexNavigationBar++;
navToggle = document.createElement( 'a' );
navToggle.className = 'NavToggle';
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );


isCollapsed = $( navFrame ).hasClass( 'collapsed' );
NavToggle.onclick = toggleNavigationBarFunction(NavToggle, NavFrame);
// backwards compatibility for old technique where the collapsed class was not yet used
if (initiallyToggle) {
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
toggleNavigationBar(NavToggle, NavFrame);
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
} else { // make sure that 'display' is always set for every NavFrame
if ( navChild.style.display === 'none' ) {
for (
isCollapsed = true;
var NavChild = NavFrame.firstChild;
NavChild !== null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
NavChild.style.display = 'block';
}
}
}
}
}
}
if ( isCollapsed ) {
}
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
})});
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'none';
}
}
}
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
navToggle.appendChild( navToggleText );
 
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for ( j = 0; j < navFrame.childNodes.length; j++ ) {
if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
navToggle.style.color = navFrame.childNodes[j].style.color;
navFrame.childNodes[j].appendChild( navToggle );
}
}
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
} );
}
 
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
 
}());

Version vom 25. Januar 2021, 16:49 Uhr

//================================================================================
//*** Dynamic Navigation Bars

// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// mw.user.options.set( 'NavigationBarShowDefault', 0 ); // all bars will be hidden
// mw.user.options.set( 'NavigationBarShowDefault', 1 ); // on pages with more than 1 bar all bars will be hidden

// adds show/hide-button to navigation bars
// using 'jquery.makeCollapsible': for messages
// using 'user', 'mediawiki.user', 'user.options': wait for overrides in user.js
mw.loader.using( [ 'jquery.makeCollapsible', 'user', 'mediawiki.user', 'user.options' ], function() { mw.hook( 'wikipage.content' ).add( function( $content ) {
	// allow setting NavigationBarShowDefault
	var showDefaultCount = mw.user.options.get( 'NavigationBarShowDefault',
		typeof NavigationBarShowDefault !== 'undefined' ? NavigationBarShowDefault : 1 );
	// allow user overrides for b/c
	var textHide = typeof NavigationBarHide === 'string' ? NavigationBarHide : mw.msg( 'collapsible-collapse' );
	var textShow = typeof NavigationBarShow === 'string' ? NavigationBarShow : mw.msg( 'collapsible-expand' );

	// shows and hides content and picture (if available) of navigation bars
	// Parameters:
	//     indexNavigationBar: the index of navigation bar to be toggled
	function toggleNavigationBar(NavToggle, NavFrame)
	{
		if (!NavFrame || !NavToggle) {
			return false;
		}

		// if shown now
		if (NavToggle.firstChild.data === textHide) {
			for (
					var NavChild = NavFrame.firstChild;
					NavChild !== null;
					NavChild = NavChild.nextSibling
				) {
				if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
					NavChild.style.display = 'none';
				}
			}
			NavToggle.firstChild.data = textShow;

		// if hidden now
		} else if (NavToggle.firstChild.data === textShow) {
			for (
					var NavChild = NavFrame.firstChild;
					NavChild !== null;
					NavChild = NavChild.nextSibling
				) {
				if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
					NavChild.style.display = 'block';
				}
			}
			NavToggle.firstChild.data = textHide;
		}
	}

	function toggleNavigationBarFunction(NavToggle, NavFrame) {
		return function() {
			toggleNavigationBar(NavToggle, NavFrame);
			return false;
		};
	}
	// iterate over all NavFrames
	var NavFrames = $content.find( 'div.NavFrame' );

	// if more Navigation Bars found and not template namespace than Default: hide all
	var initiallyToggle	= showDefaultCount < NavFrames.length && mw.config.get( 'wgNamespaceNumber' ) !== 10;
	for (var i=0; i<NavFrames.length; i++) {
		var NavFrame = NavFrames[i];
		var NavToggle = document.createElement("a");
		NavToggle.className = 'NavToggle';
		NavToggle.setAttribute('href', '#');

		var NavToggleText = document.createTextNode(textHide);
		NavToggle.appendChild(NavToggleText);

		// add NavToggle-Button as first div-element
		// in < div class="NavFrame" >
		NavFrame.insertBefore(NavToggle, NavFrame.firstChild);

		NavToggle.onclick = toggleNavigationBarFunction(NavToggle, NavFrame);
		if (initiallyToggle) {
			toggleNavigationBar(NavToggle, NavFrame);
		} else { // make sure that 'display' is always set for every NavFrame
			for (
					var NavChild = NavFrame.firstChild;
					NavChild !== null;
					NavChild = NavChild.nextSibling
				) {
				if (NavChild.className === 'NavPic' || NavChild.className === 'NavContent') {
					NavChild.style.display = 'block';
				}
			}
		}
	}
})});