Merge "Remove the dependency on uls.data"
This commit is contained in:
@@ -72,7 +72,6 @@ $wgResourceModules['ext.uls.init'] = array(
|
|||||||
'jquery.client',
|
'jquery.client',
|
||||||
'jquery.json',
|
'jquery.json',
|
||||||
'jquery.cookie',
|
'jquery.cookie',
|
||||||
'jquery.uls.data',
|
|
||||||
'ext.uls.messages',
|
'ext.uls.messages',
|
||||||
),
|
),
|
||||||
'position' => 'top',
|
'position' => 'top',
|
||||||
|
|||||||
@@ -271,6 +271,10 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors;
|
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors;
|
||||||
$vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors;
|
$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 ) ) {
|
if ( is_string( $wgULSFontRepositoryBasePath ) ) {
|
||||||
$vars['wgULSFontRepositoryBasePath'] = $wgULSFontRepositoryBasePath;
|
$vars['wgULSFontRepositoryBasePath'] = $wgULSFontRepositoryBasePath;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
mw.uls = mw.uls || {};
|
mw.uls = mw.uls || {};
|
||||||
mw.uls.previousLanguagesCookie = 'uls-previous-languages';
|
mw.uls.previousLanguagesCookie = 'uls-previous-languages';
|
||||||
|
mw.uls.previousLanguageAutonymCookie = 'uls-previous-language-autonym';
|
||||||
mw.uls.languageSettingsModules = ['ext.uls.inputsettings', 'ext.uls.displaysettings'];
|
mw.uls.languageSettingsModules = ['ext.uls.inputsettings', 'ext.uls.displaysettings'];
|
||||||
|
|
||||||
// What was the last thing that the user did to select the language:
|
// What was the last thing that the user did to select the language:
|
||||||
@@ -94,6 +95,7 @@
|
|||||||
uri.extend( {
|
uri.extend( {
|
||||||
setlang: language
|
setlang: language
|
||||||
} );
|
} );
|
||||||
|
|
||||||
window.location.href = uri.toString();
|
window.location.href = uri.toString();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@@ -107,8 +109,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
mw.uls.setPreviousLanguages = function ( previousLanguages ) {
|
mw.uls.setPreviousLanguages = function ( previousLanguages ) {
|
||||||
$.cookie( mw.uls.previousLanguagesCookie, $.toJSON( previousLanguages ),
|
$.cookie( mw.uls.previousLanguagesCookie,
|
||||||
{ path: '/' } );
|
$.toJSON( previousLanguages ),
|
||||||
|
{ path: '/' }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
mw.uls.getPreviousLanguages = function () {
|
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.
|
* It also allows to undo the language selection.
|
||||||
*/
|
*/
|
||||||
function showULSTooltip() {
|
function showULSTooltip() {
|
||||||
var ulsPosition = mw.config.get( 'wgULSPosition' ),
|
var ulsPosition = mw.config.get( 'wgULSPosition' ),
|
||||||
currentLang = mw.config.get( 'wgUserLanguage' ),
|
currentLang = mw.config.get( 'wgUserLanguage' ),
|
||||||
previousLang,
|
previousLang,
|
||||||
|
previousLanguageAutonym,
|
||||||
$ulsTrigger,
|
$ulsTrigger,
|
||||||
anonMode,
|
anonMode,
|
||||||
rtlPage = $( 'body' ).hasClass( 'rtl' ),
|
rtlPage = $( 'body' ).hasClass( 'rtl' ),
|
||||||
@@ -198,11 +199,14 @@
|
|||||||
|
|
||||||
anonMode = ( mw.user.isAnon() && !mw.config.get( 'wgULSAnonCanChangeLanguage' ) );
|
anonMode = ( mw.user.isAnon() && !mw.config.get( 'wgULSAnonCanChangeLanguage' ) );
|
||||||
|
|
||||||
if ( anonMode || !previousLang || !$.uls.data.languages[previousLang] ) {
|
if ( anonMode || !previousLang ) {
|
||||||
// Do not show tooltip
|
// Do not show tooltip
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previousLanguageAutonym = $.cookie( mw.uls.previousLanguageAutonymCookie ) ||
|
||||||
|
previousLang;
|
||||||
|
|
||||||
// Attach a tipsy tooltip to the trigger
|
// Attach a tipsy tooltip to the trigger
|
||||||
$ulsTrigger.tipsy( {
|
$ulsTrigger.tipsy( {
|
||||||
gravity: tipsyGravity[ulsPosition],
|
gravity: tipsyGravity[ulsPosition],
|
||||||
@@ -213,12 +217,15 @@
|
|||||||
title: function () {
|
title: function () {
|
||||||
var link;
|
var link;
|
||||||
|
|
||||||
link = $( '<a>' ).text( $.uls.data.getAutonym( previousLang ) )
|
link = $( '<a>' ).text( previousLanguageAutonym )
|
||||||
.attr( {
|
.attr( {
|
||||||
href: '#',
|
href: '#',
|
||||||
'class': 'uls-prevlang-link',
|
'class': 'uls-prevlang-link',
|
||||||
lang: previousLang,
|
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
|
// 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 ) {
|
function showTipsy( timeout ) {
|
||||||
var tipsyTimer = 0;
|
var tipsyTimer = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user