« MediaWiki:Common.js » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| (16 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ | /* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ | ||
/* Penser à aligner Mobile.js et Common.js pour la version bureau */ | |||
//alert("common.js"); | |||
//--------------------------------------------------------------------------- | |||
// Javascript nécessaire en exploitation | |||
// Version en exploitation : cette importation doit être dans les deux pages | |||
// Mediawiki:Common.js et Mediawiki:Mobile.js qui sont mutuellement exclusives | |||
// Pour les tests utiliser la connexion Daniel pour mise au point du script dans la | |||
// page Utilisateur:Daniel/common.js | |||
//--------------------------------------------------------------------------- | |||
importScript('MediaWiki:Catpat.js'); | |||
/*******************************************************************************/ | /*******************************************************************************/ | ||
// Les scripts suivants sont spécifiques de la mise en page en version bureau | |||
/********************************************************************************/ | |||
/********************************************************************************/ | |||
/* Javascript applicable à la catégorie des recettes (voir if... plus bas) | /* Javascript applicable à la catégorie des recettes (voir if... plus bas) | ||
/* Javascript pour modifier la navigation Outils */ | /* Javascript pour modifier la navigation Outils */ | ||
| Ligne 101 : | Ligne 97 : | ||
} | } | ||
if($.inArray('Recettes', | dsg_wgCategories = mw.config.get("wgCategories"); | ||
addOnloadHook( CustomizeModificationsOfSidebar ); | if($.inArray('Recettes', dsg_wgCategories) !== -1){ | ||
//alert("105"); | |||
// addOnloadHook( CustomizeModificationsOfSidebar ); deprecated | |||
jQuery( CustomizeModificationsOfSidebar ); | |||
} | } | ||
| Ligne 291 : | Ligne 188 : | ||
'labelMsg': 'A1', | 'labelMsg': 'A1', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'button_head_A1.png', | 'icon': 'resources/assets/button_head_A1.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 304 : | Ligne 201 : | ||
'labelMsg': 'A2', | 'labelMsg': 'A2', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'button_head_A2.png', | 'icon': 'resources/assets/button_head_A2.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 317 : | Ligne 214 : | ||
'labelMsg': 'Galerie', | 'labelMsg': 'Galerie', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'btn_toolbar_gallery.png', | 'icon': 'resources/assets/btn_toolbar_gallery.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 330 : | Ligne 227 : | ||
'labelMsg': 'Date', | 'labelMsg': 'Date', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'button_date.png', | 'icon': 'resources/assets/button_date.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 341 : | Ligne 238 : | ||
'labelMsg': 'Attention', | 'labelMsg': 'Attention', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'button_aviso.png', | 'icon': 'resources/assets/button_aviso.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 353 : | Ligne 250 : | ||
'labelMsg': 'Retour ligne', | 'labelMsg': 'Retour ligne', | ||
'type': 'button', | 'type': 'button', | ||
'icon': 'button_br.png', | 'icon': 'resources/assets/button_br.png', | ||
'action': { | 'action': { | ||
'type': 'encapsulate', | 'type': 'encapsulate', | ||
| Ligne 364 : | Ligne 261 : | ||
label: 'Liens vers', | label: 'Liens vers', | ||
type: 'button', | type: 'button', | ||
icon: 'button_liens.png', | icon: 'resources/assets/button_liens.png', | ||
action: { | action: { | ||
type: 'encapsulate', | type: 'encapsulate', | ||
| Ligne 377 : | Ligne 274 : | ||
label: 'Catégorie', | label: 'Catégorie', | ||
type: 'button', | type: 'button', | ||
icon: 'button_categorie.png', | icon: 'resources/assets/button_categorie.png', | ||
action: { | action: { | ||
type: 'encapsulate', | type: 'encapsulate', | ||
| Ligne 389 : | Ligne 286 : | ||
label: 'Box', | label: 'Box', | ||
type: 'button', | type: 'button', | ||
icon: 'button_box.png', | icon: 'resources/assets/button_box.png', | ||
action: { | action: { | ||
type: 'encapsulate', | type: 'encapsulate', | ||
| Ligne 402 : | Ligne 299 : | ||
label: 'Code', | label: 'Code', | ||
type: 'button', | type: 'button', | ||
icon: 'button_code.png', | icon: 'resources/assets/button_code.png', | ||
action: { | action: { | ||
type: 'encapsulate', | type: 'encapsulate', | ||
| Ligne 417 : | Ligne 314 : | ||
}; | }; | ||
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar | /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */ | ||
if ( | if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) { | ||
mw.loader.using( 'user.options' | mw.loader.using( 'user.options' ).then( function () { | ||
// This can be the string "0" if the user disabled the preference ([[ | // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]]) | ||
if ( mw.user.options.get( 'usebetatoolbar | if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { | ||
$.when( | $.when( | ||
mw.loader.using( 'ext.wikiEditor | mw.loader.using( 'ext.wikiEditor' ), $.ready | ||
).then( customizeToolbar ); | ).then( customizeToolbar ); | ||
} | } | ||
} ); | } ); | ||
} | } | ||
// Add the customizations to LiquidThreads' edit toolbar, if available | // Add the customizations to LiquidThreads' edit toolbar, if available | ||
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar ); | mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar ); | ||
Dernière version du 8 janvier 2024 à 18:13
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
/* Penser à aligner Mobile.js et Common.js pour la version bureau */
//alert("common.js");
//---------------------------------------------------------------------------
// Javascript nécessaire en exploitation
// Version en exploitation : cette importation doit être dans les deux pages
// Mediawiki:Common.js et Mediawiki:Mobile.js qui sont mutuellement exclusives
// Pour les tests utiliser la connexion Daniel pour mise au point du script dans la
// page Utilisateur:Daniel/common.js
//---------------------------------------------------------------------------
importScript('MediaWiki:Catpat.js');
/*******************************************************************************/
// Les scripts suivants sont spécifiques de la mise en page en version bureau
/********************************************************************************/
/********************************************************************************/
/* Javascript applicable à la catégorie des recettes (voir if... plus bas)
/* Javascript pour modifier la navigation Outils */
/* */
/* http://www.mediawiki.org/w/index.php?title=Manual:Interface/Sidebar */
/********************************************************************************/
function ModifySidebar( action, section, name, link ) {
try {
switch ( section ) {
case 'languages':
var target = 'p-lang';
break;
case 'toolbox':
var target = 'p-tb';
break;
case 'navigation':
var target = 'p-navigation';
break;
default:
var target = 'p-' + section;
break;
}
if ( action == 'add' ) {
var node = document.getElementById( target )
.getElementsByTagName( 'div' )[0]
.getElementsByTagName( 'ul' )[0];
var aNode = document.createElement( 'a' );
var liNode = document.createElement( 'li' );
aNode.appendChild( document.createTextNode( name ) );
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
liNode.className = 'plainlinks';
node.appendChild( liNode );
}
if ( action == 'remove' ) {
var list = document.getElementById( target )
.getElementsByTagName( 'div' )[0]
.getElementsByTagName( 'ul' )[0];
var listelements = list.getElementsByTagName( 'li' );
for ( var i = 0; i < listelements.length; i++ ) {
if (
listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
listelements[i].getElementsByTagName( 'a' )[0].href == link
)
{
list.removeChild( listelements[i] );
}
}
}
} catch( e ) {
// let's just ignore what's happened
return;
}
}
function CustomizeModificationsOfSidebar() {
ModifySidebar( 'remove', 'toolbox', 'Pages liées', '' );
ModifySidebar( 'remove', 'toolbox', 'Suivi des pages liées', '' );
ModifySidebar( 'remove', 'toolbox', 'Importer un fichier', 'Spécial:Téléverser' );
ModifySidebar( 'remove', 'toolbox', 'Pages spéciales', 'Spécial:Pages spéciales' );
ModifySidebar( 'remove', 'toolbox', 'Adresse de cette version', '' );
//ModifySidebar( 'remove', 'toolbox', 'Information sur la page', '' );
ModifySidebar( 'add', 'toolbox', 'Importer une image', 'Spécial:Téléverser' );
}
dsg_wgCategories = mw.config.get("wgCategories");
if($.inArray('Recettes', dsg_wgCategories) !== -1){
//alert("105");
// addOnloadHook( CustomizeModificationsOfSidebar ); deprecated
jQuery( CustomizeModificationsOfSidebar );
}
/******************************************************************************/
/* préparation de la barre d'édition */
/* https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization */
/******************************************************************************/
/**
* préparation de la barre d'édition
* https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization
*/
var d_dsg = new Date();
var curr_date_dsg = d_dsg.getDate();
var curr_month_dsg = d_dsg.getMonth() + 1;
var curr_year_dsg = d_dsg.getFullYear();
var customizeToolbar = function() {
/* Your code goes here */
/* Remove le bouton reference
$( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
'section': 'main',
'group': 'insert',
'tool': 'reference'
});
*/
//if($.inArray('Recettes', wgCategories) !== -1){
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'recettes': {
'type': 'booklet',
'deferLoad': true,
'label': 'Ingrédients',
'pages': {
'format': {
'layout': 'table',
'label' : 'Table des ingrédients',
'headings': [
{ 'textMsg': 'wikieditor-toolbar-help-heading-description' },
{ 'textMsg': 'wikieditor-toolbar-help-heading-syntax' },
{ 'textMsg': 'wikieditor-toolbar-help-heading-result' }
],
'rows': [
{
'description': { 'html':'Taper une ligne par ingrédient<br>sans omettre les séparateurs<br>|... /... /...' },
'syntax': { 'html': '{{Ingrédients<br>|nom ingrédient/quantité par personne/unité<br>}}' },
'result': { 'html': 'Un tableau des ingrédients mis en page' }
}
]
}
}
}
}
} );
//}
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'autres': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Autres'
// or 'labelMsg': 'section-emoticons-label' for a localized label
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'autres',
'groups': {
'commandes_dsg': {
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'autres',
'group': 'commandes_dsg',
'tools': {
'a1': {
'labelMsg': 'A1',
'type': 'button',
'icon': 'resources/assets/button_head_A1.png',
'action': {
'type': 'encapsulate',
'options': {
pre: "\n== ",
'peri': 'xxx',
post: " ==\n"
}
}
},
'a2': {
'labelMsg': 'A2',
'type': 'button',
'icon': 'resources/assets/button_head_A2.png',
'action': {
'type': 'encapsulate',
'options': {
pre: "\n=== ",
'peri': 'xxx',
post: " ===\n"
}
}
},
'galerie': {
'labelMsg': 'Galerie',
'type': 'button',
'icon': 'resources/assets/btn_toolbar_gallery.png',
'action': {
'type': 'encapsulate',
'options': {
pre: "<gallery>\n",
'peri': 'image:exemple1.png|aaa\nimage:exemple2.png\n',
post: "</gallery>\n"
}
}
},
'date': {
'labelMsg': 'Date',
'type': 'button',
'icon': 'resources/assets/button_date.png',
'action': {
'type': 'encapsulate',
'options': {
'peri': curr_date_dsg + "/" +curr_month_dsg + "/" +curr_year_dsg
}
}
},
'attention': {
'labelMsg': 'Attention',
'type': 'button',
'icon': 'resources/assets/button_aviso.png',
'action': {
'type': 'encapsulate',
'options': {
pre: "{{Attention}}",
'peri': 'xxx'
}
}
},
'retour_ligne': {
'labelMsg': 'Retour ligne',
'type': 'button',
'icon': 'resources/assets/button_br.png',
'action': {
'type': 'encapsulate',
'options': {
pre: "<br>\n"
}
}
},
'liens': {
label: 'Liens vers',
type: 'button',
icon: 'resources/assets/button_liens.png',
action: {
type: 'encapsulate',
options: {
pre: "{{liens|",
peri: "Page liée",
post: "}}"
}
}
},
'categorie': {
label: 'Catégorie',
type: 'button',
icon: 'resources/assets/button_categorie.png',
action: {
type: 'encapsulate',
options: {
pre: "[[Catégorie:",
peri: "A remplir",
post: "]]"
}
}
},'box': {
label: 'Box',
type: 'button',
icon: 'resources/assets/button_box.png',
action: {
type: 'encapsulate',
options: {
pre: "<blockquote style=\"background: white; border: 1px solid black; padding: 1em;\">\n",
peri: "Texte",
post: "\n</blockquote>\n"
}
}
},
'code': {
label: 'Code',
type: 'button',
icon: 'resources/assets/button_code.png',
action: {
type: 'encapsulate',
options: {
pre: "<pre>\n",
peri: "Code",
post: "\n</pre>\n"
}
}
}
}
} );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
mw.loader.using( 'user.options' ).then( function () {
// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
$.when(
mw.loader.using( 'ext.wikiEditor' ), $.ready
).then( customizeToolbar );
}
} );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );