Gerrit Patch Uploader has uploaded a new change for review. https://gerrit.wikimedia.org/r/195363
Change subject: mediawiki.jqueryMsg: Implement a new function $.fn.appendMsg() ...................................................................... mediawiki.jqueryMsg: Implement a new function $.fn.appendMsg() This function allows to append a message to a jQuery object without replacing the current content. Example: $( '<p>' ) .append( 'Text <i>before</i> the message ' ) .appendMsg( 'parentheses', $( '<a>' ).text( 'link' ) ) .append( ' Text <i>after</i> the message.' ); Change-Id: I0c6849933f5aebf35cadf5360443775430896e8c --- M resources/src/mediawiki/mediawiki.jqueryMsg.js 1 file changed, 13 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/63/195363/1 diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index b5c2dba..7f1616a 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -190,16 +190,20 @@ * We append to 'this', which in a jQuery plugin context will be the selected elements. * * @param {Object} options Parser options + * @param {boolean} append Do not empty the jQuery object before appending * @return {Function} Function suitable for assigning to jQuery plugin, such as jQuery#msg * @return {string} return.key Message key. * @return {Array|Mixed} return.replacements Optional variable replacements (variadically or an array). * @return {jQuery} return.return */ - mw.jqueryMsg.getPlugin = function ( options ) { + mw.jqueryMsg.getPlugin = function ( options, append ) { var failableParserFn = getFailableParserFn( options ); return function () { - var $target = this.empty(); + var $target = this; + if ( !append ) { + $target = $target.empty(); + } // TODO: Simply appendWithoutParsing( $target, failableParserFn( arguments ).contents() ) // or Simply appendWithoutParsing( $target, failableParserFn( arguments ) ) $.each( failableParserFn( arguments ).contents(), function ( i, node ) { @@ -1249,6 +1253,13 @@ */ $.fn.msg = mw.jqueryMsg.getPlugin(); + /** + * @method + * @member jQuery + * @see mw.jqueryMsg#getPlugin + */ + $.fn.appendMsg = mw.jqueryMsg.getPlugin( {}, true ); + // Replace the default message parser with jqueryMsg oldParser = mw.Message.prototype.parser; mw.Message.prototype.parser = function () { -- To view, visit https://gerrit.wikimedia.org/r/195363 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0c6849933f5aebf35cadf5360443775430896e8c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits