]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip: Allow content updates via async response regardless of whether a sync respon...
authorScott González <scott.gonzalez@gmail.com>
Sat, 28 May 2011 21:36:57 +0000 (17:36 -0400)
committerScott González <scott.gonzalez@gmail.com>
Sat, 28 May 2011 21:36:57 +0000 (17:36 -0400)
tests/unit/tooltip/tooltip.html
tests/unit/tooltip/tooltip_methods.js
tests/unit/tooltip/tooltip_options.js
ui/jquery.ui.tooltip.js

index d540504abc467a1fb0a93e65e0cbc8a1ad9bc644..21eff51fd4eb5e96451b8bde00046aed00179724 100644 (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>
index 1487672cbd8547d7c7221075e138dbf144bd4464..b1b319d9661ac367464e9e0d36f0be3f5d869cac 100644 (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;
index c866d219f17d817aff9052c08a7965a5dcb2938d..bbbab72ff926eeb4c33ebc8093811abceaaa3612 100644 (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 ) );
index e6f1c7bb65c684bd1afb66deb4b484cdfb35dd65..343c1d055a065d691e9234f7f6a932c3b2612986 100644 (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 ) {