Utilisateur:A123/EditZeroth.js

Aller à la navigation Aller à la recherche

Note : après avoir enregistré tes préférences, tu devras forcer le rechargement complet du cache de ton navigateur pour voir les changements. Mozilla Firefox / Safari : maintiens la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou presse Maj-Ctrl-R (Maj-Cmd-R sur Apple Mac) ; Internet Explorer / Opera : maintiens la touche Ctrl en cliquant sur le bouton Actualiser ou presse Ctrl-F5.

//gadget provenant de Wikipedia

if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {

	mw.loader.using( [ 'user', 'mediawiki.util' ], function () {
		$( function ( $ ) {
			'use strict';

			var lang = mw.config.get( 'wgUserLanguage' ),
				messages = {
					fr: {
						'editZeroth-portlet-name': 'En-tête',
						'editZeroth-summary-prefix': '/* Introduction */ ',
						'editZeroth-portlet-description': 'Modifier l’en-tête de la page'
					},
					en: {
						'editZeroth-portlet-name': 'Lead',
						'editZeroth-summary-prefix': '/* Lead section */ ',
						'editZeroth-portlet-description': 'Edit the lead section of this page'
					}
				},
				$editPortlet = $( '#ca-edit' ),
				skin = mw.config.get( 'skin' ),
				summaryPrefix,
				portletLink,
				$editZeroPortlet;

			mw.messages.set( messages.en );
			if ( lang !== 'en' && lang in messages ) {
				mw.messages.set( messages[ lang ] );
			}

			if ( !mw.config.get( 'wgIsProbablyEditable' ) ) {
				return;
			}

			if ( typeof window.EditZeroth_summary !== 'undefined' ) {
				summaryPrefix = window.EditZeroth_summary;
			} else {
				summaryPrefix = mw.msg( 'editZeroth-summary-prefix' );
			}

			portletLink = mw.util.addPortletLink(
				( skin === 'vector' || skin === 'timeless' || skin === 'vector-2022' ) ? 'p-views' : 'p-cactions',
				mw.util.getUrl( null, { action: 'edit', section: 0, summary: summaryPrefix } ),
				mw.msg( 'editZeroth-portlet-name' ),
				'ca-edit-0',
				mw.msg( 'editZeroth-portlet-description' ),
				'',
				( $editPortlet.length > 0 && $editPortlet.next().length > 0 ) ? $editPortlet.next() : null
			);
			$editZeroPortlet = $( portletLink );

			if ( skin === 'monobook' ) {
				$editZeroPortlet.after( ' ' );
			}
			
			$editZeroPortlet.addClass( 'collapsible vector-tab-noicon' );

			if ( $editPortlet.hasClass( 'istalk' ) ) {
				$editZeroPortlet.addClass( 'istalk' );
			}

			if ( $editPortlet.hasClass( 'selected' ) ) {
				if ( mw.util.getParamValue( 'section' ) === '0' ) {
					$editPortlet.removeClass( 'selected' );
					$editZeroPortlet.addClass( 'selected' );
				}
			}

		} );
	} );
}