2011-05-28 17:30:00 +00:00
|
|
|
(function( $ ) {
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
module( "tooltip: core" );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2011-05-28 19:43:22 +00:00
|
|
|
test( "markup structure", function() {
|
2012-05-22 15:06:44 +00:00
|
|
|
expect( 7 );
|
2011-05-28 19:43:22 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip(),
|
|
|
|
tooltip = $( ".ui-tooltip" );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2011-05-28 19:43:22 +00:00
|
|
|
equal( element.attr( "aria-describedby" ), undefined, "no aria-describedby on init" );
|
|
|
|
equal( tooltip.length, 0, "no tooltip on init" );
|
|
|
|
|
|
|
|
element.tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
|
2011-05-28 19:43:22 +00:00
|
|
|
equal( tooltip.length, 1, "tooltip exists" );
|
2012-05-22 15:06:44 +00:00
|
|
|
equal( element.attr( "aria-describedby"), tooltip.attr( "id" ), "aria-describedby" );
|
2011-05-28 19:43:22 +00:00
|
|
|
ok( tooltip.hasClass( "ui-tooltip" ), "tooltip is .ui-tooltip" );
|
|
|
|
equal( tooltip.length, 1, ".ui-tooltip exists" );
|
|
|
|
equal( tooltip.find( ".ui-tooltip-content" ).length, 1,
|
|
|
|
".ui-tooltip-content exists" );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "accessibility", function() {
|
2013-10-26 15:31:07 +00:00
|
|
|
expect( 15 );
|
2012-05-22 15:06:44 +00:00
|
|
|
|
2013-10-26 15:31:07 +00:00
|
|
|
var tooltipId, tooltip,
|
|
|
|
element = $( "#multiple-describedby" ).tooltip(),
|
|
|
|
liveRegion = element.tooltip( "instance" ).liveRegion;
|
2012-05-22 15:06:44 +00:00
|
|
|
|
2013-10-26 15:31:07 +00:00
|
|
|
equal( liveRegion.find( ">div" ).length, 0 );
|
|
|
|
equal( liveRegion.attr( "role" ), "log" );
|
|
|
|
equal( liveRegion.attr( "aria-live" ), "assertive" );
|
|
|
|
equal( liveRegion.attr( "aria-relevant" ), "additions" );
|
2012-05-22 15:06:44 +00:00
|
|
|
element.tooltip( "open" );
|
|
|
|
tooltipId = element.data( "ui-tooltip-id" );
|
2012-05-22 16:54:09 +00:00
|
|
|
tooltip = $( "#" + tooltipId );
|
|
|
|
equal( tooltip.attr( "role" ), "tooltip", "role" );
|
2012-05-22 15:06:44 +00:00
|
|
|
equal( element.attr( "aria-describedby" ), "fixture-span " + tooltipId,
|
|
|
|
"multiple describedby when open" );
|
2013-10-26 15:31:07 +00:00
|
|
|
|
2012-05-22 16:54:09 +00:00
|
|
|
// strictEqual to distinguish between .removeAttr( "title" ) and .attr( "title", "" )
|
2012-06-25 18:51:51 +00:00
|
|
|
// support: jQuery <1.6.2
|
|
|
|
// support: IE <8
|
|
|
|
// We should use strictEqual( ..., undefined ) when dropping jQuery 1.6.1 support (or IE6/7)
|
2012-06-19 15:12:38 +00:00
|
|
|
ok( !element.attr( "title" ), "no title when open" );
|
2013-10-26 15:31:07 +00:00
|
|
|
equal( liveRegion.children().length, 1 );
|
|
|
|
equal( liveRegion.children().last().html(), "..." );
|
2012-05-22 15:06:44 +00:00
|
|
|
element.tooltip( "close" );
|
|
|
|
equal( element.attr( "aria-describedby" ), "fixture-span",
|
|
|
|
"correct describedby when closed" );
|
2012-05-22 16:54:09 +00:00
|
|
|
equal( element.attr( "title" ), "...", "title restored when closed" );
|
2013-10-26 15:31:07 +00:00
|
|
|
|
|
|
|
element.tooltip( "open" );
|
|
|
|
equal( liveRegion.children().length, 2,
|
|
|
|
"After the second tooltip show, there should be two children" );
|
|
|
|
equal( liveRegion.children().filter( ":visible" ).length, 1,
|
|
|
|
"Only one of the children should be visible" );
|
|
|
|
ok( liveRegion.children().last().is( ":visible" ),
|
|
|
|
"Only the last child should be visible" );
|
|
|
|
element.tooltip( "close" );
|
|
|
|
|
|
|
|
element.tooltip( "destroy" );
|
|
|
|
equal( liveRegion.parent().length, 0,
|
|
|
|
"Tooltip liveregion element should be removed" );
|
2011-05-28 19:43:22 +00:00
|
|
|
});
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2012-10-15 20:15:36 +00:00
|
|
|
test( "delegated removal", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var container = $( "#contains-tooltipped" ).tooltip(),
|
|
|
|
element = $( "#contained-tooltipped" );
|
|
|
|
|
|
|
|
element.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 1 );
|
|
|
|
|
|
|
|
container.empty();
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0 );
|
|
|
|
});
|
|
|
|
|
2012-10-21 17:25:36 +00:00
|
|
|
test( "nested tooltips", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var child = $( "#contained-tooltipped" ),
|
|
|
|
parent = $( "#contains-tooltipped" ).tooltip({
|
|
|
|
show: null,
|
|
|
|
hide: null
|
|
|
|
});
|
|
|
|
|
|
|
|
parent.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip:visible" ).text(), "parent" );
|
|
|
|
|
|
|
|
child.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip" ).text(), "child" );
|
|
|
|
});
|
|
|
|
|
2012-10-29 00:28:55 +00:00
|
|
|
// #8742
|
|
|
|
test( "form containing an input with name title", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
var form = $( "#tooltip-form" ).tooltip({
|
|
|
|
show: null,
|
|
|
|
hide: null
|
|
|
|
}),
|
|
|
|
input = form.find( "[name=title]" );
|
|
|
|
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0, "no tooltips on init" );
|
|
|
|
|
|
|
|
input.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 1, "tooltip for input" );
|
|
|
|
input.trigger( "mouseleave" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0, "tooltip for input closed" );
|
|
|
|
|
|
|
|
form.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0, "no tooltip for form" );
|
|
|
|
});
|
|
|
|
|
2012-11-09 18:07:53 +00:00
|
|
|
test( "tooltip on .ui-state-disabled element", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var container = $( "#contains-tooltipped" ).tooltip(),
|
|
|
|
element = $( "#contained-tooltipped" ).addClass( "ui-state-disabled" );
|
|
|
|
|
|
|
|
element.trigger( "mouseover" );
|
|
|
|
equal( $( ".ui-tooltip" ).length, 1 );
|
|
|
|
|
|
|
|
container.empty();
|
|
|
|
equal( $( ".ui-tooltip" ).length, 0 );
|
|
|
|
});
|
|
|
|
|
2012-11-14 19:14:25 +00:00
|
|
|
// http://bugs.jqueryui.com/ticket/8740
|
|
|
|
asyncTest( "programmatic focus with async content", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
|
|
|
content: function( response ) {
|
|
|
|
setTimeout(function() {
|
|
|
|
response( "test" );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.bind( "tooltipopen", function( event ) {
|
|
|
|
deepEqual( event.originalEvent.type, "focusin" );
|
|
|
|
|
|
|
|
element.bind( "tooltipclose", function( event ) {
|
|
|
|
deepEqual( event.originalEvent.type, "focusout" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
element.blur();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
element.focus();
|
|
|
|
});
|
|
|
|
|
2014-08-05 18:19:06 +00:00
|
|
|
asyncTest( "destroy during hide animation; only one close event", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var element = $( "#tooltipped1" ).tooltip({
|
|
|
|
show: false,
|
|
|
|
hide: true
|
|
|
|
});
|
|
|
|
|
|
|
|
element.bind( "tooltipclose", function() {
|
|
|
|
ok( true, "tooltip closed" );
|
|
|
|
});
|
|
|
|
|
|
|
|
element.tooltip( "open" );
|
|
|
|
element.tooltip( "close" );
|
|
|
|
setTimeout(function() {
|
|
|
|
element.tooltip( "destroy" );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-30 13:44:34 +00:00
|
|
|
// http://bugs.jqueryui.com/ticket/10602
|
|
|
|
asyncTest( "multiple active delegated tooltips", function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var anchor = $( "#tooltipped1" ),
|
|
|
|
input = anchor.next(),
|
|
|
|
actions = [];
|
|
|
|
|
|
|
|
$( document ).tooltip({
|
|
|
|
show: false,
|
|
|
|
hide: false,
|
|
|
|
open: function( event, ui ) {
|
|
|
|
actions.push( "open:" + ui.tooltip.text() );
|
|
|
|
},
|
|
|
|
close: function( event, ui ) {
|
|
|
|
actions.push( "close:" + ui.tooltip.text() );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function step1() {
|
|
|
|
anchor.simulate( "mouseover" );
|
|
|
|
setTimeout( step2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
|
|
|
input.simulate( "focus" );
|
|
|
|
setTimeout( step3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step3() {
|
|
|
|
input.simulate( "blur" );
|
|
|
|
setTimeout( step4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step4() {
|
|
|
|
anchor.simulate( "mouseout" );
|
|
|
|
deepEqual( actions, [
|
|
|
|
"open:anchortitle",
|
|
|
|
"open:inputtitle",
|
|
|
|
"close:inputtitle",
|
|
|
|
"close:anchortitle"
|
|
|
|
], "Both tooltips open and close" );
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
step1();
|
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
}( jQuery ) );
|