Followup to r86603 per Bug 28681 : Create public array mw.toolbar.buttons. User scrip...
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Tue, 26 Apr 2011 10:08:46 +0000 (10:08 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Tue, 26 Apr 2011 10:08:46 +0000 (10:08 +0000)
includes/EditPage.php
resources/mediawiki.action/mediawiki.action.edit.js

index 882c72b..21f030f 100644 (file)
@@ -2414,9 +2414,8 @@ HTML
                                array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
                        $script .= "mw.toolbar.addButton($paramList);\n";
                }
-               $script .= "mw.toolbar.init();\n";
                $wgOut->addScript( Html::inlineScript(
-                       "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }"
+                       "if ( window.mediaWiki ) {{$script}}"
                ) );
 
                $toolbar .= "\n</div>";
index 3005c17..09dad46 100644 (file)
@@ -4,7 +4,13 @@
        
        mw.toolbar = {
                $toolbar : $( '#toolbar' ),
-               addButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
+               buttons : [],
+               // If you want to add buttons, use 
+               // mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText );
+               addButton : function() {
+                       this.buttons.push( [].slice.call( arguments ) );
+               },
+               insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
                        var image = $('<img>', {
                                width  : 23,
                                height : 23,
                                currentFocused.textSelection(
                                        'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
                                );
-                               return;
                        }
                }, 
                init : function() {
                        // Legacy
-                       // Print out buttons from mwCustomEditButtons
-                       // If you want to add buttons, use 
-                       // $( document ).ready( function () { mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) } );
-                       var c;
-                       for ( var i = 0; i < window.mwCustomEditButtons.length; i++ ) {
-                               c = window.mwCustomEditButtons[i];
-                               mw.toolbar.addButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
+                       // Merge buttons from mwCustomEditButtons
+                       var buttons = [].concat( this.buttons, window.mwCustomEditButtons );
+                       for ( var i = 0; i < buttons.length; i++ ) {
+                               if ( buttons[i] instanceof Array ) {
+                                       // Passes our button array as arguments
+                                       mw.toolbar.insertButton.apply( this, buttons[i] );
+                               } else {
+                                       // Legacy mwCustomEditButtons is an object
+                                       var c = buttons[i];
+                                       mw.toolbar.insertButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
+                               }
                        }
                        return true;
                }
                        }
                };
                scrollEditBox();
-
+               
+               // Create button bar
+               mw.toolbar.init();
+               
                $( '#wpSummary, #wpTextbox1' ).focus( function() {
                        currentFocused = $(this);
                });