mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-15 02:04:02 +00:00
Use 'wikiEditor-toolbar-doneInitialSections' as trigger
Also refactor out single use functions and call enableCodeMirror from within addCodeMirrorToWikiEditor. Change-Id: I77d37ae401483e187fe0bc355d7173b57fbe454b
This commit is contained in:
parent
4181729151
commit
9c04302f23
|
@ -252,33 +252,18 @@
|
|||
$codeMirrorButton
|
||||
.attr( 'id', 'mw-editbutton-codemirror' );
|
||||
|
||||
updateToolbarButton();
|
||||
}
|
||||
if ( useCodeMirror ) {
|
||||
enableCodeMirror();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds CodeMirror button to the toolbar
|
||||
*/
|
||||
function addToolbarButton() {
|
||||
// They are using WikiEditor
|
||||
mw.loader.using( 'ext.wikiEditor', function () {
|
||||
// Add CodeMirror button to the enhanced editing toolbar.
|
||||
// Add an additional $() to avoid a race condition with WikiEditor.
|
||||
// FIXME: Solve this with an explicit dependency.
|
||||
$( addCodeMirrorToWikiEditor );
|
||||
} );
|
||||
updateToolbarButton();
|
||||
}
|
||||
|
||||
$( function () {
|
||||
$textbox1 = $( '#wpTextbox1' );
|
||||
// If view is in edit mode, add the button to the toolbar.
|
||||
if ( $textbox1.length ) {
|
||||
addToolbarButton();
|
||||
}
|
||||
|
||||
// enable CodeMirror
|
||||
if ( useCodeMirror ) {
|
||||
$textbox1.on( 'wikiEditor-toolbar-doneInitialSections', enableCodeMirror.bind( this ) );
|
||||
}
|
||||
// Add CodeMirror button to the enhanced editing toolbar.
|
||||
$textbox1.on( 'wikiEditor-toolbar-doneInitialSections', addCodeMirrorToWikiEditor );
|
||||
} );
|
||||
|
||||
// Synchronize textarea with CodeMirror before leaving
|
||||
|
|
Loading…
Reference in a new issue