« MediaWiki:Guidedtour-tour-visual edition.js » : différence entre les versions

De Wikimedica
(Ajout console.log)
(Ajout support pour l'éditeur visuel)
Ligne 1 : Ligne 1 :
// Guided Tour to help users make their first edit.
// Guided Tour to help users make their first edit using the visual editor.
// Designed to work on any Wikipedia article, and can work for other sites with minor message changes.


( function ( window, document, $, mw, gt ) {
( function ( gt ) {
var hasEditSection, tour;
var hasEditSectionAtLoadTime, editSectionSelector = '.mw-editsection-visualeditor',
editPageDescription, editSectionDescription, tour,
pointSavePageStep;
console.log('Loading visual_edition tour.');
console.log('Loaded visual_edition tour.');
// Check if there are section edit links (used later)
function shouldShowForPage() {
hasEditSection = $( '.mw-editsection' ).length > 0;
// Excludes pages with editing restrictions
return mw.config.get( 'wgIsProbablyEditable' );
}


tour = new gt.TourBuilder({name: 'visual_edition'});
// If we shouldn't show it, don't initialize the guiders.
if ( !shouldShowForPage() ) {
return;
}
 
function hasEditSection() {
return $( editSectionSelector ).length > 0;
}
 
function handleVeChange( transitionEvent ) {
var isSaveButtonDisabled;
 
if ( transitionEvent.type === gt.TransitionEvent.MW_HOOK ) {
if ( transitionEvent.hookName === 've.toolbarSaveButton.stateChanged' ) {
isSaveButtonDisabled = transitionEvent.hookArguments[ 0 ];
if ( !isSaveButtonDisabled ) {
return pointSavePageStep;
}
}
 
return gt.TransitionAction.HIDE;
}
}
 
hasEditSectionAtLoadTime = $( editSectionSelector ).length > 0;
 
tour = new gt.TourBuilder( {
name: 'visual_edition',
shouldLog: true,
showConditionally: 'VisualEditor'
} );
tour.firstStep( {
tour.firstStep({
name: 'overlay',
name: 'overlay',
title: ($( '.ve-ce-documentNode[contenteditable="true"]' ).length > 0).toString(), //'Comment modifier une page?',
title: 'Comment modifier une page?',
description: 'Dans ce guide, vous apprendrez à modifier une page. À la fin de ce guide, vous saurez comment rédiger de nouvelles sections, ajouter des images et créer des liens vers d\'autres pages!',
description: 'Dans ce guide, vous apprendrez à modifier une page. À la fin de ce guide, vous saurez comment rédiger de nouvelles sections, ajouter des images et créer des liens vers d\'autres pages!',
overlay: true
overlay: true
} )
}).next('intro');
.next( 'intro' );
 
tour.firstStep( {
tour.step( {
name: 'intro',
name: 'intro',
title: 'Modification d\'une page',
title: 'Modification d\'une page',
description: 'Par défaut, Wikimedica vous permet de consulter ses pages en mode \"Lecture\". Il est cependant possible de modifier une page en cliquant sur le bouton ci-dessus.',
description: 'Par défaut, Wikimedica vous permet de consulter ses pages en mode \"Lecture\". Il est cependant possible de modifier une page en cliquant sur le bouton ci-dessus.',
position: 'bottom',
attachTo: '#ca-ve-edit',
attachTo: '#ca-ve-edit',
position: 'bottom',
// This indicates that we don't want an automatic next button,
// even though we are specifying which step comes next.
allowAutomaticNext: false,
buttons: [ {
buttons: [ {
// Custom logic to specify a button and its behavior
action: hasEditSectionAtLoadTime ? 'next' : 'okay',
// depending on whether there are sections on the page.
action: hasEditSection ? 'next' : 'okay',
onclick: function () {
onclick: function () {
if ( hasEditSection ) {
if ( hasEditSection() ) {
mw.libs.guiders.next();
mw.libs.guiders.next();
} else {
} else {
Ligne 40 : Ligne 67 :
}
}
}
}
} ]
} ],
} )
allowAutomaticNext: false,
// At certain times, called transition points, the callback passed to .transition
allowAutomaticOkay: false
// will be called.  At those times, this tour checks if the user is editing.  If so,
// Tour-level listeners would avoid repeating this for two steps
// the tour returns 'modifier_texte', indicating that the tour should transition to the
} ).listenForMwHooks( 've.activationComplete', 've.toolbarSaveButton.stateChanged' )
// 'modifier_texte' step automatically.
.transition( handleVeChange )
.transition( function () {
.next( 'editSection' );
if ( gt.isEditingWithVisualEditor() ) {
return 'modifier_texte';
}
} )
.next( 'editSection' );


tour.step( {
tour.step( {
Ligne 58 : Ligne 80 :
description: 'Il existe aussi sur chaque page des boutons de modification pour chaque section. Ils permettent alors de se concentrer uniquement sur la section pertinente!',
description: 'Il existe aussi sur chaque page des boutons de modification pour chaque section. Ils permettent alors de se concentrer uniquement sur la section pertinente!',
position: 'right',
position: 'right',
attachTo: '.mw-editsection-visualeditor',
attachTo: editSectionSelector,
// Automatically scroll to this step
autoFocus: true,
// Custom width, in pixels
width: 300
width: 300
} )
} ).listenForMwHooks( 've.activationComplete', 've.toolbarSaveButton.stateChanged' )
.transition( function () {
.transition( function ( transitionEvent ) {
if ( gt.isEditingWithVisualEditor() ) {
if (
return 'modifier_texte';
transitionEvent.type === gt.TransitionEvent.BUILTIN &&
} else if ( !hasEditSection ) {
!hasEditSection()
// Returning HIDE means that the tour should be hidden, but not ended.
) {
return gt.TransitionAction.HIDE;
return gt.TransitionAction.HIDE;
}
} else {
} )
return handleVeChange( transitionEvent );
.back( 'intro' );
}
} )
.back( 'intro' );


tour.step( {
pointSavePageStep = tour.step( {
name: 'modifier_texte',
name: 'pointSavePage',
title: ($( '.ve-ce-documentNode[contenteditable="true"]' ).length > 0).toString(),
title: 'Sauvegarde',
description: 'Afin d\'écrire du texte, vous pouvez simplement cliquer à l\'endroit où vous désirez écrire, et taper le texte désirez. Essayer par exemple d\'écrire \"Voici ma première phrase écrite sur Wikimedica\".',
description: 'Cliquez sur ce bouton pour sauvegarder vos changements.',
attachTo: '#n-help',
attachTo: '.ve-ui-toolbar-saveButton',
autoFocus: true,
position: 'bottomRight',
position: 'right',
// This specifies that, unlike the default, the guider should not close when the user clicks outside of it.
closeOnClickOutside: false
closeOnClickOutside: false
} )
} ).listenForMwHooks( 've.deactivationComplete' )
.transition( function () {
.transition( function () {
// isReviewing checks whether the user is either previewing or showing changes.
if ( !gt.isEditing() ) {
if ( gt.isReviewing() ) {
return gt.TransitionAction.END;
return 'save';
}
} else if ( !gt.isEditingWithVisualEditor() ) {
} );
// When the user is on this step, but neither editing nor reviewing, this tour automatically ends.
return gt.TransitionAction.END;
}
} )
.next( 'save' );
 
tour.step( {
name: 'save',
title: 'You\'re almost done!',
description: 'When you\'re ready, clicking "Save pages" will make your changes visible for everyone.',
attachTo: '#wpSave',
autoFocus: true,
position: 'top',
closeOnClickOutside: false
} )
.transition( function () {
if ( !gt.isReviewing() ) {
return gt.TransitionAction.END;
}
} )
.back( 'modifier_texte' );


} ( window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) );
}( mw.guidedTour ) );

Version du 18 février 2020 à 12:30

// Guided Tour to help users make their first edit using the visual editor.

( function ( gt ) {
	var hasEditSectionAtLoadTime, editSectionSelector = '.mw-editsection-visualeditor',
		editPageDescription, editSectionDescription, tour,
		pointSavePageStep;
	
	console.log('Loaded visual_edition tour.');
	
	function shouldShowForPage() {
		// Excludes pages with editing restrictions
		return mw.config.get( 'wgIsProbablyEditable' );
	}

	// If we shouldn't show it, don't initialize the guiders.
	if ( !shouldShowForPage() ) {
		return;
	}

	function hasEditSection() {
		return $( editSectionSelector ).length > 0;
	}

	function handleVeChange( transitionEvent ) {
		var isSaveButtonDisabled;

		if ( transitionEvent.type === gt.TransitionEvent.MW_HOOK ) {
			if ( transitionEvent.hookName === 've.toolbarSaveButton.stateChanged' ) {
				isSaveButtonDisabled = transitionEvent.hookArguments[ 0 ];
				if ( !isSaveButtonDisabled ) {
					return pointSavePageStep;
				}
			}

			return gt.TransitionAction.HIDE;
		}
	}

	hasEditSectionAtLoadTime = $( editSectionSelector ).length > 0;

	tour = new gt.TourBuilder( {
		name: 'visual_edition',
		shouldLog: true,
		showConditionally: 'VisualEditor'
	} );
	
	tour.firstStep({
		name: 'overlay',
		title: 'Comment modifier une page?',
		description: 'Dans ce guide, vous apprendrez à modifier une page. À la fin de ce guide, vous saurez comment rédiger de nouvelles sections, ajouter des images et créer des liens vers d\'autres pages!',
		overlay: true
	}).next('intro');
	
	tour.firstStep( {
		name: 'intro',
		title: 'Modification d\'une page',
		description: 'Par défaut, Wikimedica vous permet de consulter ses pages en mode \"Lecture\". Il est cependant possible de modifier une page en cliquant sur le bouton ci-dessus.',
		position: 'bottom',
		attachTo: '#ca-ve-edit',
		buttons: [ {
			action: hasEditSectionAtLoadTime ? 'next' : 'okay',
			onclick: function () {
				if ( hasEditSection() ) {
					mw.libs.guiders.next();
				} else {
					mw.libs.guiders.hideAll();
				}
			}
		} ],
		allowAutomaticNext: false,
		allowAutomaticOkay: false
	// Tour-level listeners would avoid repeating this for two steps
	} ).listenForMwHooks( 've.activationComplete', 've.toolbarSaveButton.stateChanged' )
		.transition( handleVeChange )
		.next( 'editSection' );

	tour.step( {
		name: 'editSection',
		title: 'Modification d\'une page (suite)',
		description: 'Il existe aussi sur chaque page des boutons de modification pour chaque section. Ils permettent alors de se concentrer uniquement sur la section pertinente!',
		position: 'right',
		attachTo: editSectionSelector,
		width: 300
	} ).listenForMwHooks( 've.activationComplete', 've.toolbarSaveButton.stateChanged' )
		.transition( function ( transitionEvent ) {
			if (
				transitionEvent.type === gt.TransitionEvent.BUILTIN &&
				!hasEditSection()
			) {
				return gt.TransitionAction.HIDE;
			} else {
				return handleVeChange( transitionEvent );
			}
		} )
		.back( 'intro' );

	pointSavePageStep = tour.step( {
		name: 'pointSavePage',
		title: 'Sauvegarde',
		description: 'Cliquez sur ce bouton pour sauvegarder vos changements.',
		attachTo: '.ve-ui-toolbar-saveButton',
		position: 'bottomRight',
		closeOnClickOutside: false
	} ).listenForMwHooks( 've.deactivationComplete' )
		.transition( function () {
			if ( !gt.isEditing() ) {
				return gt.TransitionAction.END;
			}
		} );

}( mw.guidedTour ) );