Nikerabbit has uploaded a new change for review.

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

Change subject: Refactor showULSTooltip
......................................................................

Refactor showULSTooltip

Makes the code easier to understand and fixes T52743

Bug: T52743
Change-Id: If508f26b5133284f3059b50d420066a8b4fefb07
---
M resources/js/ext.uls.interface.js
1 file changed, 18 insertions(+), 18 deletions(-)


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

diff --git a/resources/js/ext.uls.interface.js 
b/resources/js/ext.uls.interface.js
index 4618060..6e1e8f7 100644
--- a/resources/js/ext.uls.interface.js
+++ b/resources/js/ext.uls.interface.js
@@ -189,37 +189,37 @@
         * It also allows to undo the language selection.
         */
        function showULSTooltip() {
-               var ulsPosition = mw.config.get( 'wgULSPosition' ),
+               var previousLang, $ulsTrigger, anonMode, showUndo, newLanguage, 
previousLanguages,
+                       ulsPosition = mw.config.get( 'wgULSPosition' ),
                        currentLang = mw.config.get( 'wgUserLanguage' ),
-                       previousLang,
-                       $ulsTrigger,
-                       anonMode,
                        rtlPage = $( 'body' ).hasClass( 'rtl' ),
                        tipsyGravity = {
                                personal: 'n',
                                interlanguage: rtlPage ? 'e' : 'w'
-                       },
-                       previousLanguages = mw.uls.getPreviousLanguages() || [];
-
-               previousLang = previousLanguages.slice( -1 )[0];
+                       };
 
                $ulsTrigger = ( ulsPosition === 'interlanguage' ) ?
                        $( '.uls-settings-trigger' ) :
                        $( '.uls-trigger' );
 
-               if ( previousLang === currentLang ) {
-                       $ulsTrigger.tipsy( { gravity: rtlPage ? 'e' : 'w' } );
+               previousLanguages = mw.uls.getPreviousLanguages() || [];
+               previousLang = previousLanguages.slice( -1 )[0];
 
-                       return;
+               // Whether we see current language for the first time
+               newLanguage = currentLang !== previousLang;
+               // Whether user is able to change language
+               anonMode = ( mw.user.isAnon() && !mw.config.get( 
'wgULSAnonCanChangeLanguage' ) );
+               // Whether user is able to change language, and just did so
+               showUndo = !anonMode && newLanguage && previousLang !== 
undefined;
+
+               if ( newLanguage ) {
+                       previousLanguages.push( currentLang );
+                       mw.uls.setPreviousLanguages( previousLanguages );
                }
 
-               previousLanguages.push( currentLang );
-               mw.uls.setPreviousLanguages( previousLanguages );
-
-               anonMode = ( mw.user.isAnon() && !mw.config.get( 
'wgULSAnonCanChangeLanguage' ) );
-
-               if ( anonMode || !previousLang ) {
-                       // Do not show tooltip
+               if ( !showUndo ) {
+                       // In interlanguage mode, we will have normal tooltip, 
make it look same using tipsy
+                       $ulsTrigger.tipsy( { gravity: tipsyGravity[ulsPosition] 
} );
                        return;
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If508f26b5133284f3059b50d420066a8b4fefb07
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