MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
KKeine Bearbeitungszusammenfassung
Markierung: Zurückgesetzt
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
//================================================================================
/**
* 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.
*/


/** Skript für [[Vorlage:Galerie]] */
/* global mw, $ */
$( function() {
/* jshint strict:false, browser:true */
  if (document.URL.match(/printable/g)) return;


  function toggleImageFunction(group,  remindex, shwindex) {
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
    return function() {
/* Begin of mw.loader.using callback */
      document.getElementById("ImageGroupsGr" + group + "Im" + remindex).style["display"] = "none";
      document.getElementById("ImageGroupsGr" + group + "Im" + shwindex).style["display"] = "block";
      return false;
    };
  }


  var divs = document.getElementsByTagName("div");
/**
  var i = 0, j = 0;
* Map addPortletLink to mw.util
  var units, search;
* @deprecated: Use mw.util.addPortletLink instead.
  var currentimage;
*/
  var UnitNode;
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
  for (i = 0; i < divs.length; i++) {
 
    if (divs[i].className !== "ImageGroup") { continue; }
/**
    UnitNode = undefined;
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
    search = divs[i].getElementsByTagName("div");
* @rev 6
    for (j = 0; j < search.length; j++) {
*/
      if (search[j].className !== "ImageGroupUnits") { continue; }
var extraCSS = mw.util.getParamValue( 'withCSS' ),
      UnitNode=search[j];
extraJS = mw.util.getParamValue( 'withJS' );
      break;
 
    }
if ( extraCSS ) {
    if (UnitNode === undefined) { continue; }
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
    units = [];
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
    for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
} else {
      var temp = UnitNode.childNodes[j];
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
      if (temp.className === "center") { units.push(temp); }
}
    }
}
    var rightlink = undefined;
 
    var commentText = undefined;
if ( extraJS ) {
    for (j = 0; j < units.length; j++) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
      currentimage = units[j];
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
      currentimage.id = "ImageGroupsGr" + i + "Im" + j;
} else {
      var leftlink = document.createElement("a");
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
      if (commentText !== undefined) {
}
        leftlink.setAttribute("title", commentText);
}
      }
 
      var comment;
/**
      if (typeof(currentimage.getAttribute("title")) !== "string") {
* WikiMiniAtlas
        commentText = (j+1) + "/" + units.length;
*
        comment = document.createElement("tt").appendChild(document.createTextNode("("+ commentText + ")"));
* Description: WikiMiniAtlas is a popup click and drag world map.
      } else {
*              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
        commentText = currentimage.getAttribute("title");
*              The script itself is located on the Meta-Wiki because it is used by many projects.
        comment = document.createElement("span").appendChild(document.createTextNode(commentText));
*              See [[Meta:WikiMiniAtlas]] for more information.
        currentimage.removeAttribute("title");
* Note - use of this service is recommended to be replaced with mw:Help:Extension:Kartographer
      }
*/
      if(rightlink !== undefined) {
$( function () {
        rightlink.setAttribute("title", commentText);
var requireWikiminiatlas = $( 'a.external.text[href*="geohack"]' ).length || $( 'div.kmldata' ).length;
      }
if ( requireWikiminiatlas ) {
      var imghead = document.createElement("div");
mw.loader.load( 'ext.gadget.WikiMiniAtlas' );
      rightlink = document.createElement("a");
}
      if (j !== 0) {
} );
        leftlink.href = "#";
 
        leftlink.onclick = toggleImageFunction(i, j, j-1);
/**
        leftlink.appendChild(document.createTextNode("◀"));
* Collapsible tables; reimplemented with mw-collapsible
      }
* Styling is also in place to avoid FOUC
      if (j !== units.length - 1) {
*
        rightlink.href = "#";
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
        rightlink.onclick = toggleImageFunction(i, j, j+1);
* @version 3.0.0 (2018-05-20)
        rightlink.appendChild(document.createTextNode("▶"));
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
      }
* @author [[User:R. Koot]]
      imghead.style["fontSize"] = "110%";
* @author [[User:Krinkle]]
      imghead.style["fontweight"] = "bold";
* @author [[User:TheDJ]]
      imghead.appendChild(leftlink);
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
      imghead.appendChild(document.createTextNode("\xA0"));
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
      imghead.appendChild(comment);
*
      imghead.appendChild(document.createTextNode("\xA0"));
* @param {jQuery} $content
      imghead.appendChild(rightlink);
*/
      if (units.length > 1) {
function makeCollapsibleMwCollapsible( $content ) {
        currentimage.insertBefore(imghead,currentimage.childNodes[0]);
var $tables = $content
      }
.find( 'table.collapsible:not(.mw-collapsible)' )
      if (j !== 0) {
.addClass( 'mw-collapsible' );
        currentimage.style["display"] = "none";
 
      }
$.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 */

Aktuelle Version vom 20. September 2024, 06: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 */