2013-04-29 18:47:02 +00:00
|
|
|
(function ( $ ) {
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
module( "selectmenu: events", {
|
2012-01-13 18:49:42 +00:00
|
|
|
setup: function () {
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element = $( "#speed" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
asyncTest( "change", function () {
|
2013-05-30 19:11:08 +00:00
|
|
|
expect( 5 );
|
|
|
|
|
2013-06-04 19:16:13 +00:00
|
|
|
var optionIndex = 1,
|
2013-05-30 20:30:56 +00:00
|
|
|
button, menu, options;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
|
|
|
this.element.selectmenu({
|
2013-02-13 22:58:14 +00:00
|
|
|
change: function ( event, ui ) {
|
|
|
|
ok( event, "change event fired on change" );
|
|
|
|
equal( event.type, "selectmenuchange", "event type set to selectmenuchange" );
|
2013-05-30 19:11:08 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
|
|
|
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
|
|
|
|
equal( ui.item.value, options.eq( optionIndex ).text(), "ui.item.value property updated correctly" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button = this.element.selectmenu( "widget" );
|
|
|
|
menu = this.element.selectmenu( "menuWidget" ).parent();
|
|
|
|
options = this.element.find( "option" );
|
2012-01-22 13:12:52 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
|
|
|
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2013-05-30 20:30:56 +00:00
|
|
|
start();
|
|
|
|
}, 1 );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
test( "close", function () {
|
2013-05-30 19:21:44 +00:00
|
|
|
expect( 4 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
|
|
|
this.element.selectmenu({
|
2013-06-04 19:16:13 +00:00
|
|
|
close: function ( event ) {
|
2013-02-13 22:58:14 +00:00
|
|
|
ok( event, "close event fired on close" );
|
|
|
|
equal( event.type, "selectmenuclose", "event type set to selectmenuclose" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-30 20:30:56 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element.selectmenu( "open" ).selectmenu( "close" );
|
2013-05-30 20:30:56 +00:00
|
|
|
|
2013-05-30 19:21:44 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2013-07-01 20:04:30 +00:00
|
|
|
$( "body" ).trigger( "click" );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
asyncTest( "focus", function () {
|
2013-05-30 19:02:38 +00:00
|
|
|
expect( 12 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
var that = this,
|
2013-05-30 19:02:38 +00:00
|
|
|
optionIndex = this.element[ 0 ].selectedIndex + 1,
|
2013-05-30 20:30:56 +00:00
|
|
|
options = this.element.find( "option" ),
|
|
|
|
button, menu, links;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
|
|
|
this.element.selectmenu({
|
2013-02-13 22:58:14 +00:00
|
|
|
focus: function ( event, ui ) {
|
2013-05-30 19:02:38 +00:00
|
|
|
ok( event, "focus event fired on element #" + optionIndex + " mouseover" );
|
2013-02-13 22:58:14 +00:00
|
|
|
equal( event.type, "selectmenufocus", "event type set to selectmenufocus" );
|
2013-05-30 19:02:38 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
|
|
|
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2013-06-04 19:16:13 +00:00
|
|
|
button = this.element.selectmenu( "widget" );
|
2013-02-13 22:58:14 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" );
|
2012-12-12 17:37:57 +00:00
|
|
|
|
2013-06-04 19:16:13 +00:00
|
|
|
button.simulate( "focus" );
|
2013-05-30 19:11:08 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-05-30 20:30:56 +00:00
|
|
|
links = menu.find( "li.ui-menu-item a" );
|
|
|
|
optionIndex = 0;
|
|
|
|
links.eq( optionIndex ).simulate( "mouseover" );
|
|
|
|
optionIndex += 1;
|
|
|
|
links.eq( optionIndex ).simulate( "mouseover" );
|
|
|
|
|
|
|
|
// this tests for unwanted, additional focus event on close
|
|
|
|
that.element.selectmenu( "close" );
|
|
|
|
start();
|
|
|
|
}, 1 );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
test( "open", function () {
|
2013-04-29 18:51:01 +00:00
|
|
|
expect( 2 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
|
|
|
this.element.selectmenu({
|
2013-06-04 19:16:13 +00:00
|
|
|
open: function ( event ) {
|
2013-02-13 22:58:14 +00:00
|
|
|
ok( event, "open event fired on open" );
|
|
|
|
equal( event.type, "selectmenuopen", "event type set to selectmenuopen" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
asyncTest( "select", function () {
|
2013-05-30 19:11:08 +00:00
|
|
|
expect( 4 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
|
|
|
this.element.selectmenu({
|
2013-02-13 22:58:14 +00:00
|
|
|
select: function ( event, ui ) {
|
|
|
|
ok( event, "select event fired on item select" );
|
|
|
|
equal( event.type, "selectmenuselect", "event type set to selectmenuselect" );
|
2013-05-30 19:11:08 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
|
|
|
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ], "ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-07 18:15:46 +00:00
|
|
|
var button = this.element.selectmenu( "widget" ),
|
2013-05-12 19:02:03 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" ).parent(),
|
2013-05-30 19:11:08 +00:00
|
|
|
options = this.element.find( "option" ),
|
|
|
|
optionIndex = 1;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
|
|
|
menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2013-05-30 20:30:56 +00:00
|
|
|
start();
|
|
|
|
}, 1 );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
2011-11-24 15:50:20 +00:00
|
|
|
|
|
|
|
})(jQuery);
|