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.
)
);
- $script = '';
+ $script = 'mw.loader.using("mediawiki.action.edit", function() {';
foreach ( $toolarray as $tool ) {
if ( !$tool ) {
continue;
$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>';
};
scrollEditBox();
- // Create button bar
- mw.toolbar.init();
-
$( 'textarea, input:text' ).focus( function() {
currentFocused = $(this);
});