Tooltip: Allow content updates via async response regardless of whether a sync response came back. Added more tests.

This commit is contained in:
Scott González
2011-05-28 17:36:57 -04:00
parent c2ae4e3fe4
commit 4dbfdcede3
4 changed files with 37 additions and 32 deletions

View File

@@ -37,7 +37,7 @@
<div>
<a id="tooltipped1" href="#" title="anchortitle">anchor</a>
<input title="inputtitle">
<span id="fixture-span" data-tooltip="text">span</span>
<span id="fixture-span" title="title-text">span</span>
</div>
</div>

View File

@@ -3,9 +3,14 @@
module( "tooltip: methods" );
test( "destroy", function() {
expect( 2 );
domEqual( "#tooltipped1", function() {
$( "#tooltipped1" ).tooltip().tooltip( "destroy" );
});
// make sure that open tooltips are removed on destroy
$( "#tooltipped1" ).tooltip().tooltip( "open" ).tooltip( "destroy" );
equal( $( ".ui-tooltip" ).length, 0 );
});
test( "open/close", function() {
@@ -13,12 +18,11 @@ test( "open/close", function() {
$.fx.off = true;
var element = $( "#tooltipped1" ).tooltip();
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
$( ".ui-tooltip" ).each(function() {
console.log( $( this ).html() );
});
element.tooltip( "open" );
var tooltip = $( "#" + element.attr( "aria-describedby" ) );
ok( tooltip.is( ":visible" ) );
element.tooltip( "close" );
ok( tooltip.is( ":hidden" ) );
$.fx.off = false;

View File

@@ -3,15 +3,21 @@
module( "tooltip: options" );
test( "items", function() {
var event = $.Event( "mouseenter" );
event.target = $( "[data-tooltip]" )[ 0 ];
expect( 2 );
var element = $( "#qunit-fixture" ).tooltip({
items: "[data-tooltip]",
content: function() {
return $( this ).attr( "data-tooltip" );
}
}).tooltip( "open", event );
same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "text" );
items: "#fixture-span"
});
var event = $.Event( "mouseenter" );
event.target = $( "#fixture-span" )[ 0 ];
element.tooltip( "open", event );
same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" );
// make sure default [title] doesn't get used
event.target = $( "#tooltipped1" )[ 0 ];
element.tooltip( "open", event );
same( $( "#tooltipped1" ).attr( "aria-describedby" ), undefined );
element.tooltip( "destroy" );
});
@@ -38,22 +44,22 @@ test( "content: return jQuery", function() {
same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" );
});
/*
TODO broken, probably related to async content
test("content: callback string", function() {
stop();
$("#tooltipped1").tooltip({
content: function(response) {
response("customstring2");
asyncTest( "content: sync + async callback", function() {
expect( 2 );
var element = $( "#tooltipped1" ).tooltip({
content: function( response ) {
setTimeout(function() {
//console.log($("#tooltipped1").attr("aria-describedby"))
same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "customstring2" );
start();
}, 100)
same( $( "#" + element.attr("aria-describedby") ).text(), "loading..." );
response( "customstring2" );
setTimeout(function() {
same( $( "#" + element.attr("aria-describedby") ).text(), "customstring2" );
start();
}, 13 );
}, 13 );
return "loading...";
}
}).tooltip("open");
}).tooltip( "open" );
});
*/
}( jQuery ) );

View File

@@ -63,12 +63,7 @@ $.widget( "ui.tooltip", {
// IE may instantly serve a cached response for ajax requests
// delay this call to _open so the other call to _open runs first
setTimeout(function() {
// when undefined, it got removeAttr, then ignore (ajax response)
// initially its an empty string, so not undefined
// TODO is there a better approach to enable ajax tooltips to have two updates?
if ( target.attr( "aria-describedby" ) !== undefined ) {
that._open( event, target, response );
}
that._open( event, target, response );
}, 1 );
});
if ( content ) {