From: Fomafix Date: Tue, 13 May 2014 18:23:05 +0000 (+0000) Subject: jquery.accessKeyLabel: Replace hardcoded brackets and space X-Git-Tag: 1.31.0-rc.0~15727^2 X-Git-Url: http://git.cyclocoop.org/%28%5B%5E/404?a=commitdiff_plain;h=416ec6298a9118d19aaec75f176207a89055d28c;p=lhc%2Fweb%2Fwiklou.git jquery.accessKeyLabel: Replace hardcoded brackets and space Since If914e26f2af23f04c46f011ad8a276a9d3190583 the brackets of the accesskey are localized, so do it also on the client side. Also added a comment to match php and js. Adjust tests to work on wikis with changed messages. Bug: 65010 Change-Id: Id9908b9efcb923f0b740e2c8fd77d1ef676b489f --- diff --git a/includes/Linker.php b/includes/Linker.php index a912fdeb2b..14821cf929 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -2114,6 +2114,7 @@ class Linker { if ( $options == 'withaccess' ) { $accesskey = self::accesskey( $name ); if ( $accesskey !== false ) { + // Should be build the same as in jquery.accessKeyLabel.js if ( $tooltip === false || $tooltip === '' ) { $tooltip = wfMessage( 'brackets', $accesskey )->escaped(); } else { diff --git a/resources/Resources.php b/resources/Resources.php index 3a6f5e3459..abc166133f 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -202,7 +202,9 @@ return array( 'scripts' => 'resources/src/jquery/jquery.accessKeyLabel.js', 'dependencies' => array( 'jquery.client', + 'jquery.mwExtension', ), + 'messages' => array( 'brackets', 'word-separator' ), 'targets' => array( 'mobile', 'desktop' ), ), 'jquery.appear' => array( diff --git a/resources/src/jquery/jquery.accessKeyLabel.js b/resources/src/jquery/jquery.accessKeyLabel.js index 4caf072745..80b8303bd0 100644 --- a/resources/src/jquery/jquery.accessKeyLabel.js +++ b/resources/src/jquery/jquery.accessKeyLabel.js @@ -3,7 +3,7 @@ * * @class jQuery.plugin.accessKeyLabel */ -( function ( $ ) { +( function ( $, mw ) { // Cached access key prefix for used browser var cachedAccessKeyPrefix, @@ -111,8 +111,10 @@ function getAccessKeyLabel( element ) { * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`) */ function updateTooltipOnElement( element, titleElement ) { - var oldTitle = titleElement.title, - rawTitle = oldTitle.replace( / \[.*?\]$/, '' ), + var array = ( mw.msg( 'word-separator' ) + mw.msg( 'brackets' ) ).split( '$1' ), + regexp = new RegExp( $.map( array, $.escapeRE ).join( '.*?' ) + '$' ), + oldTitle = titleElement.title, + rawTitle = oldTitle.replace( regexp, '' ), newTitle = rawTitle, accessKeyLabel = getAccessKeyLabel( element ); @@ -122,7 +124,8 @@ function updateTooltipOnElement( element, titleElement ) { } if ( accessKeyLabel ) { - newTitle += ' [' + accessKeyLabel + ']'; + // Should be build the same as in Linker::titleAttrib + newTitle += mw.msg( 'word-separator' ) + mw.msg( 'brackets', accessKeyLabel ); } if ( oldTitle !== newTitle ) { titleElement.title = newTitle; @@ -194,4 +197,4 @@ $.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) { * @mixins jQuery.plugin.accessKeyLabel */ -}( jQuery ) ); +}( jQuery, mediaWiki ) ); diff --git a/tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js b/tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js index d5c5d27e3b..60a63f9c62 100644 --- a/tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js @@ -1,5 +1,10 @@ ( function ( $ ) { - QUnit.module( 'jquery.accessKeyLabel', QUnit.newMwEnvironment() ); + QUnit.module( 'jquery.accessKeyLabel', QUnit.newMwEnvironment( { + messages: { + 'brackets': '[$1]', + 'word-separator': ' ' + } + } ) ); var getAccessKeyPrefixTestData = [ //ua string, platform string, expected prefix diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 81fda7e3b2..b2587bea2b 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -5,6 +5,11 @@ }, teardown: function () { $.fn.updateTooltipAccessKeys.setTestMode( false ); + }, + messages: { + // Used by accessKeyLabel in test for addPortletLink + 'brackets': '[$1]', + 'word-separator': ' ' } } ) );