Skip to content

Commit

Permalink
Tabs: When adding a new tab with an existing panel, don't move it. Fi…
Browse files Browse the repository at this point in the history
…xes #4578 - adding tab moves targeted panel.
  • Loading branch information
David Murdoch authored and scottgonzalez committed May 16, 2011
1 parent db3d194 commit 965cb73
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ui/jquery.ui.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,20 +775,30 @@ if ( $.uiBackCompat !== false ) {
li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
li.find( "a" ).attr( "aria-controls", id );

var doInsertAfter = index >= this.lis.length;

// try to find an existing element before creating a new one
var panel = this.element.find( "#" + id );
if ( !panel.length ) {
panel = this._createPanel( id );
if ( doInsertAfter ) {
if ( index > 0 ) {
panel.insertAfter( this.panels.eq( -1 ) );
} else {
panel.appendTo( this.element );
}
} else {
panel.insertBefore( this.panels[ index ] );
}
}
panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();

if ( index >= this.lis.length ) {
if ( doInsertAfter ) {
li.appendTo( this.list );
panel.appendTo( this.list[ 0 ].parentNode );
} else {
li.insertBefore( this.lis[ index ] );
panel.insertBefore( this.panels[ index ] );
}

options.disabled = $.map( options.disabled, function( n ) {
return n >= index ? ++n : n;
});
Expand Down

0 comments on commit 965cb73

Please sign in to comment.