From 63bc85649a5def7159383747141fede3f2c89b50 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 15 Feb 2016 12:41:17 +0000 Subject: [PATCH] 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 --- resources/js/ext.uls.interface.js | 116 +++++++++++++++--------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 80cfeab0..14aa040b 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -214,50 +214,9 @@ $( '.uls-settings-trigger' ) : $( '.uls-trigger' ); - previousLanguages = mw.uls.getPreviousLanguages(); - 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 = $( '' ).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 = $( '
' ).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 hideTipsy() { + $ulsTrigger.tipsy( 'hide' ); + } function showTipsy( timeout ) { var tipsyTimer = 0; @@ -295,23 +254,64 @@ tipsyTimer = window.setTimeout( hideTipsy, timeout ); } - function hideTipsy() { - $ulsTrigger.tipsy( 'hide' ); - } + previousLanguages = mw.uls.getPreviousLanguages(); + previousLang = previousLanguages.slice( -1 )[0]; - // The interlanguage position needs some time to settle down - window.setTimeout( function () { - // Show the tipsy tooltip on page load. - showTipsy( 6000 ); - }, 700 ); + previousLanguages.push( currentLang ); + mw.uls.setPreviousLanguages( previousLanguages ); - // manually show the tooltip - $ulsTrigger.on( 'mouseover', function () { - // show only if the ULS panel is not shown - if ( !$( '.uls-menu:visible' ).length ) { - showTipsy( 3000 ); - } + 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 = $( '' ).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 = $( '
' ).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 + window.setTimeout( function () { + // Show the tipsy tooltip on page load. + showTipsy( 6000 ); + }, 700 ); + + // manually show the tooltip + $ulsTrigger.on( 'mouseover', function () { + // show only if the ULS panel is not shown + if ( !$( '.uls-menu:visible' ).length ) { + 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 () {