Support UI language change when global preferences are present
Notable changes: * First query global preferences to detect if global language setting is in use. If there is no global language setting, or if GlobalPreferences extension is not installed, it will fall back to changing the language as usual. If global language setting is found, it will add an override instead. * If a local override is added, the undo tooltip is different and links to the global preferences page. The task design shows mw.notify style popup located on a bottom right corner (LTR). I deviate from the design and re-use the old undo tooltip with a different message instead, for consistency. The message is chosen depending on whether local storage value `uls-gp` is set to '1' (set in mw.uls.changeLanguage). * I removed one use of deprecated mediawiki.api.options module. One other use still remains. * I changed tooltip text generation from html acrobatics to use mw.message.parseDom. Because of that I also had to move the click handler to avoid buildup of click handlers. * In message documentation fixed acronym -> autonym. Bug: T198206 Change-Id: Ie2ed792e222be919522bd1cdea98042515a0619d
This commit is contained in:
committed by
jenkins-bot
parent
2e5e57d92c
commit
fa9cea4627
@@ -157,24 +157,6 @@
|
||||
// hide the tooltip when clicked on it
|
||||
$( '.uls-tipsy' ).on( 'click', hideTipsy );
|
||||
|
||||
// Event handler for links in the tooltip.
|
||||
// It looks like the tipsy is always created from scratch so that
|
||||
// there wont be multiple event handlers bound to same click.
|
||||
$( 'a.uls-prevlang-link' ).on( 'click.ulstipsy', function ( event ) {
|
||||
var deferred = $.Deferred();
|
||||
|
||||
event.preventDefault();
|
||||
deferred.done( function () {
|
||||
mw.uls.changeLanguage( event.target.lang );
|
||||
} );
|
||||
|
||||
mw.hook( 'mw.uls.language.revert' ).fire( deferred );
|
||||
|
||||
// Delay is zero if event logging is not enabled
|
||||
window.setTimeout( function () {
|
||||
deferred.resolve();
|
||||
}, mw.config.get( 'wgULSEventLogging' ) * 500 );
|
||||
} );
|
||||
tipsyTimer = window.setTimeout( hideTipsy, timeout );
|
||||
}
|
||||
|
||||
@@ -203,9 +185,12 @@
|
||||
$floatableContainer: $ulsTrigger,
|
||||
position: ulsPopupPosition,
|
||||
$content: ( function () {
|
||||
var link = $( '<a>' ).text( previousAutonym )
|
||||
.attr( {
|
||||
href: '#',
|
||||
var messageKey, $link;
|
||||
|
||||
$link = $( '<a>' )
|
||||
.text( previousAutonym )
|
||||
.prop( {
|
||||
href: '',
|
||||
'class': 'uls-prevlang-link',
|
||||
lang: previousLang,
|
||||
// We could get dir from uls.data,
|
||||
@@ -213,16 +198,30 @@
|
||||
// and 'auto' is safe enough in this context.
|
||||
// T130390: must use attr
|
||||
dir: 'auto'
|
||||
} )
|
||||
.on( 'click', function ( event ) {
|
||||
var deferred = $.Deferred();
|
||||
|
||||
event.preventDefault();
|
||||
deferred.done( function () {
|
||||
mw.uls.changeLanguage( event.target.lang );
|
||||
} );
|
||||
|
||||
mw.hook( 'mw.uls.language.revert' ).fire( deferred );
|
||||
|
||||
// Delay is zero if event logging is not enabled
|
||||
window.setTimeout( function () {
|
||||
deferred.resolve();
|
||||
}, mw.config.get( 'wgULSEventLogging' ) * 500 );
|
||||
} );
|
||||
|
||||
// Get the html of the link by wrapping it in div first
|
||||
link = $( '<div>' ).html( link ).html();
|
||||
if ( mw.storage.get( 'uls-gp' ) === '1' ) {
|
||||
messageKey = 'ext-uls-undo-language-tooltip-text-local';
|
||||
} else {
|
||||
messageKey = 'ext-uls-undo-language-tooltip-text';
|
||||
}
|
||||
|
||||
return $( '<p>' )
|
||||
.html(
|
||||
mw.message( 'ext-uls-undo-language-tooltip-text', '$1' )
|
||||
.escaped().replace( '$1', link )
|
||||
);
|
||||
return $( '<p>' ).append( mw.message( messageKey, $link ).parseDom() );
|
||||
}() )
|
||||
} );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user