mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tooltip: Don't crash on empty content
Commit 1f2011ece
removed a `try-catch` around triggering the `remove` handlers
in the `jQuery.cleanData` override. The `try-catch` was meant for old IE but it was
also catching an error coming from the tooltip `remove` handler depending on
being able to find a relevant tooltip. The `_find` method returns `null`, though,
when the tooltip cotent is empty.
Instead of restoring the `try-catch`, handle the `null` case in the `remove` handler.
Fixes gh-1990
Closes gh-1994
Co-authored-by: Claas Augner <github@caugner.de>
Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
This commit is contained in:
parent
1f0851b538
commit
85fba3f107
@ -254,4 +254,74 @@ QUnit.test( "remove conflicting attributes from live region", function( assert )
|
|||||||
.tooltip( "open" );
|
.tooltip( "open" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// gh-1990
|
||||||
|
QUnit.test( "don't crash on empty tooltip content", function( assert ) {
|
||||||
|
var ready = assert.async();
|
||||||
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
var anchor = $( "#tooltipped1" ),
|
||||||
|
input = anchor.next(),
|
||||||
|
actions = [];
|
||||||
|
|
||||||
|
$( document ).tooltip( {
|
||||||
|
show: false,
|
||||||
|
hide: false,
|
||||||
|
content: function() {
|
||||||
|
var title = $( this ).attr( "title" );
|
||||||
|
if ( title === "inputtitle" ) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
},
|
||||||
|
open: function( event, ui ) {
|
||||||
|
actions.push( "open:" + ui.tooltip.text() );
|
||||||
|
},
|
||||||
|
close: function( event, ui ) {
|
||||||
|
actions.push( "close:" + ui.tooltip.text() );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
function step1() {
|
||||||
|
anchor.simulate( "mouseover" );
|
||||||
|
setTimeout( step2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step2() {
|
||||||
|
anchor.simulate( "mouseout" );
|
||||||
|
setTimeout( step3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step3() {
|
||||||
|
input.simulate( "focus" );
|
||||||
|
setTimeout( step4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step4() {
|
||||||
|
input.simulate( "blur" );
|
||||||
|
setTimeout( step5 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step5() {
|
||||||
|
anchor.simulate( "mouseover" );
|
||||||
|
setTimeout( step6 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step6() {
|
||||||
|
anchor.simulate( "mouseout" );
|
||||||
|
setTimeout( step7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step7() {
|
||||||
|
assert.deepEqual( actions, [
|
||||||
|
"open:anchortitle",
|
||||||
|
"close:anchortitle",
|
||||||
|
"open:anchortitle",
|
||||||
|
"close:anchortitle"
|
||||||
|
], "Tooltip opens and closes without crashing" );
|
||||||
|
ready();
|
||||||
|
}
|
||||||
|
|
||||||
|
step1();
|
||||||
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -352,7 +352,10 @@ $.widget( "ui.tooltip", {
|
|||||||
// tooltips will handle this in destroy.
|
// tooltips will handle this in destroy.
|
||||||
if ( target[ 0 ] !== this.element[ 0 ] ) {
|
if ( target[ 0 ] !== this.element[ 0 ] ) {
|
||||||
events.remove = function() {
|
events.remove = function() {
|
||||||
this._removeTooltip( this._find( target ).tooltip );
|
var targetElement = this._find( target );
|
||||||
|
if ( targetElement ) {
|
||||||
|
this._removeTooltip( targetElement.tooltip );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user