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:
Fomafix 2019-02-25 22:28:40 +01:00 committed by Ed Sanders
parent 4181729151
commit 9c04302f23

View file

@ -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