MediaWiki:Common.js

De Banane Atomic
Aller à la navigationAller à la recherche

Note : après avoir publié 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 appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */

// Actions à lancer une fois la page chargée
jQuery(document).ready(function($) {

// focus sur le champs de recherche, sauf en édition
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) === -1 ) {
    $("#searchInput").focus();
}

// Mise en forme du Footer
$("#f-poweredbyico").css("position", "static");
$("#f-poweredbyico").css("top", "0");
$("#footer").css("padding-bottom", "0.4em");
$("#f-poweredbyico").css("float", "none");
$("#f-poweredbyico").appendTo("#footer");
$("#f-copyrightico > a").appendTo("#f-poweredbyico");
$("f-list").css("margin-left", "0");

// WikiEditor Toolbar customization
var customizeToolbar = function() {
$( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
    'section': 'main',
    'group': 'format'
});
$( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
    'section': 'main',
    'group': 'insert'
});

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'section': 'main',
    'groups': {
        'balises': {
            'tools': {
                'newline': {
                    'labelMsg': 'wikieditor-toolbar-tool-newline',
                    'type': 'button',
                    'oouiIcon': 'newline',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': '<br>\n'
                        }
                    }
                },
                'kode': {
                    'label': 'kode',
                    'type': 'button',
                    'text': 'Ko',
                    'oouiIcon': 'code',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "<kode lang=''>\n",
                            'post': "\n</kode>"
                        }
                    }
                },
                'filebox': {
                    'label': 'filebox',
                    'type': 'button',
                    'text': 'Fb',
                    'oouiIcon': 'article',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "<filebox fn=''>\n",
                            'post': "\n</filebox>"
                        }
                    }
                },
                'syntaxhighlight': {
                    'label': 'syntaxhighlight',
                    'type': 'button',
                    'text': 'Sy',
                    'oouiIcon': 'highlight',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "<syntaxhighlight lang='' inline>",
                            'post': "</syntaxhighlight>"
                        }
                    }
                },
                'pre': {
                    'label': 'pre',
                    'type': 'button',
                    'text': 'Pr',
                    'oouiIcon': 'markup',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "<pre>",
                            'post': "</pre>"
                        }
                    }
                }
            }
        },
        'templates': {
            'tools': {
                'boxx': {
                    'label': 'boxx',
                    'type': 'button',
                    'text': 'Bo',
                    'oouiIcon': 'window',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{{boxx|",
                            'post': "}}"
                        }
                    }
                },
                'info': {
                    'label': 'info',
                    'type': 'button',
                    'text': '{i}',
                    'oouiIcon': 'info', /* notice */
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{{info | ",
                            'post': "}}"
                        }
                    }
                },
                'warn': {
                    'label': 'warn',
                    'type': 'button',
                    'text': '{w',
                    'oouiIcon': 'alert',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{{warn | ",
                            'post': "}}"
                        }
                    }
                },
                'list-plus': {
                    'label': 'list-plus',
                    'type': 'button',
                    'text': 'L+',
                    'oouiIcon': 'add',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{{ListPlusMinus|type=plus|list=\n",
                            'post': "\n}}"
                        }
                    }
                },
                'list-minus': {
                    'label': 'list-minus',
                    'type': 'button',
                    'text': 'L-',
                    'oouiIcon': 'subtract',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{{ListPlusMinus|type=minus|list=\n",
                            'post': "\n}}"
                        }
                    }
                }
            }
        },
        'char': {
            'tools': {
                '->': {
                    'label': '\u2192',
                    'type': 'button',
                    'text': '\u2192',
                    'oouiIcon': 'textDirLTR', /* arrowNext */
                    'action': {
                        'type': 'encapsulate', 
                        'options': { 
                            'pre': "\u2192"
                        }
                    }
                },
                '«»': {
                    'label': "\u00ab\u00bb",
                    'type': 'button',
                    'text': '\u00ab\u00bb',
                    'oouiIcon': 'markup', /* ongoingConversation */
                    'action': {
                        'type': 'encapsulate', 
                        'options': { 
                            'pre': "\u00ab ", 
                            'post': " \u00bb" 
                        }
                    }
                }
            }
        },
        'insert': {
            'tools': {
                'category': {
                    'label': 'category',
                    'type': 'button',
                    'text': 'Ca',
                    'oouiIcon': 'linkExternal',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "[[Category:",
                            'post': "]]"
                        }
                    }
                },
                'image': {
                    'label': 'image',
                    'type': 'button',
                    'text': 'Im',
                    'oouiIcon': 'imageGallery',
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "[[File:",
                            'post': "]]"
                        }
                    }
                },
                'table': {
                    'labelMsg': 'wikieditor-toolbar-tool-table',
                    'type': 'button',
                    'oouiIcon': 'table',
                    'filters': [ '#wpTextbox1:not(.toolbar-dialogs)' ],
                    'action': {
                        'type': 'encapsulate',
                        'options': {
                            'pre': "{| class=\"wikitable wtp\" \n",
                            'peri': '! Titre colonne 1\n! Titre colonne 2\n|-\n| colonne1 || colonne2',
                            'post': "\n|}",
                            'ownline': true
                        }
                    }
                },
                nowiki: {
                    labelMsg: 'wikieditor-toolbar-tool-nowiki',
                    type: 'button',
                    oouiIcon: 'noWikiText',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: '<nowiki>',
                            periMsg: 'wikieditor-toolbar-tool-nowiki-example',
                            post: '</nowiki>'
                        }
                    }
                }
            }
        }
    }
} );  // close $('#wpTextbox1').wikiEditor

};  // close customizeToolbar
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -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 );
        }
    } );
}

});  // close jQuery(document).ready