MediaWiki:Common.js

Z Wikipedie, otevřené encyklopedie

Poznámka: Po uložení musíte vyprázdnit mezipaměť vašeho prohlížeče, jinak změny neuvidíte.

/*<syntaxhighlight lang="javascript">*/

/*****************************************************\
|*                Podpora pro navboxy                *|
|*                                                   *|
|* Pro další informace vizte [[:en:Help:Collapsing]] *|
\*****************************************************/
// Převzato z https://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=888496901
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
			if( $toggle.parent()[0].style.color ) {
				$toggle.find( 'a' ).css( 'color', 'inherit' );
			}
		}
	} );
}

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

/**
 * Test, zda má prvek třídu
 * Převzato z [[:en:MediaWiki:Common.js]]
 * @deprecated:  Use $(element).hasClass() instead.
 */
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
	return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );


/********************************************************************\
|* České řazení tabulek dle ÚJČ AV ČR (prirucka.ujc.cas.cz/?id=900) *|
|*                       vytvořil Littledogboy                      *|
\********************************************************************/
mw.config.set( 'tableSorterCollation', {'á':'a','č':'cÑÑ','ď':'d','é':'e','ě':'e','í':'i','ň':'n','ó':'o','ř':'rÑÑ','š':'sÑÑ','ť':'t','ú':'u','ů':'u','ý':'y','ž':'zÑÑ','Á':'A','Č':'CÑÑ','Ď':'D','É':'E','Ě':'E','Í':'I','Ň':'N','Ó':'O','Ř':'RÑÑ','Š':'SÑÑ','Ť':'T','Ú':'U','Ů':'U','Ý':'Y','Ž':'ZÑÑ'} );


/*****************************************************************\
|* Načtení JS nebo CSS ze jmenného prostoru MediaWiki pomocí URL *|
|*       převzato z [[:mw:Snippets/Load JS and CSS by URL]]      *|
|*                       revize 2016-03-26                       *|
\*****************************************************************/
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' ),
		extraModule = mw.util.getParamValue( 'withModule' );

	if ( extraCSS ) {
		// NEMAŽTE TUTO PODMÍNKU (ledaže by vám nevadil útok CSRF)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			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 ) {
		// NEMAŽTE TUTO PODMÍNKU (ledaže by vám nevadil útok CSRF)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			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 ( extraModule ) {
		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
			mw.loader.load( extraModule );
		} else {
			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
		}
	}
} );


/****************************************\
|* Vyvolání stylu klikatelných tlačítek *|
|*           vytvořil Dvorapa           *|
\****************************************/
mw.hook('wikipage.content').add(function() {
	if ((mw.loader.getState('oojs-ui') === 'registered') && ($('.oo-ui-widget').length)) {
		mw.loader.using(['oojs-ui', 'oojs-ui.styles.icons-user', 'oojs-ui.styles.icons-editing-core', 'oojs-ui.styles.icons-editing-advanced', 'oojs-ui.styles.icons-editing-citation']);
	}
});


/**************************************************************\
|* Přidání dotazovacího parametru k odkazům v šabloně Vítejte *|
|*       na uživatelských diskusních stránkách (T206882)      *|
\**************************************************************/
if(mw.config.get('wgNamespaceNumber') == 3)
{
	var links = $('.welcome-template').find('a');
	for(var i=0; i < links.length; i++)
	{
		if(links[i].classList.contains('external') === false) {
			if (!links[i].href.includes("#")) {
				links[i].href += "?fromWelcomeTemplate=1";
			} else {
				links[i].href = links[i].href.replace("#", "?fromWelcomeTemplate=1#");
			}
		}
	}
}

function updateUserScriptWarning( msg ) {
	return function () {
		var userScript = '/wiki/Special:MyPage/' + mw.config.get('skin') + '.js';
		var commonScript = '/wiki/Special:MyPage/common.js';
		mw.notify(
			$('<div>').html(
				'Skript, který se vám načítá, používá zastaralou funkci <strong>' + msg + '</strong>. Prosím, zkontrolujte si <a href="' + userScript + '">své uživatelské</a> <a href="' + commonScript + '">skripty</a>, aby toto upozornění zmizelo.'
			),
			{ type: 'error' }
		); 
	};
}

// Can be removed when https://global-search.toolforge.org/?q=addSummaryToolbar&namespaces=2&title= returns no results for wiki
window.addSummaryToolbar = updateUserScriptWarning('addSummaryToolbar');
// Can be removed when https://global-search.toolforge.org/?q=addFindAndReplaceToolbar&namespaces=2&title= returns no results for wiki
window.addFindAndReplaceToolbar = updateUserScriptWarning('addFindAndReplaceToolbar');
// Can be removed when https://global-search.toolforge.org/?q=mwCustomEditButtons&namespaces=2&title= returns no results for wiki
window.mwCustomEditButtons = [];
// Can be removed when https://global-search.toolforge.org/?q=+akeytt&regex=1&namespaces=&title= returns no results for wiki
window.akeytt = updateUserScriptWarning('akeytt');

/*</syntaxhighlight>*/