VisualEditor/Hooks
New target hook
edit
The ve.newTarget
hook has been introduced to replace most of the client hooks listed below.
mw.hook( 've.newTarget' ).add( ( target ) => {
// Check the target is an article
if ( target.constructor.static.name !== 'article' ) {
// Other valid targets exist, e.g. 'discussionTools'
return;
}
// To check if the target is desktop or mobile, one could use:
// isMobile = ve.init.mw.MobileArticleTarget && target instanceof ve.init.mw.MobileArticleTarget;
// isDesktop = ve.init.mw.DesktopArticleTarget && target instanceof ve.init.mw.DesktopArticleTarget;
// Some replacements for existing hooks:
// ve.activationComplete
target.on( 'surfaceReady', () => {
console.log( 'surface ready' );
} );
// ve.toolbarSaveButton.stateChanged
target.on( 'toolbarSaveButtonStateChanged', () => {
console.log( 'toolbar save button changed', target.toolbarSaveButton, target.isSaveable() );
} );
// ve.saveDialog.stateChanged
target.on( 'saveWorkflowChangePanel', () => {
console.log( 'save dialog change panel', target.saveDialog );
} );
// ve.deactivationComplete
target.on( 'teardown', () => {
console.log( 'teardown', target.edited );
} );
} );
Be aware that the target lifecycle varies slightly between platforms. In particular, desktop VisualEditor for articles reuses the target between successive edits in the same pageload -- emitting the target teardown
event each time the edit finishes, but not emitting a new ve.newTarget
hook when the next edit begins. As such, you should avoid per-session setup outside of the surfaceReady
event.
Client hooks
editmw.hook
editName | Platform(s) | When | Users | Usage |
---|---|---|---|---|
ve.skinTabSetupComplete
|
Desktop | The edit tab(s) have been setup and handlers bound | GuidedTour | globalsearch |
ve.activationStart
|
Desktop | The edit link was clicked and VE has started loading | Hides sticky header in Vector2022 | globalsearch |
ve.activate
|
Desktop | VE code has loaded, but not necessarily the document | Planned for deprecation. | globalsearch |
ve.wikitextInteractive
|
Desktop | A wikitext editor is ready for use, either the full 2017WTE, or the temporary editor 2017WTE shows while loading | Extension:Linter, any wikitext gadget that wants to support 2017WTE | globalsearch |
ve.activationComplete
|
Desktop & mobile | A surface is ready for editing. (nb also fires when switching to/from 2017WTE) | Many | globalsearch |
ve.toolbarSaveButton.stateChanged
|
Desktop & mobile | The main save button has been enabled/disabled | GuidedTour | globalsearch |
ve.saveDialog.stateChanged
|
Desktop & mobile | The save dialog has been opened or changed panel | Edit summary gadgets and TemplateSandbox, the Wikipedia Adventure | globalsearch |
ve.deactivate
|
Desktop | VE has started to close | Planned for deprecation. | globalsearch |
ve.deactivationComplete
|
Desktop & mobile | VE has finished closing. Doesn't fire if loading is aborted before the target is ready. | Many | globalsearch |
plugin registry
editName | Platform(s) | When | Users | Usage |
---|---|---|---|---|
mw.libs.ve.addPlugin
|
Desktop | Runs after VE is loaded, but before it is initialized. | Anyone trying to register a tool. | globalsearch |
mw.libs.ve.targetLoader.addPlugin
|
Desktop & mobile | Runs after VE is loaded, but before it is initialized. | Anyone trying to register a tool. | globalsearch |
Server hooks
editName | Platform(s) | Description | Users | Usage |
---|---|---|---|---|
VisualEditorBeforeEditorHook
|
Desktop & mobile | Executed before deciding if the editor is available on a certain page. | FileImporter, Translate | codesearch |
VisualEditorApiVisualEditorEditPreSaveHook
|
API | Executed in calls to ApiVisualEditorEdit using action=save, before the save is attempted. | GrowthExperiments | codesearch |
VisualEditorApiVisualEditorEditPostSaveHook
|
API | Executed in the ApiVisualEditorEdit after a action=save attempt. | GrowthExperiments | codesearch |