]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Walk previous tabs (and loop) in refresh() in case the tab we're trying to...
authorScott González <scott.gonzalez@gmail.com>
Tue, 12 Jun 2012 14:07:16 +0000 (10:07 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 12 Jun 2012 14:07:16 +0000 (10:07 -0400)
tests/unit/tabs/tabs_methods.js
ui/jquery.ui.tabs.js

index ed3e73745bff5ee269fd9209d93aa0cb1ce76b57..e48d353e744a8bc0839d1ef02cac7faaee610539 100644 (file)
@@ -148,6 +148,26 @@ test( "refresh", function() {
        disabled( element, false );
 });
 
+test( "refresh - looping", function() {
+       expect( 6 );
+
+       var element = $( "#tabs1" ).tabs({
+               disabled: [ 0 ],
+               active: 1
+       });
+       state( element, 0, 1, 0 );
+       disabled( element, [ 0 ] );
+
+       // remove active, jump to previous
+       // previous is disabled, just back one more
+       // reached first tab, move to end
+       // activate last tab
+       element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
+       element.tabs( "refresh" );
+       state( element, 0, 1 );
+       disabled( element, [ 0 ] );
+});
+
 asyncTest( "load", function() {
        expect( 30 );
 
index 8c7bd207b459d07b6bc493bde63331ebdf5115de..e71b2a244666527aff22ebc0d8a4dd5120c565fb 100644 (file)
@@ -229,7 +229,7 @@ $.widget( "ui.tabs", {
                }
        },
 
-       _focusNextTab: function( index, goingForward ) {
+       _findNextTab: function( index, goingForward ) {
                var lastTabIndex = this.tabs.length - 1;
 
                function constrain() {
@@ -246,6 +246,11 @@ $.widget( "ui.tabs", {
                        index = goingForward ? index + 1 : index - 1;
                }
 
+               return index;
+       },
+
+       _focusNextTab: function( index, goingForward ) {
+               index = this._findNextTab( index, goingForward );
                this.tabs.eq( index ).focus();
                return index;
        },
@@ -309,9 +314,14 @@ $.widget( "ui.tabs", {
                        this.active = $();
                // was active, but active tab is gone
                } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
+                       // all remaining tabs are disabled
+                       if ( this.tabs.length === options.disabled.length ) {
+                               options.active = false;
+                               this.active = $();
                        // activate previous tab
-                       next = options.active - 1;
-                       this._activate( next >= 0 ? next : 0 );
+                       } else {
+                               this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
+                       }
                // was active, active tab still exists
                } else {
                        // make sure active index is correct