MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(47 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 collapseCaption = 'hide';
/* jshint strict:false, browser:true */
var expandCaption = 'show';


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;
} );
 
/**
* 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' );


// If hidden now
$.each( $tables, function ( index, table ) {
} else if ( navToggle.firstChild.data === navigationBarShow ) {
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( table ).hasClass( 'collapsed' ) ) {
if ( $( navChild ).hasClass( 'NavContent' ) || $( navChild ).hasClass( 'NavPic' ) ) {
$( table ).addClass( 'mw-collapsed' );
navChild.style.display = 'block';
// 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 );
 
}());
 
 
 
/** Skript für [[Vorlage:Galerie]] */
$( function() {
  if (document.URL.match(/printable/g)) return;
 
  function toggleImageFunction(group,  remindex, shwindex) {
    return function() {
      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;
  var units, search;
  var currentimage;
  var UnitNode;
  for (i = 0; i < divs.length; i++) {
    if (divs[i].className !== "ImageGroup") { continue; }
    UnitNode = undefined;
    search = divs[i].getElementsByTagName("div");
    for (j = 0; j < search.length; j++) {
      if (search[j].className !== "ImageGroupUnits") { continue; }
      UnitNode=search[j];
      break;
    }
    if (UnitNode === undefined) { continue; }
    units = [];
    for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
      var temp = UnitNode.childNodes[j];
      if (temp.className === "center") { units.push(temp); }
    }
    var rightlink = undefined;
    var commentText = undefined;
    for (j = 0; j < units.length; j++) {
      currentimage = units[j];
      currentimage.id = "ImageGroupsGr" + i + "Im" + j;
      var leftlink = document.createElement("a");
      if (commentText !== undefined) {
        leftlink.setAttribute("title", commentText);
      }
      var comment;
      if (typeof(currentimage.getAttribute("title")) !== "string") {
        commentText = (j+1) + "/" + units.length;
        comment = document.createElement("tt").appendChild(document.createTextNode("("+ commentText + ")"));
      } else {
        commentText = currentimage.getAttribute("title");
        comment = document.createElement("span").appendChild(document.createTextNode(commentText));
        currentimage.removeAttribute("title");
      }
      if(rightlink !== undefined) {
        rightlink.setAttribute("title", commentText);
      }
      var imghead = document.createElement("div");
      rightlink = document.createElement("a");
      if (j !== 0) {
        leftlink.href = "#";
        leftlink.onclick = toggleImageFunction(i, j, j-1);
        leftlink.appendChild(document.createTextNode("◀"));
      }
      if (j !== units.length - 1) {
        rightlink.href = "#";
        rightlink.onclick = toggleImageFunction(i, j, j+1);
        rightlink.appendChild(document.createTextNode("▶"));
      }
      imghead.style["fontSize"] = "110%";
      imghead.style["fontweight"] = "bold";
      imghead.appendChild(leftlink);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(comment);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(rightlink);
      if (units.length > 1) {
        currentimage.insertBefore(imghead,currentimage.childNodes[0]);
      }
      if (j !== 0) {
        currentimage.style["display"] = "none";
      }
    }
  }
});
 
/**
* Fügt eine Betreffzeile auf leeren Artikel-Diskussionsseiten ein
*/
if( mw.config.get( 'wgNamespaceNumber' ) === 0 || mw.config.get( 'wgNamespaceNumber' ) === 1 ) {
$(function() {
  $( '#ca-talk.new a' ).attr( 'href', function( index, attr ) {
  return attr + '&section=new';
  });
});
}
 
/**
* Fügt bei SVG-Grafiken Links zu gerenderten PNGs in verschiedenen Breiten hinzu
*/
if (mw.config.get( 'wgNamespaceNumber' ) === 6) {
$( function() {
  var file = $( '#file' ); // might fail if MediaWiki can't render the SVG
  if( file.length && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgTitle' ).match( /\.svg$/i ) ) {
  var thumbsrc = file.find( 'img' ).attr( 'src' );
  if( !thumbsrc ) {
    return;
  }


  var svgAltSize = function( w, title ) {
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
    var path = thumbsrc.replace( /\/\d+(px-[^\/]+$)/, "/" + w + "$1" );
    var a = $( document.createElement("a") );
    a.attr( 'href', path );
    a.text( title );
    return a;
  };


  var p = $( document.createElement("p") );
/* End of mw.loader.using callback */
  p.addClass( "SVGThumbs" );
} );
  p.append( document.createTextNode( "Aus SVG automatisch erzeugte PNG-Grafiken in verschiedenen Auflösungen"+": " ) );
/* DO NOT ADD CODE BELOW THIS LINE */
  var l = [ 200, 500, 1000, 2000 ];
  for( var i = 0; i < l.length; i++ ) {
    if( i !== 0 ) {
    p.append( document.createTextNode( ", " ) );
    }
    p.append( svgAltSize( l[i], l[i] + "px" ) );
  }
  p.append( document.createTextNode( "." ) );
  $( file.parent() ).find( 'div.fullMedia' ).append( p );
  }
});
}

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 */