mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tooltip: Update open tooltips if the content option changes. Fixes #8544 - Unable to update tooltip content dynamically.
This commit is contained in:
parent
c135fc18a3
commit
dee7c8bd44
@ -46,6 +46,25 @@ asyncTest( "content: sync + async callback", function() {
|
|||||||
}).tooltip( "open" );
|
}).tooltip( "open" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "content: change while open", function() {
|
||||||
|
expect( 2 ) ;
|
||||||
|
var element = $( "#tooltipped1" ).tooltip({
|
||||||
|
content: function() {
|
||||||
|
return "old";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
element.one( "tooltipopen", function( event, ui ) {
|
||||||
|
equal( ui.tooltip.text(), "old", "original content" );
|
||||||
|
element.tooltip( "option", "content", function() {
|
||||||
|
return "new";
|
||||||
|
});
|
||||||
|
equal( ui.tooltip.text(), "new", "updated content" );
|
||||||
|
});
|
||||||
|
|
||||||
|
element.tooltip( "open" );
|
||||||
|
});
|
||||||
|
|
||||||
test( "items", function() {
|
test( "items", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var event,
|
var event,
|
||||||
|
28
ui/jquery.ui.tooltip.js
vendored
28
ui/jquery.ui.tooltip.js
vendored
@ -73,13 +73,22 @@ $.widget( "ui.tooltip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setOption: function( key, value ) {
|
_setOption: function( key, value ) {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
if ( key === "disabled" ) {
|
if ( key === "disabled" ) {
|
||||||
this[ value ? "_disable" : "_enable" ]();
|
this[ value ? "_disable" : "_enable" ]();
|
||||||
this.options[ key ] = value;
|
this.options[ key ] = value;
|
||||||
// disable element style changes
|
// disable element style changes
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._super( key, value );
|
this._super( key, value );
|
||||||
|
|
||||||
|
if ( key === "content" ) {
|
||||||
|
$.each( this.tooltips, function( id, element ) {
|
||||||
|
that._updateContent( element );
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_disable: function() {
|
_disable: function() {
|
||||||
@ -114,9 +123,7 @@ $.widget( "ui.tooltip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
open: function( event ) {
|
open: function( event ) {
|
||||||
var content,
|
var target = $( event ? event.target : this.element )
|
||||||
that = this,
|
|
||||||
target = $( event ? event.target : this.element )
|
|
||||||
.closest( this.options.items );
|
.closest( this.options.items );
|
||||||
|
|
||||||
// No element to show a tooltip for
|
// No element to show a tooltip for
|
||||||
@ -140,6 +147,13 @@ $.widget( "ui.tooltip", {
|
|||||||
|
|
||||||
target.data( "tooltip-open", true );
|
target.data( "tooltip-open", true );
|
||||||
|
|
||||||
|
this._updateContent( target, event );
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateContent: function( target, event ) {
|
||||||
|
var content,
|
||||||
|
that = this;
|
||||||
|
|
||||||
content = this.options.content.call( target[0], function( response ) {
|
content = this.options.content.call( target[0], function( response ) {
|
||||||
// ignore async response if tooltip was closed already
|
// ignore async response if tooltip was closed already
|
||||||
if ( !target.data( "tooltip-open" ) ) {
|
if ( !target.data( "tooltip-open" ) ) {
|
||||||
@ -147,12 +161,12 @@ $.widget( "ui.tooltip", {
|
|||||||
}
|
}
|
||||||
// IE may instantly serve a cached response for ajax requests
|
// IE may instantly serve a cached response for ajax requests
|
||||||
// delay this call to _open so the other call to _open runs first
|
// delay this call to _open so the other call to _open runs first
|
||||||
setTimeout(function() {
|
that._delay(function() {
|
||||||
that._open( event, target, response );
|
this._open( event, target, response );
|
||||||
}, 1 );
|
});
|
||||||
});
|
});
|
||||||
if ( content ) {
|
if ( content ) {
|
||||||
that._open( event, target, content );
|
this._open( event, target, content );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user