Skip to content

Commit

Permalink
Tooltip: Handle synthetic focusin events. Fixes #8740 - Tooltip: Does…
Browse files Browse the repository at this point in the history
… not hide consistently with dynamically loaded content.
  • Loading branch information
scottgonzalez committed Nov 14, 2012
1 parent eca5abd commit 1b503a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/unit/tooltip/tooltip_core.js
Expand Up @@ -107,4 +107,31 @@ test( "tooltip on .ui-state-disabled element", function() {
equal( $( ".ui-tooltip" ).length, 0 );
});

// http://bugs.jqueryui.com/ticket/8740
asyncTest( "programmatic focus with async content", function() {
expect( 2 );
var element = $( "#tooltipped1" ).tooltip({
content: function( response ) {
setTimeout(function() {
response( "test" );
});
}
});

element.bind( "tooltipopen", function( event ) {
deepEqual( event.originalEvent.type, "focusin" );

element.bind( "tooltipclose", function( event ) {
deepEqual( event.originalEvent.type, "focusout" );
start();
});

setTimeout(function() {
element.blur();
});
});

element.focus();
});

}( jQuery ) );
11 changes: 10 additions & 1 deletion ui/jquery.ui.tooltip.js
Expand Up @@ -188,7 +188,8 @@ $.widget( "ui.tooltip", {
_updateContent: function( target, event ) {
var content,
contentOption = this.options.content,
that = this;
that = this,
eventType = event ? event.type : null;

if ( typeof contentOption === "string" ) {
return this._open( event, target, contentOption );
Expand All @@ -202,6 +203,14 @@ $.widget( "ui.tooltip", {
// 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() {
// 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
// rely on the type being correct after the event finished
// bubbling, so we set it back to the previous value. (#8740)
if ( event ) {
event.type = eventType;
}
this._open( event, target, response );
});
});
Expand Down

0 comments on commit 1b503a2

Please sign in to comment.