mediawiki-extensions-WikiEd.../modules/realtimepreview/init.js
Sam Wilson 9a5e7dd919 Realtime preview: allow loading as a gadget
* Prevent the realtimepreview module loading on anything
  other than wikitext pages (as is already done PHP-side
  but that is bypassed when loaded as a gadget).
* Give the #wpTextbox1 a class so we don't always style it.

Bug: T307039
Bug: T308176
Bug: T309330
Change-Id: I26111a61c8cf37520b3619faf09d76445973edd3
2022-06-09 17:27:24 +08:00

28 lines
867 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;
}
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 );
}
}
}
} );
if ( realtimePreview.getUserPref() && realtimePreview.isScreenWideEnough() ) {
realtimePreview.setEnabled();
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).fire( this );
}
} );