jquery.accessKeyLabel: Replace hardcoded brackets and space
authorFomafix <fomafix@googlemail.com>
Tue, 13 May 2014 18:23:05 +0000 (18:23 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Tue, 13 May 2014 18:23:05 +0000 (18:23 +0000)
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

includes/Linker.php
resources/Resources.php
resources/src/jquery/jquery.accessKeyLabel.js
tests/qunit/suites/resources/jquery/jquery.accessKeyLabel.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index a912fde..14821cf 100644 (file)
@@ -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 {
index 3a6f5e3..abc1661 100644 (file)
@@ -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(
index 4caf072..80b8303 100644 (file)
@@ -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 ) );
index d5c5d27..60a63f9 100644 (file)
@@ -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
index 81fda7e..b2587be 100644 (file)
@@ -5,6 +5,11 @@
                },
                teardown: function () {
                        $.fn.updateTooltipAccessKeys.setTestMode( false );
+               },
+               messages: {
+                       // Used by accessKeyLabel in test for addPortletLink
+                       'brackets': '[$1]',
+                       'word-separator': ' '
                }
        } ) );