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
 
(Nie pokazano 3 pośrednich wersji utworzonych przez tego samego użytkownika)
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!
*/


// --- Losowe tło w formie patternu (nie rozciąga, nie pikselizuje) ---


/**
mw.hook('wikipage.content').add(function () {
* 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, $ */
    var bgPath = "/resources/assets/";  // <-- dostosowane u Ciebie
/* jshint strict:false, browser:true */


mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
    var backgrounds = [
/* Begin of mw.loader.using callback */
        "lud_bkgrnd.png",
        "marmur_bkgrnd.png",
        "sraczka_bkgrnd.png",
        "zielona_sraczka_bkgrnd.png",
        "bomble_bkgrnd.png"
    ];


/**
    var randomBg = backgrounds[Math.floor(Math.random() * backgrounds.length)];
* Map addPortletLink to mw.util
    var finalUrl = 'url("' + bgPath + randomBg + '")';
* @deprecated: Use mw.util.addPortletLink instead.
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );


/**
    var styleTag = document.createElement("style");
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
    styleTag.innerHTML = `
* @rev 6
        body {
*/
            background-image: ${finalUrl} !important;
var extraCSS = mw.util.getParamValue( 'withCSS' ),
            background-repeat: repeat !important;
extraJS = mw.util.getParamValue( 'withJS' );
            background-size: auto !important;
            background-attachment: scroll !important;
            background-position: top left !important;
        }
    `;
    document.head.appendChild(styleTag);
});


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


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


/**
/** sortable config *********************************************************
* Collapsible tables; reimplemented with mw-collapsible
  *
* Styling is also in place to avoid FOUC
  * Description: Various tweaks for sortable tables.
*
  *  Maintainers: ?
* 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 ) {
// Kod pozwalający na skonstruowanie niesortującej się kolumny z liczbą porządkową w sortowalnych tabelkach.
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
// Odpowiednia komórka nagłówkowa sortowalnej tabelki (class="sortable") musi być oznaczona
if ( $( table ).hasClass( 'collapsed' ) ) {
// jako niesortowalna i zawierająca liczby porządkowe (class="unsortable ordinal").
$( table ).addClass( 'mw-collapsed' );
// Dyskusja w kawiarence: [[Wikipedia:Kawiarenka/Kwestie techniczne#Poprawa tabeli w Miasta w Polsce (statystyki)]]
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
// 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');
if ( $tables.length > 0 ) {
$table.on('sortEnd.tablesorter', function() {
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
$table.find('tr td:nth-child('+ (th.cellIndex+1) +')').each(function(j, td) {
$tables.makeCollapsible();
$(td).text( (j+1) );
} );
});
}
});
}
});
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


/**
/** autocollapse for collapsible *********************************************************
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
  *
*
  *  Description: (legacy) Automatyczne zwijanie szablonów nawigacyjnych. Pozostałość po starej składni (~2010).
* Maintainers: TheDJ
  *               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 ) {
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 */

Aktualna wersja na dzień 00:41, 8 gru 2025

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

// --- Losowe tło w formie patternu (nie rozciąga, nie pikselizuje) ---

mw.hook('wikipage.content').add(function () {

    var bgPath = "/resources/assets/";  // <-- dostosowane u Ciebie

    var backgrounds = [
        "lud_bkgrnd.png",
        "marmur_bkgrnd.png",
        "sraczka_bkgrnd.png",
        "zielona_sraczka_bkgrnd.png",
        "bomble_bkgrnd.png"
    ];

    var randomBg = backgrounds[Math.floor(Math.random() * backgrounds.length)];
    var finalUrl = 'url("' + bgPath + randomBg + '")';

    var styleTag = document.createElement("style");
    styleTag.innerHTML = `
        body {
            background-image: ${finalUrl} !important;
            background-repeat: repeat !important;
            background-size: auto !important;
            background-attachment: scroll !important;
            background-position: top left !important;
        }
    `;
    document.head.appendChild(styleTag);
});




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