Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/unit/tooltip/tooltip_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ asyncTest( "content: sync + async callback", function() {
}).tooltip( "open" );
});

// http://bugs.jqueryui.com/ticket/8740
asyncTest( "content: async callback loses focus before load", function() {
expect( 1 );

var element = $( "#tooltipped1" ).tooltip({
content: function( response ) {
element.trigger( "mouseleave" );
setTimeout(function() {
response( "sometext" );
setTimeout(function() {
ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ),
"Tooltip should not display" );
element.tooltip( "destroy" );
start();
});
});
}
});
element.trigger( "mouseover" );
});

test( "content: change while open", function() {
expect( 2 ) ;
var element = $( "#tooltipped1" ).tooltip({
Expand Down
18 changes: 11 additions & 7 deletions ui/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ return $.widget( "ui.tooltip", {
});
}

this._registerCloseHandlers( event, target );
this._updateContent( target, event );
},

Expand All @@ -207,13 +208,14 @@ return $.widget( "ui.tooltip", {
}

content = contentOption.call( target[0], function( response ) {
// ignore async response if tooltip was closed already
if ( !target.data( "ui-tooltip-open" ) ) {
return;
}
// IE may instantly serve a cached response for ajax requests
// delay this call to _open so the other call to _open runs first
that._delay(function() {
// ignore async response if tooltip was closed already
if ( !target.data( "ui-tooltip-open" ) ) {
return;
}

// jQuery creates a special event for focusin when it doesn't
// exist natively. To improve performance, the native event
// object is reused and the type is changed. Therefore, we can't
Expand All @@ -231,7 +233,7 @@ return $.widget( "ui.tooltip", {
},

_open: function( event, target, content ) {
var tooltip, events, delayedShow, a11yContent,
var tooltip, delayedShow, a11yContent,
positionOption = $.extend( {}, this.options.position );

if ( !content ) {
Expand Down Expand Up @@ -312,8 +314,10 @@ return $.widget( "ui.tooltip", {
}

this._trigger( "open", event, { tooltip: tooltip } );
},

events = {
_registerCloseHandlers: function( event, target ) {
var events = {
keyup: function( event ) {
if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
var fakeEvent = $.Event(event);
Expand All @@ -327,7 +331,7 @@ return $.widget( "ui.tooltip", {
// tooltips will handle this in destroy.
if ( target[ 0 ] !== this.element[ 0 ] ) {
events.remove = function() {
this._removeTooltip( tooltip );
this._removeTooltip( this._find( target ) );
};
}

Expand Down