Skip to content

Commit 4dbfdce

Browse files
committed
Tooltip: Allow content updates via async response regardless of whether a sync response came back. Added more tests.
1 parent c2ae4e3 commit 4dbfdce

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

tests/unit/tooltip/tooltip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h2 id="qunit-userAgent"></h2>
3737
<div>
3838
<a id="tooltipped1" href="#" title="anchortitle">anchor</a>
3939
<input title="inputtitle">
40-
<span id="fixture-span" data-tooltip="text">span</span>
40+
<span id="fixture-span" title="title-text">span</span>
4141
</div>
4242

4343
</div>

tests/unit/tooltip/tooltip_methods.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
module( "tooltip: methods" );
44

55
test( "destroy", function() {
6+
expect( 2 );
67
domEqual( "#tooltipped1", function() {
78
$( "#tooltipped1" ).tooltip().tooltip( "destroy" );
89
});
10+
11+
// make sure that open tooltips are removed on destroy
12+
$( "#tooltipped1" ).tooltip().tooltip( "open" ).tooltip( "destroy" );
13+
equal( $( ".ui-tooltip" ).length, 0 );
914
});
1015

1116
test( "open/close", function() {
1217
expect( 3 );
1318
$.fx.off = true;
1419
var element = $( "#tooltipped1" ).tooltip();
1520
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
16-
$( ".ui-tooltip" ).each(function() {
17-
console.log( $( this ).html() );
18-
});
21+
1922
element.tooltip( "open" );
2023
var tooltip = $( "#" + element.attr( "aria-describedby" ) );
2124
ok( tooltip.is( ":visible" ) );
25+
2226
element.tooltip( "close" );
2327
ok( tooltip.is( ":hidden" ) );
2428
$.fx.off = false;

tests/unit/tooltip/tooltip_options.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
module( "tooltip: options" );
44

55
test( "items", function() {
6-
var event = $.Event( "mouseenter" );
7-
event.target = $( "[data-tooltip]" )[ 0 ];
6+
expect( 2 );
87
var element = $( "#qunit-fixture" ).tooltip({
9-
items: "[data-tooltip]",
10-
content: function() {
11-
return $( this ).attr( "data-tooltip" );
12-
}
13-
}).tooltip( "open", event );
14-
same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "text" );
8+
items: "#fixture-span"
9+
});
10+
11+
var event = $.Event( "mouseenter" );
12+
event.target = $( "#fixture-span" )[ 0 ];
13+
element.tooltip( "open", event );
14+
same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" );
15+
16+
// make sure default [title] doesn't get used
17+
event.target = $( "#tooltipped1" )[ 0 ];
18+
element.tooltip( "open", event );
19+
same( $( "#tooltipped1" ).attr( "aria-describedby" ), undefined );
20+
1521
element.tooltip( "destroy" );
1622
});
1723

@@ -38,22 +44,22 @@ test( "content: return jQuery", function() {
3844
same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" );
3945
});
4046

41-
/*
42-
TODO broken, probably related to async content
43-
test("content: callback string", function() {
44-
stop();
45-
$("#tooltipped1").tooltip({
46-
content: function(response) {
47-
response("customstring2");
47+
asyncTest( "content: sync + async callback", function() {
48+
expect( 2 );
49+
var element = $( "#tooltipped1" ).tooltip({
50+
content: function( response ) {
4851
setTimeout(function() {
49-
//console.log($("#tooltipped1").attr("aria-describedby"))
50-
same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "customstring2" );
51-
start();
52-
}, 100)
52+
same( $( "#" + element.attr("aria-describedby") ).text(), "loading..." );
53+
54+
response( "customstring2" );
55+
setTimeout(function() {
56+
same( $( "#" + element.attr("aria-describedby") ).text(), "customstring2" );
57+
start();
58+
}, 13 );
59+
}, 13 );
60+
return "loading...";
5361
}
54-
}).tooltip("open");
55-
62+
}).tooltip( "open" );
5663
});
57-
*/
5864

5965
}( jQuery ) );

ui/jquery.ui.tooltip.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ $.widget( "ui.tooltip", {
6363
// IE may instantly serve a cached response for ajax requests
6464
// delay this call to _open so the other call to _open runs first
6565
setTimeout(function() {
66-
// when undefined, it got removeAttr, then ignore (ajax response)
67-
// initially its an empty string, so not undefined
68-
// TODO is there a better approach to enable ajax tooltips to have two updates?
69-
if ( target.attr( "aria-describedby" ) !== undefined ) {
70-
that._open( event, target, response );
71-
}
66+
that._open( event, target, response );
7267
}, 1 );
7368
});
7469
if ( content ) {

0 commit comments

Comments
 (0)