diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-11-14 14:14:25 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-11-14 14:15:16 -0500 |
commit | f4ce4d309c6384ccda68065bbbee5a4404385503 (patch) | |
tree | 93e3aa310572e1e598a11d3b9602358451fa1342 | |
parent | 3175d7d1c271298351a562b45ed9357d4c3c118e (diff) | |
download | jquery-ui-f4ce4d309c6384ccda68065bbbee5a4404385503.tar.gz jquery-ui-f4ce4d309c6384ccda68065bbbee5a4404385503.zip |
Tooltip: Handle synthetic focusin events. Fixes #8740 - Tooltip: Does not hide consistently with dynamically loaded content.
(cherry picked from commit 1b503a237e1dc47739a8a451debbc86e169851e3)
-rw-r--r-- | tests/unit/tooltip/tooltip_core.js | 27 | ||||
-rw-r--r-- | ui/jquery.ui.tooltip.js | 11 |
2 files changed, 37 insertions, 1 deletions
diff --git a/tests/unit/tooltip/tooltip_core.js b/tests/unit/tooltip/tooltip_core.js index 69936dba2..c3568bffc 100644 --- a/tests/unit/tooltip/tooltip_core.js +++ b/tests/unit/tooltip/tooltip_core.js @@ -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 ) ); diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index a113c20be..608501104 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -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 ); @@ -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 ); }); }); |