MediaWiki:Gadget-InsertButton.js
Apparence
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.
- Firefox / Safari : Maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
- Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
- Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
- Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
/*
* Allow to insert a button either in the classic or advanced toolbar depending on user preferences.
*
* Call it as:
$.when(
mw.loader.using( [ 'ext.gadget.InsertButton' ] )
).then(function() {
window.insert_button.editForm( {
'img_classic' : 'img_classic_url',
'img_advanced' : 'img_advanced_url',
'tooltip' : 'tooltip help string',
'img_id' : '#id of the image',
'on_click' : function_to_exec_on_click
} );
} );
*/
/**
* Setup the InsertButton global:
*/
if ( window.insert_button === undefined ) {
window.insert_button = {};
}
/**
* The global InsertButton object
*/
( function ( mw, $, is ) {
'use strict';
is.addButtonToWikiEditorToolbar = function ( b ) {
var tools = {};
tools[ b.imageId ] = {
label: b.speedTip,
type: 'button',
icon: b.imageFile,
action: {
type: 'callback',
execute: b.onClick
}
};
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'main',
group: 'insert',
tools: tools
} );
$( '[rel="' + b.imageId + '"]' ).width( 22 );
};
is.addButtonToClassicToolbar = function ( b ) {
mw.toolbar.addButton( {
imageFile: b.imageFile,
speedTip: b.speedTip,
imageId: b.imageId
} );
$( '#' + b.imageId ).off( 'click' ).click( function () {
b.onClick();
return false;
} ).width( 23 );
};
is.do_editForm = function(args) {
var modules, add, img;
// This can be the string "0" if the user disabled the preference ([[bugzilla:52542#c3]])
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 && $.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 ){
modules = [ 'ext.wikiEditor' ];
if (mw.config.get('wgNamespaceNumber') == 104) {
modules.push('ext.proofreadpage.page.edit');
}
img = args.img_advanced;
add = is.addButtonToWikiEditorToolbar;
} else if ( mw.user.options.get( 'showtoolbar' ) == 1 ){
modules = 'mediawiki.toolbar';
img = args.img_classic;
add = is.addButtonToClassicToolbar;
} else {
console.log('is.do_EditForm(): unrecognizable toolbar type');
return;
}
$.when(
mw.loader.using( modules ),
$.ready
).then( function(){
add( {
imageFile: img,
speedTip: args.tooltip,
imageId: args.img_id,
onClick: args.on_click
} );
} );
};
is.editForm = function(args) {
$.when(
// mw.loader.using( [ 'user.options' ] ),
$.ready
).then(
is.do_editForm(args)
);
};
}( mediaWiki, jQuery, window.insert_button ) );