Remove jquery.tipsy from UniversalLanguageSelector

This doesn't appear to be justified due to the one use case. This
will now be done via OOjs UI and given jquery.tipsy is deprecated
it is better to replace it (T117720).

Bug: T119417
Bug: T102922
Change-Id: I60cce248884308bf0728d153f6137a8d25e01300
This commit is contained in:
jdlrobson
2016-06-01 16:22:56 -07:00
committed by Nikerabbit
parent 78adcc5e20
commit 798874ffa0
2 changed files with 35 additions and 26 deletions

View File

@@ -20,6 +20,7 @@
"globals": { "globals": {
"mediaWiki": false, "mediaWiki": false,
"OO": false,
"QUnit": false "QUnit": false
} }
} }

View File

@@ -196,31 +196,26 @@
* It also allows to undo the language selection. * It also allows to undo the language selection.
*/ */
function showUndoTooltip( previousLang, previousAutonym ) { function showUndoTooltip( previousLang, previousAutonym ) {
var $ulsTrigger, var $ulsTrigger, ulsPopup, offset,
ulsPosition = mw.config.get( 'wgULSPosition' ), ulsPosition = mw.config.get( 'wgULSPosition' );
rtlPage = $( 'body' ).hasClass( 'rtl' ),
tipsyGravity = {
personal: 'n',
interlanguage: rtlPage ? 'e' : 'w'
};
$ulsTrigger = ( ulsPosition === 'interlanguage' ) ? $ulsTrigger = ( ulsPosition === 'interlanguage' ) ?
$( '.uls-settings-trigger' ) : $( '.uls-settings-trigger' ) :
$( '.uls-trigger' ); $( '.uls-trigger' );
function hideTipsy() { function hideTipsy() {
$ulsTrigger.tipsy( 'hide' ); ulsPopup.toggle( false );
} }
function showTipsy( timeout ) { function showTipsy( timeout ) {
var tipsyTimer = 0; var tipsyTimer = 0;
$ulsTrigger.tipsy( 'show' ); ulsPopup.toggle( true );
ulsPopup.toggleClipping( false );
// if the mouse is over the tooltip, do not hide // if the mouse is over the tooltip, do not hide
$( '.tipsy' ).on( 'mouseover', function () { $( '.tipsy' ).on( 'mouseover', function () {
window.clearTimeout( tipsyTimer ); window.clearTimeout( tipsyTimer );
} ); } ).on( 'mouseout', function () {
$( '.tipsy' ).on( 'mouseout', function () {
tipsyTimer = window.setTimeout( hideTipsy, timeout ); tipsyTimer = window.setTimeout( hideTipsy, timeout );
} ); } );
@@ -248,17 +243,17 @@
tipsyTimer = window.setTimeout( hideTipsy, timeout ); tipsyTimer = window.setTimeout( hideTipsy, timeout );
} }
// Attach a tipsy tooltip to the trigger // remove any existing popups
$ulsTrigger.tipsy( { if ( ulsPopup ) {
gravity: tipsyGravity[ ulsPosition ], ulsPopup.$element.remove();
delayOut: 3000, }
html: true, ulsPopup = new OO.ui.PopupWidget( {
fade: true, padded: true,
trigger: 'manual', width: 300,
title: function () { align: 'forwards',
var link; classes: [ 'tipsy' ],
$content: ( function () {
link = $( '<a>' ).text( previousAutonym ) var link = $( '<a>' ).text( previousAutonym )
.attr( { .attr( {
href: '#', href: '#',
'class': 'uls-prevlang-link', 'class': 'uls-prevlang-link',
@@ -273,10 +268,21 @@
// Get the html of the link by wrapping it in div first // Get the html of the link by wrapping it in div first
link = $( '<div>' ).html( link ).html(); link = $( '<div>' ).html( link ).html();
return mw.message( 'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link ); return $( '<p>' )
} .html(
mw.message( 'ext-uls-undo-language-tooltip-text', '$1' )
.escaped().replace( '$1', link )
);
}() )
} ); } );
// Position popup
offset = $ulsTrigger.offset();
ulsPopup.$element.css( {
top: offset.top + 24,
left: offset.left + $ulsTrigger.outerWidth() / 2
} ).appendTo( 'body' );
// The interlanguage position needs some time to settle down // The interlanguage position needs some time to settle down
window.setTimeout( function () { window.setTimeout( function () {
// Show the tipsy tooltip on page load. // Show the tipsy tooltip on page load.
@@ -453,7 +459,7 @@
} }
function initTooltip() { function initTooltip() {
var previousLanguageCodeStore, previousLanguageAutonymStore, var previousLanguageCodeStore, previousLanguageAutonymStore, module,
previousLanguage, currentLanguage, previousAutonym, currentAutonym; previousLanguage, currentLanguage, previousAutonym, currentAutonym;
if ( !userCanChangeLanguage() ) { if ( !userCanChangeLanguage() ) {
@@ -477,7 +483,9 @@
} }
if ( previousLanguage !== currentLanguage ) { if ( previousLanguage !== currentLanguage ) {
mw.loader.using( 'jquery.tipsy' ).done( function () { // Use oojs-ui-core only after MediaWiki 1.26 is no longer supported
module = mw.loader.getState( 'oojs-ui-core' ) === null ? 'oojs-ui' : 'oojs-ui-core';
mw.loader.using( module ).done( function () {
showUndoTooltip( previousLanguage, previousAutonym ); showUndoTooltip( previousLanguage, previousAutonym );
} ); } );
previousLanguageCodeStore.set( currentLanguage ); previousLanguageCodeStore.set( currentLanguage );