]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Reduce cyclomatic complexity.
authorScott González <scott.gonzalez@gmail.com>
Thu, 6 Dec 2012 19:18:20 +0000 (14:18 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 6 Dec 2012 19:31:21 +0000 (14:31 -0500)
ui/jquery.ui.tabs.js

index bce0585a023a10a1f270dc972f0b66f2a8df75bc..fb66ec6a5ea6963110bf59d4587b809098885e76 100644 (file)
@@ -47,9 +47,7 @@ $.widget( "ui.tabs", {
 
        _create: function() {
                var that = this,
-                       options = this.options,
-                       active = options.active,
-                       locationHash = location.hash.substring( 1 );
+                       options = this.options;
 
                this.running = false;
 
@@ -75,6 +73,36 @@ $.widget( "ui.tabs", {
                        });
 
                this._processTabs();
+               options.active = this._initialActive();
+
+               // Take disabling tabs via class attribute from HTML
+               // into account and update option properly.
+               if ( $.isArray( options.disabled ) ) {
+                       options.disabled = $.unique( options.disabled.concat(
+                               $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
+                                       return that.tabs.index( li );
+                               })
+                       ) ).sort();
+               }
+
+               // check for length avoids error when initializing empty list
+               if ( this.options.active !== false && this.anchors.length ) {
+                       this.active = this._findActive( options.active );
+               } else {
+                       this.active = $();
+               }
+
+               this._refresh();
+
+               if ( this.active.length ) {
+                       this.load( options.active );
+               }
+       },
+
+       _initialActive: function() {
+               var active = this.options.active,
+                       collapsible = this.options.collapsible,
+                       locationHash = location.hash.substring( 1 );
 
                if ( active === null ) {
                        // check the fragment identifier in the URL
@@ -102,38 +130,16 @@ $.widget( "ui.tabs", {
                if ( active !== false ) {
                        active = this.tabs.index( this.tabs.eq( active ) );
                        if ( active === -1 ) {
-                               active = options.collapsible ? false : 0;
+                               active = collapsible ? false : 0;
                        }
                }
-               options.active = active;
 
                // don't allow collapsible: false and active: false
-               if ( !options.collapsible && options.active === false && this.anchors.length ) {
-                       options.active = 0;
-               }
-
-               // Take disabling tabs via class attribute from HTML
-               // into account and update option properly.
-               if ( $.isArray( options.disabled ) ) {
-                       options.disabled = $.unique( options.disabled.concat(
-                               $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
-                                       return that.tabs.index( li );
-                               })
-                       ) ).sort();
+               if ( !collapsible && active === false && this.anchors.length ) {
+                       active = 0;
                }
 
-               // check for length avoids error when initializing empty list
-               if ( this.options.active !== false && this.anchors.length ) {
-                       this.active = this._findActive( this.options.active );
-               } else {
-                       this.active = $();
-               }
-
-               this._refresh();
-
-               if ( this.active.length ) {
-                       this.load( options.active );
-               }
+               return active;
        },
 
        _getCreateEventData: function() {
@@ -144,6 +150,7 @@ $.widget( "ui.tabs", {
        },
 
        _tabKeydown: function( event ) {
+               /*jshint maxcomplexity:15*/
                var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
                        selectedIndex = this.tabs.index( focusedTab ),
                        goingForward = true;