From: Scott González Date: Tue, 3 May 2011 10:31:12 +0000 (-0400) Subject: Tabs: Fixed enabled and disabled methods. Fixes #7142 - Tabs: Deprecate enable and... X-Git-Tag: 1.9m5~104 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=45c727d75e411d0330027162646bbb26c4f671f1;p=jquery-ui.git Tabs: Fixed enabled and disabled methods. Fixes #7142 - Tabs: Deprecate enable and disable events. --- diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index 25877e69c..15df3cd25 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -152,39 +152,37 @@ test('selected', function() { equals(el.tabs('option', 'selected'), 1, 'should select tab'); }); -module("tabs (deprecated): events"); +module( "tabs (deprecated): events" ); -test('enable', function() { - expect(4); +test( "enable", function() { + expect( 3 ); - var uiObj; - el = $('#tabs1').tabs({ + var element = $( "#tabs1" ).tabs({ disabled: [ 0, 1 ], - enable: function (event, ui) { - uiObj = ui; + enable: function ( event, ui ) { + equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" ); + equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" ); + equals( ui.index, 1, "ui.index" ); } }); - el.tabs('enable', 1); - ok(uiObj !== undefined, 'trigger callback'); - equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element'); - equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element'); - equals(uiObj.index, 1, 'contain index'); + element.tabs( "enable", 1 ); + // shouldn't trigger event + element.tabs( "enable", 2 ); }); -test('disable', function() { - expect(4); +test( "disable", function() { + expect( 3 ); - var uiObj; - el = $('#tabs1').tabs({ - disable: function (event, ui) { - uiObj = ui; + var element = $( "#tabs1" ).tabs({ + disable: function ( event, ui ) { + equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" ); + equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" ); + equals( ui.index, 1, "ui.index" ); } }); - el.tabs('disable', 1); - ok(uiObj !== undefined, 'trigger callback'); - equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element'); - equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element'); - equals(uiObj.index, 1, 'contain index'); + element.tabs( "disable", 1 ); + // shouldn't trigger event + element.tabs( "disable", 1 ); }); test('show', function() { diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 7946cc667..39969d655 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -783,10 +783,11 @@ if ( $.uiBackCompat !== false ) { disable = prototype.disable; prototype.enable = function( index ) { - var o = this.options, + var options = this.options, trigger; - if ( index && o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) !== -1 ) ) { + if ( index && options.disabled === true || + ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) { trigger = true; } @@ -798,10 +799,11 @@ if ( $.uiBackCompat !== false ) { }; prototype.disable = function( index ) { - var o = this.options, + var options = this.options, trigger; - if ( index && !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) { + if ( index && options.disabled === false || + ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) { trigger = true; }