]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip: Treat the tooltip as closing until it's fully removed
authorScott González <scott.gonzalez@gmail.com>
Tue, 5 Aug 2014 18:19:06 +0000 (14:19 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 6 Aug 2014 19:01:58 +0000 (15:01 -0400)
This ensures that we don't trigger the close event twice if the tooltip is
destroyed during the hide animation.

Closes gh-1306

tests/unit/tooltip/tooltip_core.js
ui/tooltip.js

index 710444b442e07fb569603f1189ac5ccf57acb87a..760ffeed2eb5ddd71b1b7ef9023c63e367cee11c 100644 (file)
@@ -154,4 +154,24 @@ asyncTest( "programmatic focus with async content", function() {
        element.focus();
 });
 
+asyncTest( "destroy during hide animation; only one close event", function() {
+       expect( 1 );
+
+       var element = $( "#tooltipped1" ).tooltip({
+               show: false,
+               hide: true
+       });
+
+       element.bind( "tooltipclose", function() {
+               ok( true, "tooltip closed" );
+       });
+
+       element.tooltip( "open" );
+       element.tooltip( "close" );
+       setTimeout(function() {
+               element.tooltip( "destroy" );
+               start();
+       });
+});
+
 }( jQuery ) );
index 52be04dcb91989c9a733b53b92ef3a2120806d5e..048b6324a8e89f9ba596ca9d2614cad515200599 100644 (file)
@@ -296,6 +296,8 @@ return $.widget( "ui.tooltip", {
                        }, this.options.position ) );
                }
 
+               this.hiding = false;
+               this.closing = false;
                tooltip.hide();
 
                this._show( tooltip, this.options.show );
@@ -362,9 +364,12 @@ return $.widget( "ui.tooltip", {
 
                this._removeDescribedBy( target );
 
+               this.hiding = true;
                tooltip.stop( true );
                this._hide( tooltip, this.options.hide, function() {
                        that._removeTooltip( $( this ) );
+                       this.hiding = false;
+                       this.closing = false;
                });
 
                target.removeData( "ui-tooltip-open" );
@@ -385,7 +390,9 @@ return $.widget( "ui.tooltip", {
 
                this.closing = true;
                this._trigger( "close", event, { tooltip: tooltip } );
-               this.closing = false;
+               if ( !this.hiding ) {
+                       this.closing = false;
+               }
        },
 
        _tooltip: function( element ) {