2015-04-07 14:30:07 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
|
|
|
"lib/helper",
|
2015-07-15 02:11:35 +00:00
|
|
|
"ui/widgets/tabs"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, helper ) {
|
2015-04-06 19:01:13 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
return $.extend( helper, {
|
2016-04-06 13:48:50 +00:00
|
|
|
disabled: function( assert, tabs, state ) {
|
2012-04-19 16:53:06 +00:00
|
|
|
var expected, actual,
|
|
|
|
internalState = tabs.tabs( "option", "disabled" );
|
|
|
|
|
|
|
|
if ( internalState === false ) {
|
|
|
|
internalState = [];
|
|
|
|
}
|
|
|
|
if ( internalState === true ) {
|
|
|
|
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
|
|
|
return index;
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-04-19 16:53:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
expected = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
|
2012-04-19 16:53:06 +00:00
|
|
|
if ( typeof state === "boolean" ) {
|
|
|
|
return state ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
return $.inArray( index, state ) !== -1 ? 1 : 0;
|
|
|
|
}
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-04-19 16:53:06 +00:00
|
|
|
|
2015-08-24 12:57:25 +00:00
|
|
|
actual = tabs.find( ".ui-tabs-nav li" ).map( function( index ) {
|
2012-04-19 16:53:06 +00:00
|
|
|
var tab = $( this ),
|
|
|
|
tabIsDisabled = tab.hasClass( "ui-state-disabled" );
|
|
|
|
|
|
|
|
if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-24 12:57:25 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
// Mixed state - invalid
|
2012-04-19 16:53:06 +00:00
|
|
|
return -1;
|
2015-08-24 12:57:25 +00:00
|
|
|
} ).get();
|
2012-04-19 16:53:06 +00:00
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.deepEqual( tabs.tabs( "option", "disabled" ), state );
|
|
|
|
assert.deepEqual( actual, expected );
|
2012-04-19 16:53:06 +00:00
|
|
|
},
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
equalHeight: function( assert, tabs, height ) {
|
2015-08-24 12:57:25 +00:00
|
|
|
tabs.find( ".ui-tabs-panel" ).each( function() {
|
2015-10-26 21:37:41 +00:00
|
|
|
|
|
|
|
// Handle overly-precise values
|
|
|
|
var actualHeight = parseFloat( $( this ).outerHeight().toFixed( 1 ) );
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.equal( actualHeight, height );
|
2015-08-24 12:57:25 +00:00
|
|
|
} );
|
2012-05-28 19:11:20 +00:00
|
|
|
},
|
|
|
|
|
2016-04-06 13:48:50 +00:00
|
|
|
state: function( assert, tabs ) {
|
|
|
|
var expected = $.makeArray( arguments ).slice( 2 ),
|
2015-08-24 12:57:25 +00:00
|
|
|
actual = tabs.find( ".ui-tabs-nav li" ).map( function() {
|
2012-04-19 16:53:06 +00:00
|
|
|
var tab = $( this ),
|
2024-10-26 22:04:00 +00:00
|
|
|
panel = $( "#" + CSS.escape( tab.attr( "aria-controls" ) ) ),
|
2012-04-19 16:53:06 +00:00
|
|
|
tabIsActive = tab.hasClass( "ui-state-active" ),
|
|
|
|
panelIsActive = panel.css( "display" ) !== "none";
|
|
|
|
|
|
|
|
if ( tabIsActive && panelIsActive ) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ( !tabIsActive && !panelIsActive ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-06 13:48:50 +00:00
|
|
|
return -1; // Mixed state - invalid
|
2015-08-24 12:57:25 +00:00
|
|
|
} ).get();
|
2016-04-06 13:48:50 +00:00
|
|
|
assert.deepEqual( actual, expected );
|
2012-04-19 16:53:06 +00:00
|
|
|
}
|
2015-04-07 14:30:07 +00:00
|
|
|
} );
|
2015-04-06 19:01:13 +00:00
|
|
|
|
|
|
|
} );
|