From d819cdd3a92d9d152a33ce6aecbd5cd9737a3ade Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 28 Apr 2011 12:04:08 -0400 Subject: [PATCH] Tabs: Fixed disable method and cleaned up tests for enable and disable methods. --- tests/unit/tabs/tabs.html | 35 +++++++ tests/unit/tabs/tabs_deprecated.html | 35 +++++++ tests/unit/tabs/tabs_methods.js | 134 +++++++++++++-------------- ui/jquery.ui.tabs.js | 3 + 4 files changed, 136 insertions(+), 71 deletions(-) diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html index bba0e8a58..3e38f5f25 100644 --- a/tests/unit/tabs/tabs.html +++ b/tests/unit/tabs/tabs.html @@ -46,6 +46,41 @@ }).get(); same( actual, expected ); } + + function tabs_disabled( tabs, state ) { + var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { + if ( typeof state === "boolean" ) { + return state ? 1 : 0; + } else { + return $.inArray( index, state ) !== -1 ? 1 : 0; + } + }); + + var 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; + }); + } + + var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) { + 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; + } + return -1; // mixed state - invalid + }).get(); + same( tabs.tabs( "option", "disabled" ), state ); + same( actual, expected ); + }