MediaWiki:Common.js
Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
mw.loader.load( '/index.php?title=MediaWiki:Welcome-modal-dialog.js&action=raw&ctype=text/javascript' );
// Mermaid does not seem to load in talk namespaces. This script forces it.
if(mw.config.get('wgNamespaceNumber') % 2 && $('.ext-mermaid').length)
{
setTimeout(function() {
var config = mw.config.get( 'mermaid' );
mw.loader.using( [ 'mediawiki.api', 'ext.mermaid', 'ext.mermaid.theme.' + config.theme ] );
}, 3000);
}
/* Menu de gauche collapsible et en tête (Gestion:Tâches/Liste/221/13) */
$('#p-tb-label').addClass("not-collapsed");
$('#p-tb-label').siblings('.body').toggleClass( "collapsed" );
$('#p-tb-label').click(function(event) {
console.log(event);
$(event.target).siblings('.body').toggleClass( "collapsed" );
$(event.target).toggleClass( "not-collapsed" );
/* Prise en compte des iframe (e.g. fil de discussion) */
/*
if ($(event.target).parent().parent().nextUntil('h2').find("iframe").css( "height") == '0px'){
$(event.target).parent().parent().nextUntil('h2').find("iframe").css( "height", "");
}¸
*/
});
$('.collapse').click(); // Collaspe all by default.
/* Add heading image (see Gestion:Tâches/Liste/564) */
var namespace = mw.config.get("wgNamespaceNumber");
var bg;
if(namespace == 0) // if on the main namespace.
{
// Retrieve the image in the HTML.
img = $(".mw-capiunto-infobox-spanning").find("img").first().attr("src");
// If an image was feteched.
if(img) { bg = "linear-gradient(0deg, black 0%, #00000032 30%), url(" + img + ")" }
}
else if(namespace == 1) // If on the talk namespace.
{
mw.loader.using('mediawiki.api', function () {
// Retrieve the image using the API.
var api = new mw.Api();
api.get( {
action: 'query',
prop: 'pageimages',
titles: mw.config.get("wgTitle"),
pithumbsize: 300
} ).done( function ( data ) {
pages = data.query.pages;
if(thumb = pages[Object.keys(pages)[0]].thumbnail) // If there is thumbnail for that page.
{
img = thumb.source;
bg = "linear-gradient(0deg, black 0%, #00000032 30%), url(" + img + ")";
}
} );
});
}
if(bg) { $('<style>"#firstHeading-wrapper"{ background-image: '+ bg +' }</style>').appendTo('body'); }