mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tooltip: Better cleanup on destroy. Fixes #8627 - The Tooltip destroy method is not clearing up the data properties.
This commit is contained in:
parent
96f2aa4c72
commit
0a31a82831
@ -3,13 +3,20 @@
|
|||||||
module( "tooltip: methods" );
|
module( "tooltip: methods" );
|
||||||
|
|
||||||
test( "destroy", function() {
|
test( "destroy", function() {
|
||||||
expect( 2 );
|
expect( 3 );
|
||||||
|
var element = $( "#tooltipped1" );
|
||||||
|
|
||||||
domEqual( "#tooltipped1", function() {
|
domEqual( "#tooltipped1", function() {
|
||||||
$( "#tooltipped1" ).tooltip().tooltip( "destroy" );
|
element.tooltip().tooltip( "destroy" );
|
||||||
});
|
});
|
||||||
|
|
||||||
// make sure that open tooltips are removed on destroy
|
// make sure that open tooltips are removed on destroy
|
||||||
$( "#tooltipped1" ).tooltip().tooltip( "open" ).tooltip( "destroy" );
|
domEqual( "#tooltipped1", function() {
|
||||||
|
element
|
||||||
|
.tooltip()
|
||||||
|
.tooltip( "open", $.Event( "mouseover", { target: element[0] }) )
|
||||||
|
.tooltip( "destroy" );
|
||||||
|
});
|
||||||
equal( $( ".ui-tooltip" ).length, 0 );
|
equal( $( ".ui-tooltip" ).length, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
18
ui/jquery.ui.tooltip.js
vendored
18
ui/jquery.ui.tooltip.js
vendored
@ -317,8 +317,24 @@ $.widget( "ui.tooltip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_destroy: function() {
|
_destroy: function() {
|
||||||
$.each( this.tooltips, function( id ) {
|
var that = this;
|
||||||
|
|
||||||
|
// close open tooltips
|
||||||
|
$.each( this.tooltips, function( id, element ) {
|
||||||
|
// Delegate to close method to handle common cleanup
|
||||||
|
var event = $.Event( "blur" );
|
||||||
|
event.target = event.currentTarget = element[0];
|
||||||
|
that.close( event, true );
|
||||||
|
|
||||||
|
// Remove immediately; destroying an open tooltip doesn't use the
|
||||||
|
// hide animation
|
||||||
$( "#" + id ).remove();
|
$( "#" + id ).remove();
|
||||||
|
|
||||||
|
// Restore the title
|
||||||
|
if ( element.data( "ui-tooltip-title" ) ) {
|
||||||
|
element.attr( "title", element.data( "ui-tooltip-title" ) );
|
||||||
|
element.removeData( "ui-tooltip-title" );
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user