From: Tim Starling Date: Sun, 26 Feb 2012 22:46:40 +0000 (+0000) Subject: * Fix r111983 (bug 34662): make mw.toolbar.addButton() work even after DOM ready X-Git-Tag: 1.31.0-rc.0~24495 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=2fe53c67aa2bc7b8029cdc756a700bbfe3689213;p=lhc%2Fweb%2Fwiklou.git * Fix r111983 (bug 34662): make mw.toolbar.addButton() work even after DOM ready * Don't use an empty array as the default for $toolbar, use false which will throw an exception on a logic error. * Fix exception handling in mw.loader: have handlePending() rethrow its exception so that the exception handler in execute() can run, so that the exception gets logged. But don't rethrow the exception in execute(), because that may break other modules. --- diff --git a/resources/mediawiki.action/mediawiki.action.edit.js b/resources/mediawiki.action/mediawiki.action.edit.js index 499aba6f03..c5e38fffa6 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.js +++ b/resources/mediawiki.action/mediawiki.action.edit.js @@ -3,12 +3,17 @@ var currentFocused = $( '#wpTextbox1' ); mw.toolbar = { - $toolbar : [], + $toolbar : false, buttons : [], + isReady : false, // 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 ) ); + if ( isReady ) { + this.insertButton.apply( this, arguments ); + } else { + this.buttons.push( [].slice.call( arguments ) ); + } }, insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { var image = $('', { @@ -42,18 +47,20 @@ init : function() {}, onReady : function() { - mw.toolbar.$toolbar = $( '#toolbar' ); + this.$toolbar = $( '#toolbar' ); + isReady = true; // Legacy // Merge buttons from mwCustomEditButtons var buttons = [].concat( this.buttons, window.mwCustomEditButtons ); for ( var i = 0; i < buttons.length; i++ ) { if ( $.isArray( buttons[i] ) ) { // Passes our button array as arguments - mw.toolbar.insertButton.apply( this, buttons[i] ); + this.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 ); + this.insertButton( c.imageFile, c.speedTip, c.tagOpen, + c.tagClose, c.sampleText, c.imageId, c.selectText ); } } return true; diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index c7e584bea7..4aee9eb737 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -630,6 +630,7 @@ var mw = ( function ( $, undefined ) { j -= 1; } } + throw e; } } @@ -785,7 +786,6 @@ var mw = ( function ( $, undefined ) { console.log( 'mw.loader::execute> Exception thrown by ' + module + ': ' + e.message ); } registry[module].state = 'error'; - throw e; } }