]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip: handle removal of elements with delegated tooltips. Fixed #8646 - Delegated...
authorAndrew Couch <acouch@bluewolf.com>
Mon, 15 Oct 2012 20:15:36 +0000 (16:15 -0400)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sun, 21 Oct 2012 17:15:44 +0000 (13:15 -0400)
tests/unit/tooltip/tooltip.html
tests/unit/tooltip/tooltip_core.js
ui/jquery.ui.tooltip.js

index f6e60b367353e9b5e827d1766d98d447410b7dc4..2c9667ff5071113ade4c771a41df8e1606cb449f 100644 (file)
@@ -43,6 +43,7 @@
        <input title="inputtitle">
        <span id="multiple-describedby" aria-describedby="fixture-span" title="...">aria-describedby</span>
        <span id="fixture-span" title="title-text">span</span>
+       <span id="contains-tooltipped"><span id="contained-tooltipped" title="foobar">baz</span></span>
 </div>
 
 </div>
index 2b39253a270badb7948b26871c66800b13e7113d..06fb194cd7cec4aa3c6e5073d22f347d49899991 100644 (file)
@@ -44,4 +44,17 @@ test( "accessibility", function() {
        equal( element.attr( "title" ), "...", "title restored when closed" );
 });
 
+test( "delegated removal", function() {
+       expect( 2 );
+
+       var container = $( "#contains-tooltipped" ).tooltip(),
+               element = $( "#contained-tooltipped" );
+
+       element.trigger( "mouseover" );
+       equal( $( ".ui-tooltip" ).length, 1 );
+
+       container.empty();
+       equal( $( ".ui-tooltip" ).length, 0 );
+});
+
 }( jQuery ) );
index b56d939e83145b4ce9b828b8aa14297b01c4b40d..1be56c7ea35117bd7619b6adc84c5c7087287acf 100644 (file)
@@ -207,6 +207,7 @@ $.widget( "ui.tooltip", {
 
        _open: function( event, target, content ) {
                var tooltip, positionOption, events;
+
                if ( !content ) {
                        return;
                }
@@ -268,6 +269,9 @@ $.widget( "ui.tooltip", {
                                        fakeEvent.currentTarget = target[0];
                                        this.close( fakeEvent, true );
                                }
+                       },
+                       remove: function( event ) {
+                               this._removeTooltip( tooltip );
                        }
                };
                if ( !event || event.type === "mouseover" ) {
@@ -299,12 +303,15 @@ $.widget( "ui.tooltip", {
 
                tooltip.stop( true );
                this._hide( tooltip, this.options.hide, function() {
-                       $( this ).remove();
-                       delete that.tooltips[ this.id ];
+                       that._removeTooltip( $( this ) );
                });
 
                target.removeData( "tooltip-open" );
                this._off( target, "mouseleave focusout keyup" );
+               // Remove 'remove' binding only on delegated targets
+               if ( target[0] !== this.element[0] ) {
+                       this._off( target, "remove" );
+               }
                this._off( this.document, "mousemove" );
 
                if ( event && event.type === "mouseleave" ) {
@@ -344,6 +351,11 @@ $.widget( "ui.tooltip", {
                return id ? $( "#" + id ) : $();
        },
 
+       _removeTooltip: function( tooltip ) {
+               tooltip.remove();
+               delete this.tooltips[ tooltip.attr( "id" ) ];
+       },
+
        _destroy: function() {
                var that = this;