mirror of
https://github.com/jquery/jquery-ui.git
synced 2026-04-20 03:02:41 -04:00
Tooltip: Allow content updates via async response regardless of whether a sync response came back. Added more tests.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
7
ui/jquery.ui.tooltip.js
vendored
7
ui/jquery.ui.tooltip.js
vendored
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user