MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(50 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
// see [[:en:MediaWiki:Navigation.js]] and/or [[w:en:MediaWiki:Common.js]]
/**
* 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.
*/


// BEGIN Collapsible tables
/* global mw, $ */
// Description: Allows tables to be collapsed, showing only the header.
/* jshint strict:false, browser:true */
// See Wikipedia:NavFrame.
// Maintainers: User:R. Koot


var autoCollapse = 2;
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
// set up the words in your language
/* Begin of mw.loader.using callback */
var collapseCaption = 'hide';
var expandCaption = 'show';


if( mw.config.get( 'wgUserLanguage') == 'de' ) {
/**
collapseCaption = 'Einklappen';
* Map addPortletLink to mw.util
expandCaption = 'Aufklappen';
* @deprecated: Use mw.util.addPortletLink instead.
}
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );


function collapseTable( tableIndex ) {
/**
var Button = document.getElementById( 'collapseButton' + tableIndex );
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
* @rev 6
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );


if ( !Table || !Button ) {
if ( extraCSS ) {
return false;
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
}
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
 
} else {
var Rows = Table.getElementsByTagName( 'tr' );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
 
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
}


function createCollapseButtons() {
if ( extraJS ) {
var tableIndex = 0;
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
var NavigationBoxes = new Object();
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
var Tables = document.getElementsByTagName( 'table' );
} else {
 
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
for ( var i = 0; i < Tables.length; i++ ) {
if ( $(Tables[i]).hasClass('collapsible' ) ) {
NavigationBoxes[tableIndex] = Tables[i];
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
var Button = document.createElement( 'span' );
var ButtonLink = document.createElement( 'a' );
var ButtonText = document.createTextNode( collapseCaption );
 
Button.style.styleFloat = 'right';
Button.style.cssFloat = 'right';
Button.style.fontWeight = 'normal';
Button.style.textAlign = 'right';
Button.style.width = '6em';
 
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', 'javascript:collapseTable(' + tableIndex + ');' );
ButtonLink.appendChild( ButtonText );
 
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
 
var Header = Tables[i].getElementsByTagName( 'tr' )[0].getElementsByTagName( 'th' )[0];
/* only add button and increment count if there is a header row to work with */
if ( Header ) {
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
}
}
}


for ( var i = 0; i < tableIndex; i++ ) {
/**
if (
* WikiMiniAtlas
$(NavigationBoxes[i]).hasClass('collapsed' ) ||
*
( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass('autocollapse' ) )
* 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.
collapseTable( i );
*              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' );
}
}
}
} );
}
 
$(document).ready( createCollapseButtons );
 
// Dynamic Navigation Bars
 
// set up the words in your language
var NavigationBarHide = 'Collapse';
var NavigationBarShow = 'Expand';
 
if( mw.config.get( 'wgUserLanguage') == 'de' ) {
NavigationBarHide = 'Einklappen';
NavigationBarShow = 'Aufklappen';
}


// shows and hides content and picture (if available) of navigation bars
/**
function toggleNavigationBar( e ) {
* Collapsible tables; reimplemented with mw-collapsible
e = e || window.event;
* Styling is also in place to avoid FOUC
var NavToggle = e.target || e.srcElement;
*
var NavFrame = NavToggle.parentNode.parentNode;
* 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' );


if ( NavToggle.firstChild.data == NavigationBarHide ) {
$.each( $tables, function ( index, table ) {
for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
if ( $(NavChild).hasClass('NavContent' ) || $(NavChild).hasClass('NavPic' ) ) {
if ( $( table ).hasClass( 'collapsed' ) ) {
NavChild.style.display = 'none';
$( 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 = NavigationBarShow;
} else if ( NavToggle.firstChild.data == NavigationBarShow ) {
for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $(NavChild).hasClass('NavContent' ) || $(NavChild).hasClass('NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


// adds show/hide-button to navigation bars
/**
function createNavigationBarToggleButton() {
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
// iterate over all <div> elements
*
var NavFrame = document.getElementsByTagName( 'div' );
* Maintainers: TheDJ
 
*/
for ( var i = 0; i < NavFrame.length; i++ ) {
function mwCollapsibleSetup( $collapsibleContent ) {
if ( $(NavFrame[i]).hasClass('NavFrame' ) ) {
var $element,
var NavToggle = document.createElement( 'a' );
$toggle,
var NavToggleText = document.createTextNode(
autoCollapseThreshold = 2;
$(NavFrame[i]).hasClass('selected' ) ? NavigationBarShow : NavigationBarHide
$.each( $collapsibleContent, function ( index, element ) {
);
$element = $( element );
 
if ( $element.hasClass( 'collapsible' ) ) {
NavToggle.className = 'NavToggle';
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
NavToggle.onclick = toggleNavigationBar;
}
NavToggle.appendChild( NavToggleText );
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
 
$element.data( 'mw-collapsible' ).collapse();
// add NavToggle-Button as element in <div class="NavFrame">
} else if ( $element.hasClass( 'innercollapse' ) ) {
for ( var j = 0; j < NavFrame[i].childNodes.length; j++ ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
if ( $(NavFrame[i].childNodes[j]).hasClass('NavHead' ) ) {
$element.data( 'mw-collapsible' ).collapse();
NavFrame[i].childNodes[j].appendChild( NavToggle );
}
}
}
}
 
// because of colored backgrounds, style the link in the text color
if ( document.createEvent ) { // DOM 2 and DOM 3 compliant browsers
// to ensure accessible contrast
var e = document.createEvent( 'MouseEvents' );
$toggle = $element.find( '.mw-collapsible-toggle' );
e.initMouseEvent(
if ( $toggle.length ) {
'click', true, true, window, 0, 0, 0, 0, 0, false, false,
// Make the toggle inherit text color (Updated for T333357 2023-04-29)
false, false, 0, null
if ( $toggle.parent()[ 0 ].style.color ) {
);
$toggle.css( 'color', 'inherit' );
NavToggle.dispatchEvent( e );
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
} else if ( NavToggle.fireEvent ) { // IE
}
NavToggle.fireEvent( 'onclick' );
}
}
}
} );
}
}
}


$(document).ready( 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 */