From 2dfc1bd9ed8a902cb7fe359ef5344ceac0e2d962 Mon Sep 17 00:00:00 2001 From: Leo Koppelkamm Date: Tue, 26 Apr 2011 10:08:46 +0000 Subject: [PATCH] Followup to r86603 per Bug 28681 : Create public array mw.toolbar.buttons. User scripts can modify it, until it's written to the DOM on doc.ready --- includes/EditPage.php | 3 +- .../mediawiki.action/mediawiki.action.edit.js | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 882c72ba44..21f030f613 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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"; diff --git a/resources/mediawiki.action/mediawiki.action.edit.js b/resources/mediawiki.action/mediawiki.action.edit.js index 3005c17f4a..09dad46527 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.js +++ b/resources/mediawiki.action/mediawiki.action.edit.js @@ -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 = $('', { width : 23, height : 23, @@ -29,18 +35,21 @@ 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; } @@ -72,7 +81,10 @@ } }; scrollEditBox(); - + + // Create button bar + mw.toolbar.init(); + $( '#wpSummary, #wpTextbox1' ).focus( function() { currentFocused = $(this); }); -- 2.20.1