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() {
$.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;
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" );
});
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 ) );
// 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 ) {