MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(78 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
/**
/**
  * Dynamic Navigation Bars. See [[Wikipedia:NavFrame]]
  * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
  *  
* loaded for all users on every wiki page. If possible create a gadget that is
  * Based on script from en.wikipedia.org, 2008-09-15.
  * enabled by default instead of adding it here (since gadgets are fully
  * optimized ResourceLoader modules with possibility to add dependencies etc.)
  *
  *
  * @source www.mediawiki.org/wiki/MediaWiki:Gadget-NavFrame.js
  * Since Common.js isn't a gadget, there is no place to declare its
  * @maintainer Helder.wiki, 2012–2013
* dependencies, so we have to lazy load them with mw.loader.using on demand and
  * @maintainer Krinkle, 2013
* then execute the rest in the callback. In most cases these dependencies will
  * be loaded (or loading) already and the callback will not be delayed. In case a
  * dependency hasn't arrived yet it'll make sure those are loaded before this.
  */
  */
( function () {


// Set up the words in your language
/* global mw, $ */
var autoCollapse = 0;
/* jshint strict:false, browser:true */
var collapseCaption = 'Einklappen';
var expandCaption = 'Ausklappen';


var navigationBarHide = '[' + collapseCaption + ']';
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
var navigationBarShow = '[' + expandCaption + ']';
/* Begin of mw.loader.using callback */


/**
/**
* Shows and hides content and picture (if available) of navigation bars.
* Map addPortletLink to mw.util
*
* @deprecated: Use mw.util.addPortletLink instead.
* @param {number} indexNavigationBar The index of navigation bar to be toggled
*/
* @param {jQuery.Event} e Event object
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
*/
 
function toggleNavigationBar( indexNavigationBar, e ) {
/**
var navChild,
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),
* @rev 6
navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );


// Prevent browser from jumping to href "#"
if ( extraCSS ) {
e.preventDefault();
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}


if ( !navFrame || !navToggle ) {
if ( extraJS ) {
return false;
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
}


// If shown now
/**
if ( navToggle.firstChild.data === navigationBarHide ) {
* WikiMiniAtlas
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
*
if ( $( navChild ).hasClass( 'NavContent' ) || $( navChild ).hasClass( 'NavPic' ) ) {
* Description: WikiMiniAtlas is a popup click and drag world map.
navChild.style.display = 'none';
*              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
}
*              The script itself is located on the Meta-Wiki because it is used by many projects.
*              See [[Meta:WikiMiniAtlas]] for more information.
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
*/
$( function () {
var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
if ( requireWikiminiatlas ) {
mw.loader.load( 'ext.gadget.WikiMiniAtlas' );
}
}
navToggle.firstChild.data = navigationBarShow;
} );


// If hidden now
/**
} else if ( navToggle.firstChild.data === navigationBarShow ) {
* Collapsible tables; reimplemented with mw-collapsible
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
* Styling is also in place to avoid FOUC
if ( $( navChild ).hasClass( 'NavContent' ) || $( navChild ).hasClass( 'NavPic' ) ) {
*
navChild.style.display = 'block';
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
* @version 3.0.0 (2018-05-20)
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @author [[User:TheDJ]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
*
* @param {jQuery} $content
*/
function makeCollapsibleMwCollapsible( $content ) {
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );
 
$.each( $tables, function ( index, table ) {
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
if ( $( table ).hasClass( 'collapsed' ) ) {
$( table ).addClass( 'mw-collapsed' );
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
}
}
} );
if ( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
$tables.makeCollapsible();
} );
}
}
navToggle.firstChild.data = navigationBarHide;
}
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


/**
/**
* Adds show/hide-button to navigation bars.
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
*
*
* @param {jQuery} $content
* Maintainers: TheDJ
*/
*/
function createNavigationBarToggleButton( $content ) {
function mwCollapsibleSetup( $collapsibleContent ) {
var i, j, navChild, navToggle, navToggleText, isCollapsed,
var $element,
indexNavigationBar = 0;
$toggle,
// iterate over all < div >-elements
autoCollapseThreshold = 2;
var $divs = $content.find( 'div.NavFrame' );
$.each( $collapsibleContent, function ( index, element ) {
$divs.each( function ( i, navFrame ) {
$element = $( element );
indexNavigationBar++;
if ( $element.hasClass( 'collapsible' ) ) {
navToggle = document.createElement( 'a' );
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
navToggle.className = 'NavToggle';
}
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
navToggle.setAttribute( 'href', '#' );
$element.data( 'mw-collapsible' ).collapse();
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
} else if ( $element.hasClass( 'innercollapse' ) ) {
 
if ( $element.parents( '.outercollapse' ).length > 0 ) {
isCollapsed = $( navFrame ).hasClass( 'collapsed' );
$element.data( 'mw-collapsible' ).collapse();
// backwards compatibility for old technique where the collapsed class was not yet used
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
if ( navChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
}
}
// because of colored backgrounds, style the link in the text color
if ( isCollapsed ) {
// to ensure accessible contrast
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
if ( $toggle.length ) {
navChild.style.display = 'none';
// Make the toggle inherit text color (Updated for T333357 2023-04-29)
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.css( 'color', 'inherit' );
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
}
}
}
}
}
} );
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 );
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );


}());
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */

Aktuelle Version vom 20. September 2024, 05:22 Uhr

/**
 * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 * loaded for all users on every wiki page. If possible create a gadget that is
 * enabled by default instead of adding it here (since gadgets are fully
 * optimized ResourceLoader modules with possibility to add dependencies etc.)
 *
 * Since Common.js isn't a gadget, there is no place to declare its
 * dependencies, so we have to lazy load them with mw.loader.using on demand and
 * then execute the rest in the callback. In most cases these dependencies will
 * be loaded (or loading) already and the callback will not be delayed. In case a
 * dependency hasn't arrived yet it'll make sure those are loaded before this.
 */

/* global mw, $ */
/* jshint strict:false, browser:true */

mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
	/* Begin of mw.loader.using callback */

	/**
	 * Map addPortletLink to mw.util
	 * @deprecated: Use mw.util.addPortletLink instead.
	 */
	mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );

	/**
	 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
	 * @rev 6
	 */
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
			mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

	/**
	 * WikiMiniAtlas
	 *
	 * Description: WikiMiniAtlas is a popup click and drag world map.
	 *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
	 *              The script itself is located on the Meta-Wiki because it is used by many projects.
	 *              See [[Meta:WikiMiniAtlas]] for more information.
	 * Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
	 */
	$( function () {
		var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
		if ( requireWikiminiatlas ) {
			mw.loader.load( 'ext.gadget.WikiMiniAtlas' );
		}
	} );

	/**
	 * Collapsible tables; reimplemented with mw-collapsible
	 * Styling is also in place to avoid FOUC
	 *
	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
	 * @version 3.0.0 (2018-05-20)
	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
	 * @author [[User:R. Koot]]
	 * @author [[User:Krinkle]]
	 * @author [[User:TheDJ]]
	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
	 *
	 * @param {jQuery} $content
	 */
	function makeCollapsibleMwCollapsible( $content ) {
		var $tables = $content
			.find( 'table.collapsible:not(.mw-collapsible)' )
			.addClass( 'mw-collapsible' );

		$.each( $tables, function ( index, table ) {
			// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
			if ( $( table ).hasClass( 'collapsed' ) ) {
				$( table ).addClass( 'mw-collapsed' );
				// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
			}
		} );
		if ( $tables.length > 0 ) {
			mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
				$tables.makeCollapsible();
			} );
		}
	}
	mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

	/**
	 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
	 *
	 * Maintainers: TheDJ
	 */
	function mwCollapsibleSetup( $collapsibleContent ) {
		var $element,
			$toggle,
			autoCollapseThreshold = 2;
		$.each( $collapsibleContent, function ( index, element ) {
			$element = $( element );
			if ( $element.hasClass( 'collapsible' ) ) {
				$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
			}
			if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
				$element.data( 'mw-collapsible' ).collapse();
			} else if ( $element.hasClass( 'innercollapse' ) ) {
				if ( $element.parents( '.outercollapse' ).length > 0 ) {
					$element.data( 'mw-collapsible' ).collapse();
				}
			}
			// because of colored backgrounds, style the link in the text color
			// to ensure accessible contrast
			$toggle = $element.find( '.mw-collapsible-toggle' );
			if ( $toggle.length ) {
				// Make the toggle inherit text color (Updated for T333357 2023-04-29)
				if ( $toggle.parent()[ 0 ].style.color ) {
					$toggle.css( 'color', 'inherit' );
					$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
				}
			}
		} );
	}

	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

	/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */