Skip to content
Permalink
Browse files

Tabs: enable/disable handle when current state already matches, fix e…

…rror when disabled = true and enable gets called
  • Loading branch information...
petersendidit authored and scottgonzalez committed Apr 18, 2011
1 parent abe4c37 commit 0e7769c66958a0f86ffda0209caa4039d96c79b2
Showing with 29 additions and 3 deletions.
  1. +20 −2 tests/unit/tabs/tabs_methods.js
  2. +9 −1 ui/jquery.ui.tabs.js
@@ -18,7 +18,7 @@ test('destroy', function() {
});

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

el = $('#tabs1').tabs({ disabled: [ 0, 1 ] });
el.tabs("enable", 1);
@@ -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 ] });
@@ -43,7 +55,7 @@ test('enable', function() {
});

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

// normal
el = $('#tabs1').tabs();
@@ -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();
@@ -513,6 +513,9 @@ $.widget( "ui.tabs", {

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

if ( index === undefined ) {
disabled = false;
@@ -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;

0 comments on commit 0e7769c

Please sign in to comment.
You can’t perform that action at this time.