Merge "Remove the dependency on uls.data"
This commit is contained in:
@@ -72,7 +72,6 @@ $wgResourceModules['ext.uls.init'] = array(
|
||||
'jquery.client',
|
||||
'jquery.json',
|
||||
'jquery.cookie',
|
||||
'jquery.uls.data',
|
||||
'ext.uls.messages',
|
||||
),
|
||||
'position' => 'top',
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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 = $( '<a>' ).text( $.uls.data.getAutonym( previousLang ) )
|
||||
link = $( '<a>' ).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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user