Use wikiEditor.toolbarReady hook instead of ready event

The hook avoids race conditions as it will run even if
CodeMirror loads after the toolbar.

Change-Id: Ida035fad473210add4a604b3c8d65d2d4edb49dc
This commit is contained in:
Ed Sanders 2020-12-28 23:26:39 +00:00
parent 16f8d02327
commit 5bba5436a8

View file

@ -278,11 +278,11 @@
}
$( function () {
// eslint-disable-next-line no-jquery/no-global-selector
$textbox1 = $( '#wpTextbox1' );
// Add CodeMirror button to the enhanced editing toolbar.
$textbox1.on( 'wikiEditor-toolbar-doneInitialSections', addCodeMirrorToWikiEditor );
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
$textbox1 = $textarea;
addCodeMirrorToWikiEditor();
} );
} );
// Synchronize textarea with CodeMirror before leaving