MediaWiki:Common.js: Różnice pomiędzy wersjami

Z PUTwiki
Przejdź do nawigacjiPrzejdź do wyszukiwania
Utworzono nową stronę "Umieszczony tutaj kod JavaScript zostanie załadowany przez każdego użytkownika, podczas każdego ładowania strony.: /** * 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 ga…"
 
Nie podano opisu zmian
Linia 1: Linia 1:
/* Umieszczony tutaj kod JavaScript zostanie załadowany przez każdego użytkownika, podczas każdego ładowania strony. */
// <pre>
/*
UWAGA! Ten JavaScript działa dla wszystkich skórek. Należy zachować szczególną ostrożność wprowadzając tutaj zmiany!
*/


var backgrounds = [
    'lud_bkgrnd.png',
    'marmur_bkgrnd.png',
    'sra czka_bkgrnd.png',
    'zielona_sra czka_bkgrnd.png',
    'b omble_bkgrnd.png'
];


/**
// Losuj indeks z tablicy
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
var randomBg = backgrounds[Math.floor(Math.random() * backgrounds.length)];
* 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, $ */
// Ustaw jako tło całej strony
/* jshint strict:false, browser:true */
document.addEventListener("DOMContentLoaded", function() {
    document.body.style.backgroundImage = 'url("/resources/assets/' + randomBg + '")';
    document.body.style.backgroundSize = "cover";
    document.body.style.backgroundRepeat = "no-repeat";
    document.body.style.backgroundAttachment = "fixed";
});


mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
/* Begin of mw.loader.using callback */


/**
/** ? *********************************************************
* Map addPortletLink to mw.util
  *
* @deprecated: Use mw.util.addPortletLink instead.
  *  Description: ?
*/
  * Maintainers: ?
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
  */
jQuery(function()
{
//
// Ustawienie wysokości "Usunięcie" pustego elementu contentSub
//
var el=document.getElementById('mw-revisiontag');
if (el && el.className.indexOf('flaggedrevs_short')!=-1)
{
if (el.parentNode.id=='contentSub') el.parentNode.style.height='17px';
}


/**
//
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
jQuery('table.navbox').first().addClass('firstNavbox');
* @rev 6
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );


if ( extraCSS ) {
//Pomyłki przy archiwizowaniu stron dyskusji
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
if($('#wpNewTitleNs select').val() == 3) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
$('#wpMovesubpages input').prop('checked', false);
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
}
});


if ( extraJS ) {
/** sortable config *********************************************************
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
  *
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
  *  Description: Various tweaks for sortable tables.
} else {
  *  Maintainers: ?
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
  */
}
}


/**
// Kod pozwalający na skonstruowanie niesortującej się kolumny z liczbą porządkową w sortowalnych tabelkach.
* Collapsible tables; reimplemented with mw-collapsible
// Odpowiednia komórka nagłówkowa sortowalnej tabelki (class="sortable") musi być oznaczona
* Styling is also in place to avoid FOUC
// jako niesortowalna i zawierająca liczby porządkowe (class="unsortable ordinal").
*
// Dyskusja w kawiarence: [[Wikipedia:Kawiarenka/Kwestie techniczne#Poprawa tabeli w Miasta w Polsce (statystyki)]]
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
// Zgłoszenie na Bugzilli: [https://bugzilla.wikimedia.org/show_bug.cgi?id=40618]
* @version 3.0.0 (2018-05-20)
$('table.sortable th.unsortable.ordinal').each(function(i, th) {
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
var $th = $(th), $table = $th.closest('table');
* @author [[User:R. Koot]]
$table.on('sortEnd.tablesorter', function() {
* @author [[User:Krinkle]]
$table.find('tr td:nth-child('+ (th.cellIndex+1) +')').each(function(j, td) {
* @author [[User:TheDJ]]
$(td).text( (j+1) );
* @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 ) {
/** autocollapse for collapsible *********************************************************
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
  *
if ( $( table ).hasClass( 'collapsed' ) ) {
  *  Description: (legacy) Automatyczne zwijanie szablonów nawigacyjnych. Pozostałość po starej składni (~2010).
$( table ).addClass( 'mw-collapsed' );
  *              Zwija navboksy, jeśli są co najmniej dwa. Aktualnie (2023) stosowane tylko poza przestrzenią główną.
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
  *  Maintainers: -
}
  */
} );
mw.loader.using( "mediawiki.util" ).then(function() {
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 ) {
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
if ($($collapsibleContent).length > 2) {
$toggle,
$.each( $collapsibleContent, function (index, element) {
autoCollapseThreshold = 2;
var $element = $( element );
$.each( $collapsibleContent, function ( index, element ) {
if ( $element.hasClass( 'autocollapse' ) ) {
$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();
$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 );
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
 
});
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */

Wersja z 00:32, 8 gru 2025

// <pre>
/*
UWAGA! Ten JavaScript działa dla wszystkich skórek. Należy zachować szczególną ostrożność wprowadzając tutaj zmiany!
*/

var backgrounds = [
    'lud_bkgrnd.png',
    'marmur_bkgrnd.png',
    'sra czka_bkgrnd.png',
    'zielona_sra czka_bkgrnd.png',
    'b omble_bkgrnd.png'
];

// Losuj indeks z tablicy
var randomBg = backgrounds[Math.floor(Math.random() * backgrounds.length)];

// Ustaw jako tło całej strony
document.addEventListener("DOMContentLoaded", function() {
    document.body.style.backgroundImage = 'url("/resources/assets/' + randomBg + '")';
    document.body.style.backgroundSize = "cover";
    document.body.style.backgroundRepeat = "no-repeat";
    document.body.style.backgroundAttachment = "fixed";
});


/** ? *********************************************************
  *
  *  Description: ?
  *  Maintainers: ?
  */
jQuery(function()
{
//
// Ustawienie wysokości "Usunięcie" pustego elementu contentSub
//
	var el=document.getElementById('mw-revisiontag');
	if (el && el.className.indexOf('flaggedrevs_short')!=-1)
	{
		if (el.parentNode.id=='contentSub') el.parentNode.style.height='17px';
	}

//
	jQuery('table.navbox').first().addClass('firstNavbox');

//Pomyłki przy archiwizowaniu stron dyskusji
	if($('#wpNewTitleNs select').val() == 3) {
		$('#wpMovesubpages input').prop('checked', false);
	}
});

/** sortable config *********************************************************
  *
  *  Description: Various tweaks for sortable tables.
  *  Maintainers: ?
  */

// Kod pozwalający na skonstruowanie niesortującej się kolumny z liczbą porządkową w sortowalnych tabelkach.
// Odpowiednia komórka nagłówkowa sortowalnej tabelki (class="sortable") musi być oznaczona
// jako niesortowalna i zawierająca liczby porządkowe (class="unsortable ordinal").
// Dyskusja w kawiarence: [[Wikipedia:Kawiarenka/Kwestie techniczne#Poprawa tabeli w Miasta w Polsce (statystyki)]]
// Zgłoszenie na Bugzilli: [https://bugzilla.wikimedia.org/show_bug.cgi?id=40618]
$('table.sortable th.unsortable.ordinal').each(function(i, th) {
	var $th = $(th), $table = $th.closest('table');
	$table.on('sortEnd.tablesorter', function() {
		$table.find('tr td:nth-child('+ (th.cellIndex+1) +')').each(function(j, td) {
			$(td).text( (j+1) );
		});
	});
});

/** autocollapse for collapsible *********************************************************
  *
  *  Description: (legacy) Automatyczne zwijanie szablonów nawigacyjnych. Pozostałość po starej składni (~2010).
  *               Zwija navboksy, jeśli są co najmniej dwa. Aktualnie (2023) stosowane tylko poza przestrzenią główną.
  *  Maintainers: -
  */
mw.loader.using( "mediawiki.util" ).then(function() {
	function mwCollapsibleSetup( $collapsibleContent ) {
		if ($($collapsibleContent).length > 2) {
			$.each( $collapsibleContent, function (index, element) {
				var $element = $( element );
				if ( $element.hasClass( 'autocollapse' ) ) {
					$element.data( 'mw-collapsible' ).collapse();
				}
			} );
		}
	}
	
	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
});