mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tabs: Reduce cyclomatic complexity.
This commit is contained in:
parent
9deb71b713
commit
ebf8a60187
65
ui/jquery.ui.tabs.js
vendored
65
ui/jquery.ui.tabs.js
vendored
@ -47,9 +47,7 @@ $.widget( "ui.tabs", {
|
|||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var that = this,
|
var that = this,
|
||||||
options = this.options,
|
options = this.options;
|
||||||
active = options.active,
|
|
||||||
locationHash = location.hash.substring( 1 );
|
|
||||||
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
|
||||||
@ -75,6 +73,36 @@ $.widget( "ui.tabs", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this._processTabs();
|
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 ) {
|
if ( active === null ) {
|
||||||
// check the fragment identifier in the URL
|
// check the fragment identifier in the URL
|
||||||
@ -102,38 +130,16 @@ $.widget( "ui.tabs", {
|
|||||||
if ( active !== false ) {
|
if ( active !== false ) {
|
||||||
active = this.tabs.index( this.tabs.eq( active ) );
|
active = this.tabs.index( this.tabs.eq( active ) );
|
||||||
if ( active === -1 ) {
|
if ( active === -1 ) {
|
||||||
active = options.collapsible ? false : 0;
|
active = collapsible ? false : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.active = active;
|
|
||||||
|
|
||||||
// don't allow collapsible: false and active: false
|
// don't allow collapsible: false and active: false
|
||||||
if ( !options.collapsible && options.active === false && this.anchors.length ) {
|
if ( !collapsible && active === false && this.anchors.length ) {
|
||||||
options.active = 0;
|
active = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take disabling tabs via class attribute from HTML
|
return active;
|
||||||
// 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( this.options.active );
|
|
||||||
} else {
|
|
||||||
this.active = $();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._refresh();
|
|
||||||
|
|
||||||
if ( this.active.length ) {
|
|
||||||
this.load( options.active );
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_getCreateEventData: function() {
|
_getCreateEventData: function() {
|
||||||
@ -144,6 +150,7 @@ $.widget( "ui.tabs", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_tabKeydown: function( event ) {
|
_tabKeydown: function( event ) {
|
||||||
|
/*jshint maxcomplexity:15*/
|
||||||
var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
|
var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
|
||||||
selectedIndex = this.tabs.index( focusedTab ),
|
selectedIndex = this.tabs.index( focusedTab ),
|
||||||
goingForward = true;
|
goingForward = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user