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: events" );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "programmatic triggers", function() {
|
2011-05-30 22:51:29 +00:00
|
|
|
expect( 4 );
|
|
|
|
var tooltip,
|
|
|
|
element = $( "#tooltipped1" ).tooltip();
|
2011-05-28 20:20:46 +00:00
|
|
|
|
2011-05-30 22:51:29 +00:00
|
|
|
element.one( "tooltipopen", function( event, ui ) {
|
|
|
|
tooltip = ui.tooltip;
|
2011-05-28 20:20:46 +00:00
|
|
|
ok( !( "originalEvent" in event ), "open" );
|
2011-05-30 22:51:29 +00:00
|
|
|
strictEqual( ui.tooltip[0],
|
|
|
|
$( "#" + element.attr( "aria-describedby" ) )[0], "ui.tooltip" );
|
2011-05-28 20:20:46 +00:00
|
|
|
});
|
|
|
|
element.tooltip( "open" );
|
|
|
|
|
2011-05-30 22:51:29 +00:00
|
|
|
element.one( "tooltipclose", function( event, ui ) {
|
2011-05-28 20:20:46 +00:00
|
|
|
ok( !( "originalEvent" in event ), "close" );
|
2011-05-30 22:51:29 +00:00
|
|
|
strictEqual( ui.tooltip[0], tooltip[0], "ui.tooltip" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
2011-05-28 20:20:46 +00:00
|
|
|
element.tooltip( "close" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "mouse events", function() {
|
2011-05-28 20:20:46 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#tooltipped1" ).tooltip();
|
|
|
|
|
|
|
|
element.one( "tooltipopen", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "mouseover" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
2011-05-28 20:20:46 +00:00
|
|
|
element.trigger( "mouseover" );
|
|
|
|
|
|
|
|
element.one( "tooltipclose", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "mouseleave" );
|
2011-05-28 20:20:46 +00:00
|
|
|
});
|
|
|
|
element.trigger( "mouseleave" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
test( "focus events", function() {
|
2011-05-28 20:20:46 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#tooltipped1" ).tooltip();
|
|
|
|
|
|
|
|
element.one( "tooltipopen", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "focusin" );
|
2011-05-28 20:20:46 +00:00
|
|
|
});
|
|
|
|
element.trigger( "focusin" );
|
|
|
|
|
|
|
|
element.one( "tooltipclose", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "focusout" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
2012-02-23 18:37:31 +00:00
|
|
|
element.trigger( "focusout" );
|
2010-04-15 07:45:35 +00:00
|
|
|
});
|
|
|
|
|
2011-10-12 14:25:55 +00:00
|
|
|
asyncTest( "mixed events", function() {
|
2011-05-29 23:21:31 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#tooltipped1" ).tooltip();
|
|
|
|
|
|
|
|
element.one( "tooltipopen", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "focusin" );
|
2011-05-29 23:21:31 +00:00
|
|
|
});
|
2011-10-31 21:28:00 +00:00
|
|
|
element.simulate( "focus" );
|
2011-05-29 23:21:31 +00:00
|
|
|
|
|
|
|
element.one( "tooltipopen", function() {
|
|
|
|
ok( false, "open triggered while already open" );
|
|
|
|
});
|
|
|
|
element.trigger( "mouseover" );
|
|
|
|
|
|
|
|
element.bind( "tooltipclose", function( event ) {
|
|
|
|
ok( false, "close triggered while still focused" );
|
|
|
|
});
|
|
|
|
element.trigger( "mouseleave" );
|
|
|
|
element.unbind( "tooltipclose" );
|
|
|
|
|
2011-10-12 14:25:55 +00:00
|
|
|
// blurring is async in IE
|
2011-05-29 23:21:31 +00:00
|
|
|
element.one( "tooltipclose", function( event ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual( event.originalEvent.type, "focusout" );
|
2011-10-12 14:25:55 +00:00
|
|
|
start();
|
2011-05-29 23:21:31 +00:00
|
|
|
});
|
2011-10-31 21:28:00 +00:00
|
|
|
element.simulate( "blur" );
|
2011-05-29 23:21:31 +00:00
|
|
|
});
|
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
}( jQuery ) );
|