Nikerabbit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/199874

Change subject: When changing language first time, language code was shown
......................................................................

When changing language first time, language code was shown

Now it shows the language autonym as expected

Change-Id: I1f2c3bca2b5582b917d65533b08545d1332782ab
---
M resources/js/ext.uls.interface.js
1 file changed, 46 insertions(+), 27 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector 
refs/changes/74/199874/1

diff --git a/resources/js/ext.uls.interface.js 
b/resources/js/ext.uls.interface.js
index 88b890b..4618060 100644
--- a/resources/js/ext.uls.interface.js
+++ b/resources/js/ext.uls.interface.js
@@ -164,6 +164,27 @@
        }
 
        /**
+        * Gets the name of the previously active language
+        * @param {string} code Language code of previously selected language.
+        * @return {jQuery.promise}
+        */
+       function getUndoAutonym( code ) {
+               var
+                       deferred = $.Deferred(),
+                       autonym = $.cookie( 
mw.uls.previousLanguageAutonymCookie );
+
+               if ( autonym ) {
+                       deferred.resolve( autonym );
+               } else {
+                       mw.loader.using( 'jquery.uls.data', function () {
+                               deferred.resolve( $.uls.data.getAutonym( code ) 
);
+                       } );
+               }
+
+               return deferred.promise();
+       }
+
+       /**
         * The tooltip to be shown when language changed using ULS.
         * It also allows to undo the language selection.
         */
@@ -171,7 +192,6 @@
                var ulsPosition = mw.config.get( 'wgULSPosition' ),
                        currentLang = mw.config.get( 'wgUserLanguage' ),
                        previousLang,
-                       previousLanguageAutonym,
                        $ulsTrigger,
                        anonMode,
                        rtlPage = $( 'body' ).hasClass( 'rtl' ),
@@ -203,35 +223,34 @@
                        return;
                }
 
-               previousLanguageAutonym = $.cookie( 
mw.uls.previousLanguageAutonymCookie ) ||
-                       previousLang;
+               getUndoAutonym( previousLang ).done( function( autonym ) {
+                       // Attach a tipsy tooltip to the trigger
+                       $ulsTrigger.tipsy( {
+                               gravity: tipsyGravity[ulsPosition],
+                               delayOut: 3000,
+                               html: true,
+                               fade: true,
+                               trigger: 'manual',
+                               title: function () {
+                                       var link;
 
-               // Attach a tipsy tooltip to the trigger
-               $ulsTrigger.tipsy( {
-                       gravity: tipsyGravity[ulsPosition],
-                       delayOut: 3000,
-                       html: true,
-                       fade: true,
-                       trigger: 'manual',
-                       title: function () {
-                               var link;
+                                       link = $( '<a>' ).text( autonym )
+                                               .attr( {
+                                                       href: '#',
+                                                       'class': 
'uls-prevlang-link',
+                                                       lang: previousLang,
+                                                       // We could get dir 
from uls.data,
+                                                       // but we are trying to 
avoid loading it
+                                                       // and 'auto' is safe 
enough in this context
+                                                       dir: 'auto'
+                                               } );
 
-                               link = $( '<a>' ).text( previousLanguageAutonym 
)
-                                       .attr( {
-                                               href: '#',
-                                               'class': 'uls-prevlang-link',
-                                               lang: previousLang,
-                                               // We could get dir from 
uls.data,
-                                               // but we are trying to avoid 
loading it
-                                               // and 'auto' is safe enough in 
this context
-                                               dir: 'auto'
-                                       } );
+                                       // Get the html of the link by wrapping 
it in div first
+                                       link = $( '<div>' ).html( link ).html();
 
-                               // Get the html of the link by wrapping it in 
div first
-                               link = $( '<div>' ).html( link ).html();
-
-                               return mw.message( 
'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link );
-                       }
+                                       return mw.message( 
'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link );
+                               }
+                       } );
                } );
 
                // Now that we set the previous languages,

-- 
To view, visit https://gerrit.wikimedia.org/r/199874
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f2c3bca2b5582b917d65533b08545d1332782ab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to