mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-30 19:15:43 +00:00
9a5e7dd919
* 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
28 lines
867 B
JavaScript
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 );
|
|
}
|
|
} );
|