Skip to content

Commit ebf8a60

Browse files
committed
Tabs: Reduce cyclomatic complexity.
1 parent 9deb71b commit ebf8a60

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

ui/jquery.ui.tabs.js

+36-29
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ $.widget( "ui.tabs", {
4747

4848
_create: function() {
4949
var that = this,
50-
options = this.options,
51-
active = options.active,
52-
locationHash = location.hash.substring( 1 );
50+
options = this.options;
5351

5452
this.running = false;
5553

@@ -75,6 +73,36 @@ $.widget( "ui.tabs", {
7573
});
7674

7775
this._processTabs();
76+
options.active = this._initialActive();
77+
78+
// Take disabling tabs via class attribute from HTML
79+
// into account and update option properly.
80+
if ( $.isArray( options.disabled ) ) {
81+
options.disabled = $.unique( options.disabled.concat(
82+
$.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
83+
return that.tabs.index( li );
84+
})
85+
) ).sort();
86+
}
87+
88+
// check for length avoids error when initializing empty list
89+
if ( this.options.active !== false && this.anchors.length ) {
90+
this.active = this._findActive( options.active );
91+
} else {
92+
this.active = $();
93+
}
94+
95+
this._refresh();
96+
97+
if ( this.active.length ) {
98+
this.load( options.active );
99+
}
100+
},
101+
102+
_initialActive: function() {
103+
var active = this.options.active,
104+
collapsible = this.options.collapsible,
105+
locationHash = location.hash.substring( 1 );
78106

79107
if ( active === null ) {
80108
// check the fragment identifier in the URL
@@ -102,38 +130,16 @@ $.widget( "ui.tabs", {
102130
if ( active !== false ) {
103131
active = this.tabs.index( this.tabs.eq( active ) );
104132
if ( active === -1 ) {
105-
active = options.collapsible ? false : 0;
133+
active = collapsible ? false : 0;
106134
}
107135
}
108-
options.active = active;
109136

110137
// don't allow collapsible: false and active: false
111-
if ( !options.collapsible && options.active === false && this.anchors.length ) {
112-
options.active = 0;
113-
}
114-
115-
// Take disabling tabs via class attribute from HTML
116-
// into account and update option properly.
117-
if ( $.isArray( options.disabled ) ) {
118-
options.disabled = $.unique( options.disabled.concat(
119-
$.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
120-
return that.tabs.index( li );
121-
})
122-
) ).sort();
138+
if ( !collapsible && active === false && this.anchors.length ) {
139+
active = 0;
123140
}
124141

125-
// check for length avoids error when initializing empty list
126-
if ( this.options.active !== false && this.anchors.length ) {
127-
this.active = this._findActive( this.options.active );
128-
} else {
129-
this.active = $();
130-
}
131-
132-
this._refresh();
133-
134-
if ( this.active.length ) {
135-
this.load( options.active );
136-
}
142+
return active;
137143
},
138144

139145
_getCreateEventData: function() {
@@ -144,6 +150,7 @@ $.widget( "ui.tabs", {
144150
},
145151

146152
_tabKeydown: function( event ) {
153+
/*jshint maxcomplexity:15*/
147154
var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
148155
selectedIndex = this.tabs.index( focusedTab ),
149156
goingForward = true;

0 commit comments

Comments
 (0)