mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-12-21 20:33:06 +00:00
796d82a7ab
Change-Id: I6f2a1e11acdcdb70902357316b504f903abe8bca
28 lines
871 B
JavaScript
28 lines
871 B
JavaScript
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
|
|
|
|
// Guard against this module being loaded for non-wikitext pages.
|
|
// This is already done in Hooks.php but Realtime Preview can also be loaded as a gadget so this is necessary.
|
|
if ( mw.config.get( 'wgPageContentModel' ) !== 'wikitext' ) {
|
|
return;
|
|
}
|
|
|
|
const RealtimePreview = require( './RealtimePreview.js' );
|
|
const realtimePreview = new RealtimePreview();
|
|
$textarea.wikiEditor( 'addToToolbar', {
|
|
section: 'secondary',
|
|
group: 'default',
|
|
tools: {
|
|
realtimepreview: {
|
|
type: 'element',
|
|
element: function ( context ) {
|
|
return realtimePreview.getToolbarButton( context );
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
if ( realtimePreview.getUserPref() && realtimePreview.isScreenWideEnough() ) {
|
|
realtimePreview.setEnabled();
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).fire( this );
|
|
}
|
|
} );
|