2011-05-28 17:30:00 +00:00
|
|
|
(function( $ ) {
|
2010-10-26 12:26:53 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
module( "tooltip: options" );
|
2010-10-26 15:07:22 +00:00
|
|
|
|
2012-10-24 14:00:39 +00:00
|
|
|
test( "disabled: true", function() {
|
|
|
|
expect( 1 );
|
|
|
|
$( "#tooltipped1" ).tooltip({
|
|
|
|
disabled: true
|
|
|
|
}).tooltip( "open" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0 );
|
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "content: default", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2011-05-28 19:43:22 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip().tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
|
2010-10-26 12:26:53 +00:00
|
|
|
});
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "content: return string", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2011-05-28 17:30:00 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
2010-10-26 12:26:53 +00:00
|
|
|
content: function() {
|
|
|
|
return "customstring";
|
|
|
|
}
|
2011-05-28 17:30:00 +00:00
|
|
|
}).tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
2010-10-26 12:26:53 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "content: return jQuery", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2011-05-28 17:30:00 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
2010-10-26 13:36:43 +00:00
|
|
|
content: function() {
|
2011-05-28 17:30:00 +00:00
|
|
|
return $( "<div>" ).html( "cu<b>s</b>tomstring" );
|
2010-10-26 13:36:43 +00:00
|
|
|
}
|
2011-05-28 17:30:00 +00:00
|
|
|
}).tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" );
|
2010-10-26 13:36:43 +00:00
|
|
|
});
|
|
|
|
|
2011-05-28 21:36:57 +00:00
|
|
|
asyncTest( "content: sync + async callback", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
|
|
|
content: function( response ) {
|
2010-10-26 12:26:53 +00:00
|
|
|
setTimeout(function() {
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "loading..." );
|
2011-05-28 21:36:57 +00:00
|
|
|
|
|
|
|
response( "customstring2" );
|
|
|
|
setTimeout(function() {
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "customstring2" );
|
2011-05-28 21:36:57 +00:00
|
|
|
start();
|
|
|
|
}, 13 );
|
|
|
|
}, 13 );
|
|
|
|
return "loading...";
|
2010-10-26 12:26:53 +00:00
|
|
|
}
|
2011-05-28 21:36:57 +00:00
|
|
|
}).tooltip( "open" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
|
|
|
|
2012-08-31 19:38:21 +00:00
|
|
|
test( "content: change while open", function() {
|
|
|
|
expect( 2 ) ;
|
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
|
|
|
content: function() {
|
|
|
|
return "old";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.one( "tooltipopen", function( event, ui ) {
|
|
|
|
equal( ui.tooltip.text(), "old", "original content" );
|
|
|
|
element.tooltip( "option", "content", function() {
|
|
|
|
return "new";
|
|
|
|
});
|
|
|
|
equal( ui.tooltip.text(), "new", "updated content" );
|
|
|
|
});
|
|
|
|
|
|
|
|
element.tooltip( "open" );
|
|
|
|
});
|
|
|
|
|
2012-08-31 19:41:45 +00:00
|
|
|
test( "content: string", function() {
|
|
|
|
expect( 1 );
|
2012-10-23 14:36:42 +00:00
|
|
|
$( "#tooltipped1" ).tooltip({
|
2012-08-31 19:41:45 +00:00
|
|
|
content: "just a string",
|
|
|
|
open: function( event, ui ) {
|
|
|
|
equal( ui.tooltip.text(), "just a string" );
|
|
|
|
}
|
|
|
|
}).tooltip( "open" );
|
|
|
|
});
|
|
|
|
|
2011-05-28 21:55:45 +00:00
|
|
|
test( "items", function() {
|
|
|
|
expect( 2 );
|
2012-04-19 02:36:15 +00:00
|
|
|
var event,
|
|
|
|
element = $( "#qunit-fixture" ).tooltip({
|
|
|
|
items: "#fixture-span"
|
|
|
|
});
|
2011-05-28 21:55:45 +00:00
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
event = $.Event( "mouseenter" );
|
2011-05-28 21:55:45 +00:00
|
|
|
event.target = $( "#fixture-span" )[ 0 ];
|
|
|
|
element.tooltip( "open", event );
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#" + $( "#fixture-span" ).data( "ui-tooltip-id" ) ).text(), "title-text" );
|
2011-05-28 21:55:45 +00:00
|
|
|
|
|
|
|
// make sure default [title] doesn't get used
|
|
|
|
event.target = $( "#tooltipped1" )[ 0 ];
|
|
|
|
element.tooltip( "open", event );
|
2012-05-22 15:06:44 +00:00
|
|
|
deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined );
|
2011-05-28 21:55:45 +00:00
|
|
|
|
|
|
|
element.tooltip( "destroy" );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "tooltipClass", function() {
|
2012-04-19 02:36:15 +00:00
|
|
|
expect( 1 );
|
2011-05-28 21:55:45 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
|
|
|
tooltipClass: "custom"
|
|
|
|
}).tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) );
|
2011-05-28 21:55:45 +00:00
|
|
|
});
|
|
|
|
|
2012-10-16 16:55:50 +00:00
|
|
|
test( "track + show delay", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var event,
|
|
|
|
leftVal = 314,
|
|
|
|
topVal = 159,
|
|
|
|
offsetVal = 26,
|
|
|
|
element = $( "#tooltipped1" ).tooltip({
|
|
|
|
track: true,
|
|
|
|
show: {
|
|
|
|
delay: 1
|
|
|
|
},
|
|
|
|
position: {
|
|
|
|
my: "left+" + offsetVal + " top+" + offsetVal,
|
|
|
|
at: "right bottom"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event = $.Event( "mouseover" );
|
|
|
|
event.target = $( "#tooltipped1" )[ 0 ];
|
|
|
|
event.originalEvent = { type: "mouseover" };
|
|
|
|
event.pageX = leftVal;
|
|
|
|
event.pageY = topVal;
|
|
|
|
element.trigger( event );
|
|
|
|
|
|
|
|
event = $.Event( "mousemove" );
|
|
|
|
event.target = $( "#tooltipped1" )[ 0 ];
|
|
|
|
event.originalEvent = { type: "mousemove" };
|
|
|
|
event.pageX = leftVal;
|
|
|
|
event.pageY = topVal;
|
|
|
|
element.trigger( event );
|
|
|
|
|
|
|
|
equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" );
|
|
|
|
equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" );
|
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
}( jQuery ) );
|