X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.jqueryMsg.js;h=c82b9cbfb93e9fd8395c43d2ffe027a17db351c5;hb=dcdb8e463e3b2be121c61c91df13ea36d270a602;hp=44b911779940edc1d400a05157d74d1a8ea0a0ed;hpb=d1ac58cd85c46b5c9265ba479a45fd348c554064;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index 44b9117799..c82b9cbfb9 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -136,6 +136,7 @@ function getFailableParserFn( options ) { return function ( args ) { var fallback, + // eslint-disable-next-line new-cap parser = new mw.jqueryMsg.parser( options ), key = args[ 0 ], argsArray = $.isArray( args[ 1 ] ) ? args[ 1 ] : slice.call( args, 1 ); @@ -212,10 +213,11 @@ } return function () { + var failableResult; if ( !failableParserFn ) { failableParserFn = getFailableParserFn( options ); } - var failableResult = failableParserFn( arguments ); + failableResult = failableParserFn( arguments ); if ( format === 'text' || format === 'escaped' ) { return failableResult.text(); } else { @@ -250,10 +252,11 @@ var failableParserFn; return function () { + var $target; if ( !failableParserFn ) { failableParserFn = getFailableParserFn( options ); } - var $target = this.empty(); + $target = this.empty(); appendWithoutParsing( $target, failableParserFn( arguments ) ); return $target; }; @@ -272,6 +275,7 @@ this.settings.onlyCurlyBraceTransform = ( this.settings.format === 'text' || this.settings.format === 'escaped' ); this.astCache = {}; + // eslint-disable-next-line new-cap this.emitter = new mw.jqueryMsg.htmlEmitter( this.settings.language, this.settings.magic ); }; @@ -292,10 +296,10 @@ /** * Fetch the message string associated with a key, return parsed structure. Memoized. - * Note that we pass '[' + key + ']' back for a missing message here. + * Note that we pass '⧼' + key + '⧽' back for a missing message here. * * @param {string} key - * @return {string|Array} string of '[key]' if message missing, simple string if possible, array of arrays if needs parsing + * @return {string|Array} string of '⧼key⧽' if message missing, simple string if possible, array of arrays if needs parsing */ getAst: function ( key ) { var wikiText; @@ -303,7 +307,7 @@ if ( !this.astCache.hasOwnProperty( key ) ) { wikiText = this.settings.messages.get( key ); if ( typeof wikiText !== 'string' ) { - wikiText = '\\[' + key + '\\]'; + wikiText = '⧼' + key + '⧽'; } this.astCache[ key ] = this.wikiTextToAst( wikiText ); } @@ -903,7 +907,8 @@ /** * Starts the parse * - * @param {Function} rootExpression root parse function + * @param {Function} rootExpression Root parse function + * @return {Array|null} */ function start( rootExpression ) { var result = nOrMore( 0, rootExpression )(); @@ -933,10 +938,13 @@ /** * htmlEmitter - object which primarily exists to emit HTML from parser ASTs + * + * @param {Object} language + * @param {Object} magic */ mw.jqueryMsg.htmlEmitter = function ( language, magic ) { - this.language = language; var jmsg = this; + this.language = language; $.each( magic, function ( key, val ) { jmsg[ key.toLowerCase() ] = function () { return val; @@ -1046,6 +1054,7 @@ * It may, though, if the wikitext appears in extension-controlled content. * * @param {string[]} nodes + * @return {jQuery} */ wikilink: function ( nodes ) { var page, anchor, url, $el; @@ -1126,11 +1135,18 @@ } else { $el = $( '' ); if ( typeof arg === 'function' ) { - $el.attr( 'href', '#' ) - .click( function ( e ) { - e.preventDefault(); + $el.attr( { + role: 'button', + tabindex: 0 } ) - .click( arg ); + .on( 'click keypress', function ( e ) { + if ( + e.type === 'click' || + e.type === 'keypress' && e.which === 13 + ) { + arg.call( this, e ); + } + } ); } else { $el.attr( 'href', textify( arg ) ); } @@ -1268,7 +1284,7 @@ * @return {number|string} Formatted number */ formatnum: function ( nodes ) { - var isInteger = ( nodes[ 1 ] && nodes[ 1 ] === 'R' ) ? true : false, + var isInteger = !!nodes[ 1 ] && nodes[ 1 ] === 'R', number = nodes[ 0 ]; return this.language.convertNumber( number, isInteger ); @@ -1364,6 +1380,6 @@ return function () { return reusableParent.msg( this.key, this.parameters ).contents().detach(); }; - } )(); + }() ); }( mediaWiki, jQuery ) );