mediawiki-extensions-WikiEd.../modules/realtimepreview/init.js
Ed Sanders 796d82a7ab ESLint: Enforce no-var and autofix
Change-Id: I6f2a1e11acdcdb70902357316b504f903abe8bca
2024-11-15 11:08:22 +00:00

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 );
}
} );