MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
Keine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(101 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
/**
* 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, $ */
// BEGIN Enable multiple onload functions
/* jshint strict:false, browser:true */
// setup onload functions this way:
// aOnloadFunctions[aOnloadFunctions.length] = function_name; // without brackets!
if (!window.aOnloadFunctions) {
  var aOnloadFunctions = new Array();
}
window.onload = function() {
  if (window.aOnloadFunctions) {
    for (var _i=0; _i<aOnloadFunctions.length; _i++) {
      aOnloadFunctions[_i]();
    }
  }
}
// END Enable multiple onload functions
// ============================================================


// ============================================================
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
// BEGIN Dynamic Navigation Bars
/* Begin of mw.loader.using callback */
// NEEDS Enable multiple onload functions
 
/**
// set up the words in your language
* Map addPortletLink to mw.util
var NavigationBarHide = 'Einklappen';
* @deprecated: Use mw.util.addPortletLink instead.
var NavigationBarShow = 'Ausklappen';
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
// set up max count of Navigation Bars on page,
 
// if there are more, all will be hidden
/**
// NavigationBarShowDefault = 0; // all bars will be hidden
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
* @rev 6
if (typeof NavigationBarShowDefault == 'undefined' ) {
*/
    var NavigationBarShowDefault = 1;
var extraCSS = mw.util.getParamValue( 'withCSS' ),
}
extraJS = mw.util.getParamValue( 'withJS' );
 
// shows and hides content and picture (if available) of navigation bars
if ( extraCSS ) {
// Parameters:
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
//    indexNavigationBar: the index of navigation bar to be toggled
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
function toggleNavigationBar(indexNavigationBar)
} else {
{
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
}
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
}
 
    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 {
    // if shown now
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
    if (NavToggle.firstChild.data == NavigationBarHide) {
}
        for (
}
                var NavChild = NavFrame.firstChild;
 
                NavChild != null;
/**
                NavChild = NavChild.nextSibling
* WikiMiniAtlas
            ) {
*
            if (NavChild.className == '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.
            if (NavChild.className == 'NavContent') {
*              See [[Meta:WikiMiniAtlas]] for more information.
                NavChild.style.display = 'none';
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
            }
*/
            if (NavChild.className == 'NavToggle') {
$( function () {
                NavChild.firstChild.data = NavigationBarShow;
var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
            }
if ( requireWikiminiatlas ) {
        }
mw.loader.load( 'ext.gadget.WikiMiniAtlas' );
}
    // if hidden now
} );
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
 
        for (
/**
                var NavChild = NavFrame.firstChild;
* Collapsible tables; reimplemented with mw-collapsible
                NavChild != null;
* Styling is also in place to avoid FOUC
                NavChild = NavChild.nextSibling
*
            ) {
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
            if (NavChild.className == 'NavPic') {
* @version 3.0.0 (2018-05-20)
                NavChild.style.display = 'block';
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
            }
* @author [[User:R. Koot]]
            if (NavChild.className == 'NavContent') {
* @author [[User:Krinkle]]
                NavChild.style.display = 'block';
* @author [[User:TheDJ]]
            }
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
            if (NavChild.className == 'NavToggle') {
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
                NavChild.firstChild.data = NavigationBarHide;
*
            }
* @param {jQuery} $content
        }
*/
    }
function makeCollapsibleMwCollapsible( $content ) {
}
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
// adds show/hide-button to navigation bars
.addClass( 'mw-collapsible' );
function createNavigationBarToggleButton()
 
{
$.each( $tables, function ( index, table ) {
    var indexNavigationBar = 0;
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
    // iterate over all < div >-elements
if ( $( table ).hasClass( 'collapsed' ) ) {
    for(
$( table ).addClass( 'mw-collapsed' );
            var i=0;
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
            NavFrame = document.getElementsByTagName("div")[i];  
}
            i++
} );
        ) {
if ( $tables.length > 0 ) {
        // if found a navigation bar
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
        if (NavFrame.className == "NavFrame") {
$tables.makeCollapsible();
} );
            indexNavigationBar++;
}
            var NavToggle = document.createElement("a");
}
            NavToggle.className = 'NavToggle';
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
 
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
            var NavToggleText = document.createTextNode(NavigationBarHide);
*
            NavToggle.appendChild(NavToggleText);
* Maintainers: TheDJ
*/
            // add NavToggle-Button as first div-element
function mwCollapsibleSetup( $collapsibleContent ) {
            // in < div class="NavFrame" >
var $element,
            NavFrame.insertBefore(
$toggle,
                NavToggle,
autoCollapseThreshold = 2;
                NavFrame.firstChild
$.each( $collapsibleContent, function ( index, element ) {
            );
$element = $( element );
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
if ( $element.hasClass( 'collapsible' ) ) {
        }
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
    }
}
    // if more Navigation Bars found than Default: hide all
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
    if (NavigationBarShowDefault < indexNavigationBar) {
$element.data( 'mw-collapsible' ).collapse();
        for(
} else if ( $element.hasClass( 'innercollapse' ) ) {
                var i=1;  
if ( $element.parents( '.outercollapse' ).length > 0 ) {
                i<=indexNavigationBar;
$element.data( 'mw-collapsible' ).collapse();
                i++
}
        ) {
}
            toggleNavigationBar(i);
// 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 ) {
aOnloadFunctions[aOnloadFunctions.length] = createNavigationBarToggleButton;
$toggle.css( 'color', 'inherit' );
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
// END Dynamic Navigation Bars
}
// ============================================================
}
} );
}
 
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 */