2015-04-06 18:40:47 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-15 02:06:31 +00:00
|
|
|
"ui/widgets/selectmenu"
|
2015-04-06 18:40:47 +00:00
|
|
|
], function( $ ) {
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
module( "selectmenu: events", {
|
2014-04-22 16:19:12 +00:00
|
|
|
setup: function() {
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element = $( "#speed" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
asyncTest( "change", function() {
|
|
|
|
expect( 3 );
|
2013-05-30 19:11:08 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
var button, menu, options,
|
|
|
|
optionIndex = 1;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
|
|
|
change: function( event, ui ) {
|
2013-05-30 19:11:08 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
2014-04-22 16:19:12 +00:00
|
|
|
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
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button = this.element.selectmenu( "widget" );
|
2014-04-22 16:19:12 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" );
|
2013-05-30 20:30:56 +00:00
|
|
|
options = this.element.find( "option" );
|
2012-01-22 13:12:52 +00:00
|
|
|
|
2013-05-30 20:30:56 +00:00
|
|
|
button.simulate( "focus" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2013-05-30 20:30:56 +00:00
|
|
|
start();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
test( "close", function() {
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
var shouldFire;
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
close: function() {
|
|
|
|
ok( shouldFire, "close event fired on close" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-05-30 20:30:56 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
shouldFire = false;
|
2014-04-22 16:57:05 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2014-04-22 16:19:12 +00:00
|
|
|
shouldFire = true;
|
|
|
|
this.element.selectmenu( "close" );
|
|
|
|
shouldFire = false;
|
2013-05-30 19:21:44 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2014-04-22 16:19:12 +00:00
|
|
|
shouldFire = true;
|
2013-10-29 19:54:16 +00:00
|
|
|
$( "body" ).trigger( "mousedown" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
asyncTest( "focus", function() {
|
|
|
|
expect( 9 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
var button, menu, links,
|
|
|
|
that = this,
|
2013-05-30 19:02:38 +00:00
|
|
|
optionIndex = this.element[ 0 ].selectedIndex + 1,
|
2014-04-22 16:19:12 +00:00
|
|
|
options = this.element.find( "option" );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
focus: function( event, ui ) {
|
|
|
|
ok( true, "focus event fired on element #" + optionIndex + " mouseover" );
|
2013-05-30 19:02:38 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
2014-04-22 16:19:12 +00:00
|
|
|
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
|
|
|
"ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +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" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-05-30 20:30:56 +00:00
|
|
|
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-10-09 23:01:41 +00:00
|
|
|
links = menu.find( "li.ui-menu-item" );
|
2013-05-30 20:30:56 +00:00
|
|
|
optionIndex = 0;
|
|
|
|
links.eq( optionIndex ).simulate( "mouseover" );
|
|
|
|
optionIndex += 1;
|
|
|
|
links.eq( optionIndex ).simulate( "mouseover" );
|
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
// This tests for unwanted, additional focus event on close
|
2013-05-30 20:30:56 +00:00
|
|
|
that.element.selectmenu( "close" );
|
|
|
|
start();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
test( "open", function() {
|
|
|
|
expect( 1 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
open: function() {
|
|
|
|
ok( true, "open event fired on open" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
this.element.selectmenu( "open" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-04-22 16:19:12 +00:00
|
|
|
asyncTest( "select", function() {
|
|
|
|
expect( 3 );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
this.element.selectmenu( {
|
2014-04-22 16:19:12 +00:00
|
|
|
select: function( event, ui ) {
|
|
|
|
ok( true, "select event fired on item select" );
|
2013-05-30 19:11:08 +00:00
|
|
|
equal( ui.item.index, optionIndex, "ui.item.index contains correct option index" );
|
2014-04-22 16:19:12 +00:00
|
|
|
equal( ui.item.element[ 0 ], options.eq( optionIndex )[ 0 ],
|
|
|
|
"ui.item.element contains original option element" );
|
2012-01-13 18:49:42 +00:00
|
|
|
}
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2013-03-07 18:15:46 +00:00
|
|
|
var button = this.element.selectmenu( "widget" ),
|
2014-04-22 16:19:12 +00:00
|
|
|
menu = this.element.selectmenu( "menuWidget" ),
|
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" );
|
2015-08-24 12:50:24 +00:00
|
|
|
setTimeout( function() {
|
2013-07-01 20:04:30 +00:00
|
|
|
button.trigger( "click" );
|
2013-10-09 23:01:41 +00:00
|
|
|
menu.find( "li" ).eq( optionIndex ).simulate( "mouseover" ).trigger( "click" );
|
2013-05-30 20:30:56 +00:00
|
|
|
start();
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-11-24 15:50:20 +00:00
|
|
|
|
2015-04-06 18:40:47 +00:00
|
|
|
} );
|