2015-04-06 14:13:15 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-15 01:57:20 +00:00
|
|
|
"ui/widgets/button"
|
2015-04-06 14:13:15 +00:00
|
|
|
], function( $ ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
module( "button: options" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
test( "disabled, explicit value", function( assert ) {
|
2014-01-22 17:02:32 +00:00
|
|
|
expect( 8 );
|
2013-03-12 01:28:51 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
var element = $( "#button" ).button( { disabled: false } );
|
|
|
|
|
|
|
|
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
|
|
|
strictEqual( element.prop( "disabled" ), false, "Disabled property is false" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-02-03 00:25:52 +00:00
|
|
|
assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
element = $( "#button" ).button( { disabled: true } );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
assert.hasClasses( element.button( "widget" ), "ui-state-disabled" );
|
|
|
|
strictEqual( element.button( "widget" ).attr( "aria-disabled" ), undefined,
|
|
|
|
"element does not get aria-disabled" );
|
|
|
|
assert.hasClasses( element.button( "widget" ), "ui-button-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
strictEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
|
|
|
|
strictEqual( element.prop( "disabled" ), true, "Disabled property is set" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-08-18 18:51:30 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
// We are testing the default here because the default null is a special value which means to check
|
|
|
|
// the DOM. We need to make sure this happens correctly. Checking the options should never return
|
|
|
|
// null, it should always be true or false.
|
2015-08-21 04:12:35 +00:00
|
|
|
test( "disabled, null", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 4 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var element = $( "#button" ),
|
|
|
|
elementDisabled = $( "#button-disabled" );
|
2015-08-21 04:12:35 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
element.add( elementDisabled ).button( { disabled: null } );
|
|
|
|
strictEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
|
|
|
strictEqual( element.prop( "disabled" ), false, "element is disabled" );
|
|
|
|
strictEqual( elementDisabled.button( "option", "disabled" ), true,
|
2015-08-21 04:12:35 +00:00
|
|
|
"disabled option set to true" );
|
2014-01-22 17:02:32 +00:00
|
|
|
strictEqual( elementDisabled.prop( "disabled" ), true, "element is disabled" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-08-18 18:51:30 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "showLabel, false, without icon", function( assert ) {
|
|
|
|
expect( 4 );
|
2013-12-12 04:53:48 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#button" ).button( {
|
|
|
|
showLabel: false
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
assert.lacksClasses( button, "ui-button-icon-only" );
|
|
|
|
strictEqual( button.button( "option", "showLabel" ), true,
|
|
|
|
"showLabel false only allowed if icon true" );
|
|
|
|
|
|
|
|
button.button( "option", "showLabel", false );
|
|
|
|
assert.lacksClasses( button, "ui-button-icon-only" );
|
|
|
|
strictEqual( button.button( "option", "showLabel" ), true,
|
|
|
|
"showLabel false only allowed if icon true" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "showLabel, false, with icon", function( assert ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#button" ).button( {
|
|
|
|
showLabel: false,
|
|
|
|
icon: "iconclass"
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2014-01-22 17:02:32 +00:00
|
|
|
assert.hasClasses( button, "ui-button ui-corner-all ui-widget ui-button-icon-only" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-08-21 04:12:35 +00:00
|
|
|
test( "label, default", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#button" ).button();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
deepEqual( button.text(), "Label" );
|
|
|
|
deepEqual( button.button( "option", "label" ), "Label" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "label, explicit value", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#button" ).button( {
|
2010-01-20 14:00:14 +00:00
|
|
|
label: "xxx"
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
deepEqual( button.text(), "xxx" );
|
|
|
|
deepEqual( button.button( "option", "label" ), "xxx" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "label, default, with input type submit", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#submit" ).button();
|
|
|
|
|
|
|
|
deepEqual( button.val(), "Label" );
|
|
|
|
deepEqual( button.button( "option", "label" ), "Label" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "label, explicit value, with input type submit", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 2 );
|
2014-01-22 17:02:32 +00:00
|
|
|
var button = $( "#submit" ).button( {
|
2010-01-20 14:00:14 +00:00
|
|
|
label: "xxx"
|
2014-01-22 17:02:32 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
deepEqual( button.val(), "xxx" );
|
|
|
|
deepEqual( button.button( "option", "label" ), "xxx" );
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "icon", function( assert ) {
|
|
|
|
expect( 4 );
|
|
|
|
var button = $( "#button" ).button( {
|
|
|
|
showLabel: false,
|
|
|
|
icon: "iconclass"
|
|
|
|
} ),
|
|
|
|
icon = button.find( ".ui-icon" );
|
|
|
|
|
|
|
|
assert.hasClasses( icon, "iconclass" );
|
|
|
|
equal( icon.length, 1, "button with icon option set has icon" );
|
|
|
|
|
|
|
|
button.button( "option", "icon", false );
|
|
|
|
equal( button.find( ".ui-icon" ).length, 0, "setting icon to false removes the icon" );
|
|
|
|
|
|
|
|
button.button( "option", "icon", "iconclass" );
|
|
|
|
ok( button.find( ".ui-icon" ).length, "setting icon to a value adds the icon" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2014-01-22 17:02:32 +00:00
|
|
|
test( "icon position", function( assert ) {
|
|
|
|
expect( 22 );
|
|
|
|
|
|
|
|
var button = $( "#button" ).button( {
|
|
|
|
icon: "ui-icon-gear"
|
|
|
|
} ),
|
|
|
|
icon = button.find( ".ui-icon" ),
|
|
|
|
space = button.find( ".ui-button-icon-space" );
|
|
|
|
|
|
|
|
equal( icon.length, 1, "button with icon option set has icon" );
|
|
|
|
equal( button.button( "option", "iconPosition" ), "beginning",
|
|
|
|
"Button has iconPosition beginning by default" );
|
|
|
|
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is begining" );
|
|
|
|
equal( icon.next()[ 0 ], space[ 0 ], "icon is followed by a space when position is begining" );
|
|
|
|
equal( space.text(), " ",
|
|
|
|
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
|
|
|
|
assert.lacksClasses( icon, "ui-widget-icon-block" );
|
|
|
|
|
|
|
|
button.button( "option", "iconPosition", "end" );
|
|
|
|
icon = button.find( ".ui-icon" );
|
|
|
|
space = button.find( ".ui-button-icon-space" );
|
|
|
|
equal( icon.length, 1, "Changing position to end does not re-create or duplicate icon" );
|
|
|
|
equal( button.button( "option", "iconPosition" ), "end", "Button has iconPosition end" );
|
|
|
|
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is appended when position is end" );
|
|
|
|
equal( icon.prev()[ 0 ], space[ 0 ], "icon is preceeded by a space when position is end" );
|
|
|
|
equal( space.text(), " ",
|
|
|
|
"ui-button-icon-space contains a breaking space iconPosition:beginning" );
|
|
|
|
assert.lacksClasses( icon, "ui-widget-icon-block" );
|
|
|
|
|
|
|
|
button.button( "option", "iconPosition", "top" );
|
|
|
|
icon = button.find( ".ui-icon" );
|
|
|
|
equal( icon.length, 1, "Changing position to top does not re-create or duplicate icon" );
|
|
|
|
equal( button.button( "option", "iconPosition" ), "top", "Button has iconPosition top" );
|
|
|
|
equal( button.contents()[ 0 ], icon[ 0 ], "icon is prepended when position is top" );
|
|
|
|
ok( !button.find( "ui-button-icon-space" ).length,
|
|
|
|
"Button should not have an iconSpace with position: top" );
|
|
|
|
assert.hasClasses( icon, "ui-widget-icon-block" );
|
|
|
|
|
|
|
|
button.button( "option", "iconPosition", "bottom" );
|
|
|
|
icon = button.find( ".ui-icon" );
|
|
|
|
equal( icon.length, 1, "Changing position to bottom does not re-create or duplicate icon" );
|
|
|
|
equal( button.button( "option", "iconPosition" ), "bottom", "Button has iconPosition top" );
|
|
|
|
equal( button.contents().last()[ 0 ], icon[ 0 ], "icon is prepended when position is bottom" );
|
|
|
|
ok( !button.find( "ui-button-icon-space" ).length,
|
|
|
|
"Button should not have an iconSpace with position: bottom" );
|
|
|
|
assert.hasClasses( icon, "ui-widget-icon-block" );
|
|
|
|
|
2015-08-21 04:12:35 +00:00
|
|
|
} );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2015-04-06 14:13:15 +00:00
|
|
|
} );
|