diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /resources/mediawiki.action/mediawiki.action.edit.js | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'resources/mediawiki.action/mediawiki.action.edit.js')
-rw-r--r-- | resources/mediawiki.action/mediawiki.action.edit.js | 129 |
1 files changed, 82 insertions, 47 deletions
diff --git a/resources/mediawiki.action/mediawiki.action.edit.js b/resources/mediawiki.action/mediawiki.action.edit.js index e685ca94..1c51c974 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.js +++ b/resources/mediawiki.action/mediawiki.action.edit.js @@ -1,42 +1,74 @@ -( function ( $, mw ) { - var isReady, toolbar, currentFocused; +( function ( mw, $ ) { + var isReady, toolbar, currentFocused, queue, $toolbar, slice; isReady = false; + queue = []; + $toolbar = false; + slice = Array.prototype.slice; + + /** + * Internal helper that does the actual insertion + * of the button into the toolbar. + * See mw.toolbar.addButton for parameter documentation. + */ + function insertButton( b /* imageFile */, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { + // Backwards compatibility + if ( typeof b !== 'object' ) { + b = { + imageFile: b, + speedTip: speedTip, + tagOpen: tagOpen, + tagClose: tagClose, + sampleText: sampleText, + imageId: imageId, + selectText: selectText + }; + } + var $image = $( '<img>', { + width : 23, + height: 22, + src : b.imageFile, + alt : b.speedTip, + title : b.speedTip, + id : b.imageId || undefined, + 'class': 'mw-toolbar-editbutton' + } ).click( function () { + toolbar.insertTags( b.tagOpen, b.tagClose, b.sampleText, b.selectText ); + return false; + } ); + + $toolbar.append( $image ); + return true; + } toolbar = { - $toolbar: false, - buttons: [], /** - * If you want to add buttons, use - * mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ); + * Add buttons to the toolbar. + * Takes care of race conditions and time-based dependencies + * by placing buttons in a queue if this method is called before + * the toolbar is created. + * @param {Object} button: Object with the following properties: + * - imageFile + * - speedTip + * - tagOpen + * - tagClose + * - sampleText + * - imageId + * - selectText + * For compatiblity, passing the above as separate arguments + * (in the listed order) is also supported. */ addButton: function () { if ( isReady ) { - toolbar.insertButton.apply( toolbar, arguments ); + insertButton.apply( toolbar, arguments ); } else { - toolbar.buttons.push( [].slice.call( arguments ) ); - } - }, - insertButton: function ( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { - var image = $('<img>', { - width : 23, - height: 22, - src : imageFile, - alt : speedTip, - title : speedTip, - id : imageId || '', - 'class': 'mw-toolbar-editbutton' - } ).click( function () { - mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText ); - return false; - } ); - - toolbar.$toolbar.append( image ); - return true; + // Convert arguments list to array + queue.push( slice.call( arguments ) ); + } }, /** - * apply tagOpen/tagClose to selection in textarea, + * Apply tagOpen/tagClose to selection in textarea, * use sampleText instead of selection if there is none. */ insertTags: function ( tagOpen, tagClose, sampleText, selectText ) { @@ -51,7 +83,8 @@ } }, - // For backwards compatibility + // For backwards compatibility, + // Called from EditPage.php, maybe in other places as well. init: function () {} }; @@ -59,29 +92,30 @@ window.addButton = toolbar.addButton; window.insertTags = toolbar.insertTags; - // Explose publicly + // Explose API publicly mw.toolbar = toolbar; $( document ).ready( function () { - var buttons, i, c, iframe; + var buttons, i, b, $iframe; // currentFocus is used to determine where to insert tags currentFocused = $( '#wpTextbox1' ); - // Populate the selector cache for $toolbar - toolbar.$toolbar = $( '#toolbar' ); + // Populate the selector cache for $toolbar + $toolbar = $( '#toolbar' ); // Legacy: Merge buttons from mwCustomEditButtons - buttons = [].concat( toolbar.buttons, window.mwCustomEditButtons ); + buttons = [].concat( queue, window.mwCustomEditButtons ); + // Clear queue + queue.length = 0; for ( i = 0; i < buttons.length; i++ ) { - if ( $.isArray( buttons[i] ) ) { - // Passes our button array as arguments - toolbar.insertButton.apply( toolbar, buttons[i] ); + b = buttons[i]; + if ( $.isArray( b ) ) { + // Forwarded arguments array from mw.toolbar.addButton + insertButton.apply( toolbar, b ); } else { - // Legacy mwCustomEditButtons is an object - c = buttons[i]; - toolbar.insertButton( c.imageFile, c.speedTip, c.tagOpen, - c.tagClose, c.sampleText, c.imageId, c.selectText ); + // Raw object from legacy mwCustomEditButtons + insertButton( b ); } } @@ -92,7 +126,7 @@ isReady = true; // Make sure edit summary does not exceed byte limit - $( '#wpSummary' ).byteLimit( 250 ); + $( '#wpSummary' ).byteLimit( 255 ); /** * Restore the edit box scroll state following a preview operation, @@ -120,15 +154,16 @@ // HACK: make currentFocused work with the usability iframe // With proper focus detection support (HTML 5!) this'll be much cleaner - iframe = $( '.wikiEditor-ui-text iframe' ); - if ( iframe.length > 0 ) { - $( iframe.get( 0 ).contentWindow.document ) + // TODO: Get rid of this WikiEditor code from MediaWiki core! + $iframe = $( '.wikiEditor-ui-text iframe' ); + if ( $iframe.length > 0 ) { + $( $iframe.get( 0 ).contentWindow.document ) // for IE - .add( iframe.get( 0 ).contentWindow.document.body ) + .add( $iframe.get( 0 ).contentWindow.document.body ) .focus( function () { - currentFocused = iframe; + currentFocused = $iframe; } ); } }); -}( jQuery, mediaWiki ) ); +}( mediaWiki, jQuery ) ); |