aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.tabs.js
diff options
context:
space:
mode:
authorDavid Petersen <public@petersendidit.com>2011-04-17 19:51:45 -0400
committerScott González <scott.gonzalez@gmail.com>2011-04-28 09:37:47 -0400
commitabe4c37748628d17627493070abddbd8084b3b36 (patch)
tree29a5708c19ee9046df8c023a50b8b57b9be352b9 /ui/jquery.ui.tabs.js
parenta1473042b44e2fb1415ad4d996397d315ddb462c (diff)
downloadjquery-ui-abe4c37748628d17627493070abddbd8084b3b36.tar.gz
jquery-ui-abe4c37748628d17627493070abddbd8084b3b36.zip
Tabs: simplify disabled logic
Diffstat (limited to 'ui/jquery.ui.tabs.js')
-rwxr-xr-xui/jquery.ui.tabs.js86
1 files changed, 40 insertions, 46 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js
index d4ee9984f..f73799f02 100755
--- a/ui/jquery.ui.tabs.js
+++ b/ui/jquery.ui.tabs.js
@@ -181,14 +181,7 @@ $.widget( "ui.tabs", {
this.lis.addClass( "ui-state-default ui-corner-top" );
this.panels.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" );
- if ( !options.disabled.length ) {
- options.disabled = false;
- }
-
- // disable tabs
- for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
- $( li ).toggleClass( "ui-state-disabled", $.inArray( i, options.disabled ) !== -1 );
- }
+ this._setupDisabled( options.disabled );
this._setupEvents( options.event );
@@ -260,6 +253,23 @@ $.widget( "ui.tabs", {
.data( "destroy.tabs", true );
},
+ _setupDisabled: function( disabled ) {
+ if ( $.isArray( disabled ) ) {
+ if ( !disabled.length ) {
+ disabled = false;
+ } else if ( disabled.length === this.anchors.length ) {
+ disabled = true;
+ }
+ }
+
+ // disable tabs
+ for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
+ $( li ).toggleClass( "ui-state-disabled", ( disabled === true || $.inArray( i, disabled ) !== -1 ) );
+ }
+
+ this.options.disabled = disabled;
+ },
+
_setupFx: function( fx ) {
// set up animations
if ( fx ) {
@@ -502,53 +512,37 @@ $.widget( "ui.tabs", {
},
enable: function( index ) {
+ var disabled = this.options.disabled;
+
if ( index === undefined ) {
- for ( var i = 0, len = this.lis.length; i < len; i++ ) {
- this.enable( i );
+ disabled = false;
+ } else {
+ index = this._getIndex( index );
+ if ( $.isArray( disabled ) ) {
+ disabled = $.map( disabled, function( num ) {
+ return num !== index ? num : null;
+ });
+ } else {
+ disabled = [ index ];
}
- return this;
}
- index = this._getIndex( index );
- var o = this.options;
- if ( !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
- return;
- }
-
- this.lis.eq( index ).removeClass( "ui-state-disabled" );
- o.disabled = this.lis.map( function( i ) {
- return $(this).is( ".ui-state-disabled" ) ? i : null;
- }).get();
-
- if ( !o.disabled.length ) {
- o.disabled = false;
- }
-
- return this;
+ this._setupDisabled( disabled );
},
disable: function( index ) {
+ var disabled = this.options.disabled;
+
if ( index === undefined ) {
- for ( var i = 0, len = this.lis.length; i < len; i++ ) {
- this.disable( i );
- }
- return this;
- }
- index = this._getIndex( index );
- var o = this.options;
- if ( !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
- this.lis.eq( index ).addClass( "ui-state-disabled" );
-
- o.disabled = this.lis.map( function( i ) {
- return $(this).is( ".ui-state-disabled" ) ? i : null;
- }).get();
-
- if ( o.disabled.length === this.anchors.length ) {
- o.disabled = true;
+ disabled = true;
+ } else {
+ index = this._getIndex( index );
+ if ( $.isArray( disabled ) ) {
+ disabled = $.merge( [ index ], disabled ).sort();
+ } else {
+ disabled = [ index ];
}
-
}
-
- return this;
+ this._setupDisabled( disabled );
},
load: function( index, event ) {