diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-03-21 11:30:11 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-03-21 11:30:11 -0400 |
commit | 923b5b67b9e23b58b4ce184c8c0de343d5b179be (patch) | |
tree | 0cf2c9f1ca32a12a2b7178b2b1ec65c655aac2ea /ui | |
parent | 52fd686f08d9ff1fab8b7fd92384e33bc26465da (diff) | |
parent | 710d7620e7f713677a21fc5a8572581250499dd3 (diff) | |
download | jquery-ui-923b5b67b9e23b58b4ce184c8c0de343d5b179be.tar.gz jquery-ui-923b5b67b9e23b58b4ce184c8c0de343d5b179be.zip |
Merge branch 'tabs_4386' of https://github.com/petersendidit/jquery-ui
Diffstat (limited to 'ui')
-rwxr-xr-x | ui/jquery.ui.tabs.js | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index c1c78653a..fcdf22c0e 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -32,7 +32,7 @@ $.widget( "ui.tabs", { cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true } collapsible: false, disable: null, - disabled: [], + disabled: false, enable: null, event: "click", fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 } @@ -194,15 +194,12 @@ $.widget( "ui.tabs", { // Take disabling tabs via class attribute from HTML // into account and update option properly. - // A selected tab cannot become disabled. - o.disabled = $.unique( o.disabled.concat( - $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) { - return self.lis.index( n ); - }) - ) ).sort(); - - if ( $.inArray( o.selected, o.disabled ) != -1 ) { - o.disabled.splice( $.inArray( o.selected, o.disabled ), 1 ); + if ( $.isArray( o.disabled ) ) { + o.disabled = $.unique( o.disabled.concat( + $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) { + return self.lis.index( n ); + }) + ) ).sort(); } // highlight selected tab @@ -233,6 +230,10 @@ $.widget( "ui.tabs", { o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) ); } + if ( !o.disabled.length ) { + o.disabled = false; + } + this.element.toggleClass( "ui-tabs-collapsible", o.collapsible ); // set or update cookie after init and add/remove respectively @@ -242,8 +243,7 @@ $.widget( "ui.tabs", { // disable tabs for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) { - $( li ).toggleClass( "ui-state-disabled", - $.inArray( i, o.disabled ) != -1 && !$( li ).hasClass( "ui-tabs-selected" ) ); + $( li ).toggleClass( "ui-state-disabled", $.inArray( i, o.disabled ) != -1 ); } // reset cache if switching from cached to not cached @@ -533,30 +533,50 @@ $.widget( "ui.tabs", { }, enable: function( index ) { + if ( index === undefined ) { + for ( var i = 0, len = this.lis.length; i < len; i++ ) { + this.enable( i ); + } + return this; + } index = this._getIndex( index ); var o = this.options; - if ( $.inArray( index, o.disabled ) == -1 ) { + if ( !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) { return; } this.lis.eq( index ).removeClass( "ui-state-disabled" ); - o.disabled = $.grep( o.disabled, function( n, i ) { - return n != index; - }); + o.disabled = this.lis.map( function( i ) { + return $(this).is( ".ui-state-disabled" ) ? i : null; + }).get(); + + if ( !o.disabled.length ) { + o.disabled = false; + } this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); return this; }, disable: function( index ) { + if ( index === undefined ) { + for ( var i = 0, len = this.lis.length; i < len; i++ ) { + this.disable( i ); + } + return this; + } index = this._getIndex( index ); - var self = this, o = this.options; - // cannot disable already selected tab - if ( index != o.selected ) { + 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.push( index ); - o.disabled.sort(); + 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; + } this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); } |