Fix a race condition in classic edit toolbar setup

mediawiki.action.edit used to call mw.toolbar.init on its own during DOMReady -- this required that the module already be loaded *before* DOMReady, *and* that it be fully loaded before the immedate-execution code that sets up the default toolbar items (output from EditPage.php).
This failed since we've gone fully async in the bottom-loading items, and could result in failed calls to mw.toolbar.addButton.

Wrapped those immediate calls in a mediawiki.loader.using call to ensure they're run after the module is loaded, and moved the mw.toolbar.init call into that section so we guarantee it gets run first.
This commit is contained in:
Brion Vibber 2012-01-06 01:38:26 +00:00
parent e4acd105f9
commit 749ebf4316
2 changed files with 9 additions and 4 deletions

View file

@ -2671,7 +2671,7 @@ HTML
)
);
$script = '';
$script = 'mw.loader.using("mediawiki.action.edit", function() {';
foreach ( $toolarray as $tool ) {
if ( !$tool ) {
continue;
@ -2692,6 +2692,14 @@ HTML
$script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
}
// This used to be called on DOMReady from mediawiki.action.edit, which
// ended up causing race conditions with the setup code above.
$script .= "\n" .
"// Create button bar\n" .
"$(function() { mw.toolbar.init(); } );\n";
$script .= '});';
$wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
$toolbar = '<div id="toolbar"></div>';

View file

@ -82,9 +82,6 @@
};
scrollEditBox();
// Create button bar
mw.toolbar.init();
$( 'textarea, input:text' ).focus( function() {
currentFocused = $(this);
});