mediawiki-extensions-WikiEd.../modules/realtimepreview/init.js
Sam Wilson 119f25e424 Add event logging for Realtime Preview enabling and disabling
Add two new actions for the 'preview' feature:

* preview-realtime-on – The WikiEditor 'Preview' toolbar button
  was clicked to turn the preview panel on.
* preview-realtime-off – The WikiEditor 'Preview' toolbar button
  was clicked to turn the preview panel off.
* preview-realtime-inuse – Fired without user interaction when the
  WikiEditor preview feature is already on when the editing form is
  opened.

This also adds a new hook for the last of these to use and to match
the enable/disable hooks.

Bug: T298218
Change-Id: I1a2545c2b0491c1d07f9508fab70967d03d61594
2022-04-04 14:25:16 +08:00

21 lines
575 B
JavaScript

mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
var RealtimePreview = require( './RealtimePreview.js' );
var realtimePreview = new RealtimePreview();
$textarea.wikiEditor( 'addToToolbar', {
section: 'secondary',
group: 'default',
tools: {
realtimepreview: {
type: 'element',
element: function ( context ) {
return realtimePreview.getToolbarButton( context ).$element;
}
}
}
} );
if ( realtimePreview.getUserPref() ) {
realtimePreview.enable();
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).fire( this );
}
} );