Skip to content

Commit 2fbd310

Browse files
committed
Tooltip: Added a destroy method to remove generated tooltip elements.
1 parent 302ad62 commit 2fbd310

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ui/jquery.ui.tooltip.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ $.widget( "ui.tooltip", {
3535
mouseover: "open",
3636
focusin: "open"
3737
});
38+
39+
// IDs of generated tooltips, needed for destroy
40+
this.tooltips = {};
3841
},
3942

4043
_setOption: function( key, value ) {
@@ -114,7 +117,8 @@ $.widget( "ui.tooltip", {
114117
},
115118

116119
close: function( event ) {
117-
var target = $( event ? event.currentTarget : this.element );
120+
var that = this,
121+
target = $( event ? event.currentTarget : this.element );
118122
target.attr( "title", target.data( "tooltip-title" ) );
119123

120124
if ( this.options.disabled ) {
@@ -127,6 +131,7 @@ $.widget( "ui.tooltip", {
127131
tooltip.stop( true );
128132
this._hide( tooltip, this.options.hide, function() {
129133
$( this ).remove();
134+
delete that[ this.id ];
130135
});
131136

132137
// TODO: why isn't click unbound here?
@@ -136,9 +141,10 @@ $.widget( "ui.tooltip", {
136141
},
137142

138143
_tooltip: function() {
139-
var tooltip = $( "<div>" )
144+
var id = "ui-tooltip-" + increments++,
145+
tooltip = $( "<div>" )
140146
.attr({
141-
id: "ui-tooltip-" + increments++,
147+
id: id,
142148
role: "tooltip"
143149
})
144150
.addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content" +
@@ -147,12 +153,20 @@ $.widget( "ui.tooltip", {
147153
.addClass( "ui-tooltip-content" )
148154
.appendTo( tooltip );
149155
tooltip.appendTo( document.body );
156+
this.tooltips[ id ] = true;
150157
return tooltip;
151158
},
152159

153160
_find: function( target ) {
154161
var id = target.attr( "aria-describedby" );
155162
return id ? $( "#" + id ) : $();
163+
},
164+
165+
destroy: function() {
166+
$.each( this.tooltips, function( id ) {
167+
$( "#" + id ).remove();
168+
});
169+
this._super( "destroy" );
156170
}
157171
});
158172

0 commit comments

Comments
 (0)