Tabs: Fixed back-compat for selected option. Fixes #7135 - Tabs: Rename selected option to active.

This commit is contained in:
Scott González 2011-05-03 07:14:19 -04:00
parent 45c727d75e
commit 92bcb2504f
2 changed files with 51 additions and 47 deletions

View File

@ -107,49 +107,57 @@ test('spinner', function() {
}); });
}); });
test('selected', function() { test( "selected", function() {
expect(10); expect( 19 );
el = $('#tabs1').tabs(); var element = $( "#tabs1" ).tabs();
equals(el.tabs('option', 'selected'), 0, 'should be 0 by default'); equals( element.tabs( "option", "selected" ), 0, "should be 0 by default" );
tabs_state( element, 1, 0, 0 );
element.tabs( "destroy" );
el.tabs('destroy'); location.hash = "#fragment-3";
//set a hash in the url element = $( "#tabs1" ).tabs();
location.hash = '#fragment-2'; equals( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" );
//selection of tab with divs ordered differently than list tabs_state( element, 0, 0, 1 );
el = $('#tabs1').tabs(); element.tabs( "destroy" );
equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
el.tabs('destroy'); el = $('#tabs1').tabs({
//set a hash in the url selected: -1,
location.hash = '#tabs7-2'; collapsible: true
//selection of tab with divs ordered differently than list });
el = $('#tabs7').tabs(); tabs_state( element, 0, 0, 0 );
equals(el.tabs('option', 'selected'), 1, 'second tab should be selected'); equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
strictEqual( element.tabs( "option", "selected" ), -1 );
el.tabs('destroy'); element.tabs( "option", "collapsible", false );
el = $('#tabs1').tabs({ selected: -1 }); tabs_state( element, 1, 0, 0 );
equals(el.tabs('option', 'selected'), -1, 'should be -1 for all tabs unselected'); equal( element.tabs( "option", "selected" ), 0 );
equals( $('li.ui-tabs-active', el).length, 0, 'no tab should be selected' ); element.tabs( "destroy" );
equals( $('div:hidden', '#tabs1').length, 3, 'all panels should be hidden' );
el.tabs('destroy'); element.tabs({
el.tabs({ selected: 1 }); selected: -1
equals(el.tabs('option', 'selected'), 1, 'should be specified tab'); });
tabs_state( element, 1, 0, 0 );
strictEqual( element.tabs( "option", "selected" ), 0 );
element.tabs( "destroy" );
el.tabs('destroy'); element.tabs({ selected: 2 });
el.tabs({ selected: 99 }); equals( element.tabs( "option", "selected" ), 2 );
equals(el.tabs('option', 'selected'), 0, 'selected should default to zero if given value is out of index'); tabs_state( element, 0, 0, 1 );
el.tabs('destroy'); element.tabs( "option", "selected", 0 );
el.tabs({ collapsible: true }); equals( element.tabs( "option", "selected" ), 0 );
el.tabs('option', 'selected', 0); tabs_state( element, 1, 0, 0 );
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected');
el.tabs('destroy'); element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
el = $('#tabs1').tabs(); equals( element.tabs( "option", "selected" ), 1 );
el.tabs('select', 1); tabs_state( element, 0, 1, 0 );
equals(el.tabs('option', 'selected'), 1, 'should select tab');
element.tabs( "option", "selected", 10 );
equals( element.tabs( "option", "selected" ), 1 );
tabs_state( element, 0, 1, 0 );
location.hash = "#";
}); });
module( "tabs (deprecated): events" ); module( "tabs (deprecated): events" );

20
ui/jquery.ui.tabs.js vendored
View File

@ -948,19 +948,15 @@ if ( $.uiBackCompat !== false ) {
}; };
prototype._setOption = function( key, value ) { prototype._setOption = function( key, value ) {
var options = this.options; if ( key !== "selected" ) {
if ( key === "selected" ) { return _setOption.apply( this, arguments );
key = "active";
} }
_setOption.apply( this, arguments );
if ( key === "active" ) { var options = this.options;
if ( key === - 1 ) { _setOption.call( this, "active", value === -1 ? false : value );
key = false; options.selected = options.active;
} if ( options.selected === false ) {
options.selected = options.active; options.selected = -1;
if ( options.selected === false ) {
options.selected = -1;
}
} }
}; };