diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-04-28 21:35:04 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-04-28 21:35:04 -0400 |
commit | 1bacdec6be7e9d543224c69344041aaccde059c0 (patch) | |
tree | 92829155963b371017375aa689b9f47aa2c801d6 /ui/jquery.ui.tabs.js | |
parent | c3d9bd070051a79e1a288935d420f85278268149 (diff) | |
download | jquery-ui-1bacdec6be7e9d543224c69344041aaccde059c0.tar.gz jquery-ui-1bacdec6be7e9d543224c69344041aaccde059c0.zip |
Tabs: Cleaned up add and remove methods.
Diffstat (limited to 'ui/jquery.ui.tabs.js')
-rwxr-xr-x | ui/jquery.ui.tabs.js | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 490ca71a3..7946cc667 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -826,33 +826,39 @@ if ( $.uiBackCompat !== false ) { index = this.anchors.length; } - var self = this, - o = this.options, - $li = $( o.tabTemplate.replace( /#\{href\}/g, url ).replace( /#\{label\}/g, label ) ), - id = !url.indexOf( "#" ) ? url.replace( "#", "" ) : this._tabId( $( "a", $li )[ 0 ] ); + var options = this.options, + li = $( options.tabTemplate + .replace( /#\{href\}/g, url ) + .replace( /#\{label\}/g, label ) ), + id = !url.indexOf( "#" ) ? + url.replace( "#", "" ) : + this._tabId( li.find( "a" )[ 0 ] ); - $li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true ); + li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true ); + li.find( "a" ).attr( "aria-controls", id ); // try to find an existing element before creating a new one - var $panel = self.element.find( "#" + id ); - if ( !$panel.length ) { - $panel = self._createPanel( id ); + var panel = this.element.find( "#" + id ); + if ( !panel.length ) { + panel = this._createPanel( id ); } - $panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide(); + panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide(); if ( index >= this.lis.length ) { - $li.appendTo( this.list ); - $panel.appendTo( this.list[ 0 ].parentNode ); + li.appendTo( this.list ); + panel.appendTo( this.list[ 0 ].parentNode ); } else { - $li.insertBefore( this.lis[ index ] ); - $panel.insertBefore( this.panels[ index ] ); + li.insertBefore( this.lis[ index ] ); + panel.insertBefore( this.panels[ index ] ); } - - o.disabled = $.map( o.disabled, function( n, i ) { + options.disabled = $.map( options.disabled, function( n ) { return n >= index ? ++n : n; }); this.refresh(); + if ( this.lis.length === 1 && options.active === false ) { + this.option( "active", 0 ); + } this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); return this; @@ -860,27 +866,27 @@ if ( $.uiBackCompat !== false ) { prototype.remove = function( index ) { index = this._getIndex( index ); - var o = this.options, - $li = this.lis.eq( index ).remove(), - $panel = this.panels.eq( index ).remove(); + var options = this.options, + tab = this.lis.eq( index ).remove(), + panel = this.panels.eq( index ).remove(); // If selected tab was removed focus tab to the right or // in case the last tab was removed the tab to the left. - if ( $li.hasClass( "ui-tabs-active" ) && this.anchors.length > 1) { + if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 1) { this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) ); } - o.disabled = $.map( - $.grep( o.disabled, function(n, i) { - return n != index; + options.disabled = $.map( + $.grep( options.disabled, function( n ) { + return n !== index; }), - function( n, i ) { + function( n ) { return n >= index ? --n : n; }); this.refresh(); - this._trigger( "remove", null, this._ui( $li.find( "a" )[ 0 ], $panel[ 0 ] ) ); + this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) ); return this; }; }( jQuery, jQuery.ui.tabs.prototype ) ); |