Ensure module 'jquery.tipsy' is loaded before using

Move the showTipsy calls into the callback.

Move the declaration of the functions hideTipsy and showTipsy before the
new call position.

Also change the order of the declaration of the functions hideTipsy and
showTipsy to avoid a forward reference in showTipsy. Spotted by JSLint.

Bug: T118507
Change-Id: I338a78cde249405459be14948b78cf59d715145a
This commit is contained in:
Fomafix
2016-02-15 12:41:17 +00:00
committed by Nikerabbit
parent 6171eaba10
commit 63bc85649a

View File

@@ -214,50 +214,9 @@
$( '.uls-settings-trigger' ) : $( '.uls-settings-trigger' ) :
$( '.uls-trigger' ); $( '.uls-trigger' );
previousLanguages = mw.uls.getPreviousLanguages(); function hideTipsy() {
previousLang = previousLanguages.slice( -1 )[0]; $ulsTrigger.tipsy( 'hide' );
previousLanguages.push( currentLang );
mw.uls.setPreviousLanguages( previousLanguages );
getUndoAutonym( previousLang ).done( function( autonym ) {
// Attach a tipsy tooltip to the trigger
$ulsTrigger.tipsy( {
gravity: tipsyGravity[ulsPosition],
delayOut: 3000,
html: true,
fade: true,
trigger: 'manual',
title: function () {
var link;
link = $( '<a>' ).text( autonym )
.attr( {
href: '#',
'class': 'uls-prevlang-link',
lang: 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
link = $( '<div>' ).html( link ).html();
return mw.message( 'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link );
} }
} );
} );
// 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;
@@ -295,9 +254,40 @@
tipsyTimer = window.setTimeout( hideTipsy, timeout ); tipsyTimer = window.setTimeout( hideTipsy, timeout );
} }
function hideTipsy() { previousLanguages = mw.uls.getPreviousLanguages();
$ulsTrigger.tipsy( 'hide' ); previousLang = previousLanguages.slice( -1 )[0];
previousLanguages.push( currentLang );
mw.uls.setPreviousLanguages( previousLanguages );
getUndoAutonym( previousLang ).done( function( autonym ) {
// Attach a tipsy tooltip to the trigger
$ulsTrigger.tipsy( {
gravity: tipsyGravity[ulsPosition],
delayOut: 3000,
html: true,
fade: true,
trigger: 'manual',
title: function () {
var link;
link = $( '<a>' ).text( autonym )
.attr( {
href: '#',
'class': 'uls-prevlang-link',
lang: 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
link = $( '<div>' ).html( link ).html();
return mw.message( 'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link );
} }
} );
// The interlanguage position needs some time to settle down // The interlanguage position needs some time to settle down
window.setTimeout( function () { window.setTimeout( function () {
@@ -312,6 +302,16 @@
showTipsy( 3000 ); showTipsy( 3000 );
} }
} ); } );
} );
// 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: '/' }
);
} }
$( document ).ready( function () { $( document ).ready( function () {