From 0e7769c66958a0f86ffda0209caa4039d96c79b2 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Sun, 17 Apr 2011 21:09:47 -0400 Subject: [PATCH] Tabs: enable/disable handle when current state already matches, fix error when disabled = true and enable gets called --- tests/unit/tabs/tabs_methods.js | 22 ++++++++++++++++++++-- ui/jquery.ui.tabs.js | 10 +++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index 7c72cd26d..bd28316c5 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.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(); diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index f73799f02..5c525b34a 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -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,7 +526,9 @@ $.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 ); @@ -531,6 +536,9 @@ $.widget( "ui.tabs", { disable: function( index ) { var disabled = this.options.disabled; + if ( disabled === true ) { + return; + } if ( index === undefined ) { disabled = true; -- 2.39.5