2021-11-18 10:50:17 +00:00
|
|
|
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
|
2022-06-09 09:27:24 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2024-11-15 10:57:07 +00:00
|
|
|
const RealtimePreview = require( './RealtimePreview.js' );
|
|
|
|
const realtimePreview = new RealtimePreview();
|
2021-11-18 10:50:17 +00:00
|
|
|
$textarea.wikiEditor( 'addToToolbar', {
|
|
|
|
section: 'secondary',
|
|
|
|
group: 'default',
|
|
|
|
tools: {
|
|
|
|
realtimepreview: {
|
|
|
|
type: 'element',
|
|
|
|
element: function ( context ) {
|
2022-05-25 07:10:35 +00:00
|
|
|
return realtimePreview.getToolbarButton( context );
|
2021-11-18 10:50:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2022-04-19 23:34:14 +00:00
|
|
|
if ( realtimePreview.getUserPref() && realtimePreview.isScreenWideEnough() ) {
|
|
|
|
realtimePreview.setEnabled();
|
2022-03-29 05:34:11 +00:00
|
|
|
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).fire( this );
|
2022-03-31 05:03:18 +00:00
|
|
|
}
|
2021-11-18 10:50:17 +00:00
|
|
|
} );
|