« MediaWiki:Common.js » : différence entre les versions
(Chargement du module mediawiki.api) |
(Animation pour les ...) |
||
(12 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 14 : | Ligne 14 : | ||
/* Menu de gauche collapsible et en tête (Gestion:Tâches/Liste/221/13) */ | /* Menu de gauche collapsible et en tête (Gestion:Tâches/Liste/221/13) */ | ||
$('#p-tb-label').addClass("not-collapsed"); | $('#p-tb-label').addClass("not-collapsed"); | ||
$('#p-tb-label').siblings( | $('#p-tb-label').siblings().toggleClass( "collapsed" ); | ||
$('#p-tb-label').click(function(event) { | $('#p-tb-label').click(function(event) { | ||
console.log(event); | console.log(event); | ||
$(event.target).siblings( | $(event.target).siblings().toggleClass( "collapsed" ); | ||
$(event.target).toggleClass( "not-collapsed" ); | $(event.target).toggleClass( "not-collapsed" ); | ||
}); | }); | ||
$('.collapse').click(); // Collaspe all by default. | $('.collapse').click(); // Collaspe all by default. | ||
Ligne 32 : | Ligne 25 : | ||
/* Add heading image (see Gestion:Tâches/Liste/564) */ | /* Add heading image (see Gestion:Tâches/Liste/564) */ | ||
var namespace = mw.config.get("wgNamespaceNumber"); | var namespace = mw.config.get("wgNamespaceNumber"); | ||
var bg; | |||
if(namespace == 0) // if on the main namespace. | if(namespace == 0) // if on the main namespace. | ||
{ | { | ||
// Retrieve the image in the HTML. | // Retrieve the image in the HTML. | ||
img = $(".mw-capiunto-infobox-spanning").find("img").first().attr("src"); | 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. | else if(namespace == 1) // If on the talk namespace. | ||
Ligne 45 : | Ligne 42 : | ||
api.get( { | api.get( { | ||
action: 'query', | action: 'query', | ||
prop: ' | prop: 'pageimages', | ||
titles: mw.config.get("wgTitle"), | titles: mw.config.get("wgTitle"), | ||
pithumbsize: 300 | pithumbsize: 300 | ||
Ligne 53 : | Ligne 50 : | ||
{ | { | ||
img = thumb.source; | img = thumb.source; | ||
bg = "linear-gradient(0deg, black 0%, #00000032 30%), url(" + img + ")"; | |||
} | } | ||
} ); | } ); | ||
}); | }); | ||
} | } | ||
if(bg) { $('<style>#firstHeading-wrapper { background-image: '+ bg +' }</style>').appendTo('body'); } | |||
if( | |||
// This code goes with Module:Collapsible list. | |||
$(".collapsible-list-toggle").click(function() { | |||
if($(this).html() == '[+]') | |||
{ $(this).html('[-]').prev().fadeIn().prev().toggle(); } | |||
else { $(this).html('[+]').prev().fadeOut().prev().toggle(); } | |||
}); |
Dernière version du 13 mars 2024 à 17:30
/* 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().toggleClass( "collapsed" );
$('#p-tb-label').click(function(event) {
console.log(event);
$(event.target).siblings().toggleClass( "collapsed" );
$(event.target).toggleClass( "not-collapsed" );
});
$('.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'); }
// This code goes with Module:Collapsible list.
$(".collapsible-list-toggle").click(function() {
if($(this).html() == '[+]')
{ $(this).html('[-]').prev().fadeIn().prev().toggle(); }
else { $(this).html('[+]').prev().fadeOut().prev().toggle(); }
});