Skip to content

Commit

Permalink
Tabs: enable/disable handle when current state already matches, fix e…
Browse files Browse the repository at this point in the history
…rror when disabled = true and enable gets called
  • Loading branch information
petersendidit authored and scottgonzalez committed Apr 28, 2011
1 parent abe4c37 commit 0e7769c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 20 additions & 2 deletions tests/unit/tabs/tabs_methods.js
Expand Up @@ -18,7 +18,7 @@ test('destroy', function() {
});

test('enable', function() {
expect(8);
expect(12);

el = $('#tabs1').tabs({ disabled: [ 0, 1 ] });
el.tabs("enable", 1);
Expand All @@ -31,6 +31,18 @@ test('enable', function() {
ok( !$('li.ui-state-disabled', el).length, 'enable all');
same(el.tabs('option', 'disabled'), false, 'update property');

// enable one tab
el.tabs({ disabled: true });
el.tabs("enable", 1);
ok( $('li:eq(1)', el).is(':not(.ui-state-disabled)'), 'remove class from li');
same(el.tabs('option', 'disabled'), [ 0, 2 ], 'update property');

// all tabs already enabled
el.tabs({ disabled: false });
el.tabs("enable", 1);
ok( !$('li.ui-state-disabled', el).length, 'enable all');
same(el.tabs('option', 'disabled'), false, 'update property');

el.tabs('destroy');
// enable all tabs one by one
el.tabs({ disabled: [ 1, 2 ] });
Expand All @@ -43,7 +55,7 @@ test('enable', function() {
});

test('disable', function() {
expect(12);
expect(14);

// normal
el = $('#tabs1').tabs();
Expand All @@ -61,6 +73,12 @@ test('disable', function() {
same( $('li.ui-state-disabled', el).length, 3, 'disable all');
same(el.tabs('option', 'disabled'), true, 'set to true');

// all tabs already disabled
el.tabs({ disabled: true });
el.tabs("disable", 1);
ok( $('li.ui-state-disabled', el).length, 'disable all');
same(el.tabs('option', 'disabled'), true, 'set to true');

el.tabs("destroy");
// disable all tabs one by one
el.tabs();
Expand Down
10 changes: 9 additions & 1 deletion ui/jquery.ui.tabs.js
Expand Up @@ -513,6 +513,9 @@ $.widget( "ui.tabs", {

enable: function( index ) {
var disabled = this.options.disabled;
if ( disabled === false ) {
return;
}

if ( index === undefined ) {
disabled = false;
Expand All @@ -523,14 +526,19 @@ $.widget( "ui.tabs", {
return num !== index ? num : null;
});
} else {
disabled = [ index ];
disabled = $.map( this.lis, function( li, num ) {
return num !== index ? num : null;
});
}
}
this._setupDisabled( disabled );
},

disable: function( index ) {
var disabled = this.options.disabled;
if ( disabled === true ) {
return;
}

if ( index === undefined ) {
disabled = true;
Expand Down

0 comments on commit 0e7769c

Please sign in to comment.