diff --git a/Resources.php b/Resources.php index 96a92f92..bcab4bde 100644 --- a/Resources.php +++ b/Resources.php @@ -72,7 +72,6 @@ $wgResourceModules['ext.uls.init'] = array( 'jquery.client', 'jquery.json', 'jquery.cookie', - 'jquery.uls.data', 'ext.uls.messages', ), 'position' => 'top', diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 44436a77..8de93f25 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -271,6 +271,10 @@ class UniversalLanguageSelectorHooks { $vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors; $vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors; + // An optimization to avoid loading all of uls.data just to get the autonym + $lang = RequestContext::getMain()->getLanguage(); + $vars['wgULSCurrentAutonym'] = $lang->fetchLanguageName( $lang->getCode() ); + if ( is_string( $wgULSFontRepositoryBasePath ) ) { $vars['wgULSFontRepositoryBasePath'] = $wgULSFontRepositoryBasePath; } else { diff --git a/resources/js/ext.uls.init.js b/resources/js/ext.uls.init.js index cb08fc43..a4a8d836 100644 --- a/resources/js/ext.uls.init.js +++ b/resources/js/ext.uls.init.js @@ -47,6 +47,7 @@ mw.uls = mw.uls || {}; mw.uls.previousLanguagesCookie = 'uls-previous-languages'; + mw.uls.previousLanguageAutonymCookie = 'uls-previous-language-autonym'; mw.uls.languageSettingsModules = ['ext.uls.inputsettings', 'ext.uls.displaysettings']; // What was the last thing that the user did to select the language: @@ -94,6 +95,7 @@ uri.extend( { setlang: language } ); + window.location.href = uri.toString(); } ); @@ -107,8 +109,10 @@ }; mw.uls.setPreviousLanguages = function ( previousLanguages ) { - $.cookie( mw.uls.previousLanguagesCookie, $.toJSON( previousLanguages ), - { path: '/' } ); + $.cookie( mw.uls.previousLanguagesCookie, + $.toJSON( previousLanguages ), + { path: '/' } + ); }; mw.uls.getPreviousLanguages = function () { diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 93be87f7..48b2b802 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -165,13 +165,14 @@ } /** - * The tooltip to be shown when language changed using ULS + * The tooltip to be shown when language changed using ULS. * It also allows to undo the language selection. */ function showULSTooltip() { var ulsPosition = mw.config.get( 'wgULSPosition' ), currentLang = mw.config.get( 'wgUserLanguage' ), previousLang, + previousLanguageAutonym, $ulsTrigger, anonMode, rtlPage = $( 'body' ).hasClass( 'rtl' ), @@ -198,11 +199,14 @@ anonMode = ( mw.user.isAnon() && !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ); - if ( anonMode || !previousLang || !$.uls.data.languages[previousLang] ) { + if ( anonMode || !previousLang ) { // Do not show tooltip return; } + previousLanguageAutonym = $.cookie( mw.uls.previousLanguageAutonymCookie ) || + previousLang; + // Attach a tipsy tooltip to the trigger $ulsTrigger.tipsy( { gravity: tipsyGravity[ulsPosition], @@ -213,12 +217,15 @@ title: function () { var link; - link = $( '' ).text( $.uls.data.getAutonym( previousLang ) ) + link = $( '' ).text( previousLanguageAutonym ) .attr( { href: '#', 'class': 'uls-prevlang-link', lang: previousLang, - dir: $.uls.data.getDir( 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 @@ -228,6 +235,15 @@ } } ); + // Now that we set the previous languages, + // we can set the cookie of the previous autonym. + // TODO: Refactor this, because it doesn't directly belong + // to the tooltip. + $.cookie( mw.uls.previousLanguageAutonymCookie, + mw.config.get( 'wgULSCurrentAutonym' ), + { path: '/' } + ); + function showTipsy( timeout ) { var tipsyTimer = 0;