2013-04-29 19:03:12 +00:00
|
|
|
(function ( $ ) {
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
module( "selectmenu: options" );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
test( "appendTo: null", function() {
|
|
|
|
expect( 1 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
var element = $( "#speed" ).selectmenu();
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], document.body,
|
2014-02-21 12:40:32 +00:00
|
|
|
"defaults to body" );
|
|
|
|
});
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
test( "appendTo: explicit", function() {
|
|
|
|
expect( 6 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2012-12-15 01:24:10 +00:00
|
|
|
var detached = $( "<div>" ),
|
2014-02-21 12:40:32 +00:00
|
|
|
element = $( "#speed" );
|
2012-12-15 01:24:10 +00:00
|
|
|
|
|
|
|
element.selectmenu({
|
2013-04-29 18:34:16 +00:00
|
|
|
appendTo: ".selectmenu-wrap"
|
2012-12-15 01:24:10 +00:00
|
|
|
});
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
|
|
|
$( "#selectmenu-wrap1" )[ 0 ], "first found element" );
|
2013-04-29 18:34:16 +00:00
|
|
|
equal( $( "#selectmenu-wrap2 .ui-selectmenu" ).length, 0, "only appends to one element" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
2013-04-29 18:34:16 +00:00
|
|
|
element.selectmenu().selectmenu( "option", "appendTo", "#selectmenu-wrap1" );
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
|
|
|
$( "#selectmenu-wrap1" )[ 0 ], "modified after init" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
|
|
|
element.selectmenu({
|
|
|
|
appendTo: detached
|
|
|
|
});
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
|
|
|
"detached jQuery object" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2012-05-16 18:43:42 +00:00
|
|
|
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu({
|
2013-04-29 19:03:12 +00:00
|
|
|
appendTo: detached[ 0 ]
|
2012-12-15 01:24:10 +00:00
|
|
|
});
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
|
|
|
"detached DOM element" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2012-05-16 18:43:42 +00:00
|
|
|
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu().selectmenu( "option", "appendTo", detached );
|
2014-04-22 22:24:04 +00:00
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
|
|
|
"detached DOM element via option()" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2012-01-13 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
test( "appendTo: ui-front", function() {
|
|
|
|
expect( 2 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
var element = $( "#speed" );
|
|
|
|
|
|
|
|
$( "#selectmenu-wrap2" ).addClass( "ui-front" );
|
|
|
|
element.selectmenu();
|
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
|
|
|
$( "#selectmenu-wrap2" )[ 0 ], "null, inside .ui-front" );
|
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
|
|
|
element.selectmenu({
|
|
|
|
appendTo: $()
|
|
|
|
});
|
|
|
|
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
|
|
|
$( "#selectmenu-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
|
|
|
});
|
|
|
|
|
2012-01-13 19:46:47 +00:00
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
test( "CSS styles", function() {
|
2013-02-13 22:58:14 +00:00
|
|
|
expect( 2 );
|
2012-02-26 00:24:52 +00:00
|
|
|
|
2013-04-29 19:03:12 +00:00
|
|
|
var element = $( "#speed" ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
element.selectmenu( "open" );
|
2014-04-22 22:24:04 +00:00
|
|
|
ok(
|
|
|
|
button.hasClass( "ui-corner-top" ) && !button.hasClass( "ui-corner-all" ) &&
|
|
|
|
button.find( "span.ui-icon" ).hasClass( "ui-icon-triangle-1-s" ),
|
|
|
|
"button styles dropdown"
|
|
|
|
);
|
|
|
|
ok( menu.hasClass( "ui-corner-bottom" ) && !menu.hasClass( "ui-corner-all" ),
|
|
|
|
"menu styles dropdown" );
|
2012-02-26 00:24:52 +00:00
|
|
|
});
|
|
|
|
|
2013-12-05 21:12:05 +00:00
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
test( "Width", function() {
|
2013-12-05 21:12:05 +00:00
|
|
|
expect( 8 );
|
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
var button, menu,
|
|
|
|
element = $( "#speed" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
element.selectmenu();
|
|
|
|
button = element.selectmenu( "widget" );
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
|
|
|
|
|
|
|
equal( button.outerWidth(), element.outerWidth(), "button width auto" );
|
|
|
|
element.selectmenu( "open" );
|
2014-06-23 01:00:03 +00:00
|
|
|
closeEnough( menu.outerWidth(), element.outerWidth(), 2, "menu width auto" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
element.outerWidth( 100 );
|
|
|
|
element.selectmenu( "refresh" );
|
|
|
|
|
|
|
|
equal( button.outerWidth(), 100, "button width set by CSS" );
|
|
|
|
element.selectmenu( "open" );
|
|
|
|
equal( menu.outerWidth(), 100, "menu width set by CSS" );
|
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
element
|
|
|
|
.width( "" )
|
|
|
|
.selectmenu( "option", "width", 100 )
|
|
|
|
.selectmenu( "refresh" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
equal( button.outerWidth(), 100, "button width set by JS option" );
|
|
|
|
element.selectmenu( "open" );
|
|
|
|
equal( menu.outerWidth(), 100, "menu width set by JS option" );
|
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
element
|
|
|
|
.append( $( "<option>", { text: "Option with a little longer text" } ) )
|
|
|
|
.selectmenu( "option", "width", "" )
|
|
|
|
.selectmenu( "refresh" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
equal( button.outerWidth(), element.outerWidth(), "button width with long option" );
|
|
|
|
element.selectmenu( "open" );
|
|
|
|
ok( menu.outerWidth() >= element.outerWidth(), "menu width with long option" );
|
|
|
|
});
|
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
})( jQuery );
|