// IDs of generated tooltips, needed for destroy
this.tooltips = {};
+
// IDs of parent tooltips where we removed the title attribute
this.parents = {};
this._super( key, value );
if ( key === "content" ) {
- $.each( this.tooltips, function( id, element ) {
- that._updateContent( element );
+ $.each( this.tooltips, function( id, tooltipData ) {
+ that._updateContent( tooltipData.element );
});
}
},
var that = this;
// close open tooltips
- $.each( this.tooltips, function( id, element ) {
+ $.each( this.tooltips, function( id, tooltipData ) {
var event = $.Event( "blur" );
- event.target = event.currentTarget = element[0];
+ event.target = event.currentTarget = tooltipData.element[ 0 ];
that.close( event, true );
});
},
_open: function( event, target, content ) {
- var tooltip, events, delayedShow, a11yContent,
+ var tooltipData, tooltip, events, delayedShow, a11yContent,
positionOption = $.extend( {}, this.options.position );
if ( !content ) {
// Content can be updated multiple times. If the tooltip already
// exists, then just update the content and bail.
- tooltip = this._find( target );
- if ( tooltip.length ) {
- tooltip.find( ".ui-tooltip-content" ).html( content );
+ tooltipData = this._find( target );
+ if ( tooltipData ) {
+ tooltipData.tooltip.find( ".ui-tooltip-content" ).html( content );
return;
}
}
}
- tooltip = this._tooltip( target );
+ tooltipData = this._tooltip( target );
+ tooltip = tooltipData.tooltip;
this._addDescribedBy( target, tooltip.attr( "id" ) );
tooltip.find( ".ui-tooltip-content" ).html( content );
}, this.options.position ) );
}
- this.hiding = false;
- this.closing = false;
tooltip.hide();
this._show( tooltip, this.options.show );
},
close: function( event ) {
- var that = this,
+ var tooltip,
+ that = this,
target = $( event ? event.currentTarget : this.element ),
- tooltip = this._find( target );
+ tooltipData = this._find( target );
+
+ // The tooltip may already be closed
+ if ( !tooltipData ) {
+ return;
+ }
+
+ tooltip = tooltipData.tooltip;
// disabling closes the tooltip, so we need to track when we're closing
// to avoid an infinite loop in case the tooltip becomes disabled on close
- if ( this.closing ) {
+ if ( tooltipData.closing ) {
return;
}
this._removeDescribedBy( target );
- this.hiding = true;
+ tooltipData.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" );
});
}
- this.closing = true;
+ tooltipData.closing = true;
this._trigger( "close", event, { tooltip: tooltip } );
- if ( !this.hiding ) {
- this.closing = false;
+ if ( !tooltipData.hiding ) {
+ tooltipData.closing = false;
}
},
.appendTo( tooltip );
tooltip.appendTo( this.document[0].body );
- this.tooltips[ id ] = element;
- return tooltip;
+
+ return this.tooltips[ id ] = {
+ element: element,
+ tooltip: tooltip
+ };
},
_find: function( target ) {
var id = target.data( "ui-tooltip-id" );
- return id ? $( "#" + id ) : $();
+ return id ? this.tooltips[ id ] : null;
},
_removeTooltip: function( tooltip ) {
var that = this;
// close open tooltips
- $.each( this.tooltips, function( id, element ) {
+ $.each( this.tooltips, function( id, tooltipData ) {
// Delegate to close method to handle common cleanup
- var event = $.Event( "blur" );
- event.target = event.currentTarget = element[0];
+ var event = $.Event( "blur" ),
+ element = tooltipData.element;
+ event.target = event.currentTarget = element[ 0 ];
that.close( event, true );
// Remove immediately; destroying an open tooltip doesn't use the