2011-04-11 17:49:22 +00:00
|
|
|
(function( $ ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-04-19 16:53:06 +00:00
|
|
|
var disabled = TestHelpers.tabs.disabled,
|
|
|
|
state = TestHelpers.tabs.state;
|
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
module( "tabs: options" );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
test( "{ active: default }", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 0, "should be 0 by default" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
2011-04-15 12:53:05 +00:00
|
|
|
location.hash = "#fragment-3";
|
2011-04-11 17:49:22 +00:00
|
|
|
element = $( "#tabs1" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
2011-04-15 12:53:05 +00:00
|
|
|
element.tabs( "destroy" );
|
2011-05-03 11:14:33 +00:00
|
|
|
location.hash = "#";
|
2011-04-11 17:49:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ active: false }", function() {
|
|
|
|
expect( 7 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
active: false,
|
|
|
|
collapsible: true
|
|
|
|
});
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( element.find( ".ui-tabs-nav .ui-state-active" ).length, 0, "no tabs selected" );
|
2011-04-11 17:49:22 +00:00
|
|
|
strictEqual( element.tabs( "option", "active" ), false );
|
|
|
|
|
|
|
|
element.tabs( "option", "collapsible", false );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 0 );
|
|
|
|
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
element.tabs({
|
|
|
|
active: false
|
|
|
|
});
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
strictEqual( element.tabs( "option", "active" ), 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ active: Number }", function() {
|
|
|
|
expect( 8 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
active: 2
|
|
|
|
});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
2011-04-11 17:49:22 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 0 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2009-02-03 13:37:54 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2009-02-03 13:37:54 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
element.tabs( "option", "active", 10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
test( "{ active: -Number }", function() {
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
active: -1
|
|
|
|
});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
2011-04-11 17:49:22 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", -2 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", -10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", -3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 0 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-15 12:53:05 +00:00
|
|
|
test( "active - mismatched tab/panel order", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
location.hash = "#tabs7-2";
|
|
|
|
var element = $( "#tabs7" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1 );
|
2011-04-15 12:53:05 +00:00
|
|
|
element.tabs( "option", "active", 0 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0 );
|
2011-05-03 11:14:33 +00:00
|
|
|
location.hash = "#";
|
2011-04-15 12:53:05 +00:00
|
|
|
});
|
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
test( "{ collapsible: false }", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
active: 1
|
|
|
|
});
|
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
|
|
|
|
element.find( ".ui-state-active a" ).eq( 1 ).click();
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-04-11 17:49:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ collapsible: true }", function() {
|
|
|
|
expect( 6 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
active: 1,
|
|
|
|
collapsible: true
|
|
|
|
});
|
2011-03-29 02:28:59 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
equal( element.tabs( "option", "active" ), false );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
element.tabs( "option", "active", 1 );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2010-04-21 19:31:29 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
element.find( ".ui-state-active a" ).click();
|
|
|
|
equal( element.tabs( "option", "active" ), false );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
test( "disabled", function() {
|
|
|
|
expect( 10 );
|
2010-04-21 19:31:29 +00:00
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
// fully enabled by default
|
|
|
|
var element = $( "#tabs1" ).tabs();
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-05-09 21:10:36 +00:00
|
|
|
|
|
|
|
// disable single tab
|
|
|
|
element.tabs( "option", "disabled", [ 1 ] );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 1 ] );
|
2010-04-21 19:31:29 +00:00
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
// disabled active tab
|
|
|
|
element.tabs( "option", "disabled", [ 0, 1 ] );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0, 1 ] );
|
2010-04-21 19:31:29 +00:00
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
// disable all tabs
|
|
|
|
element.tabs( "option", "disabled", [ 0, 1, 2 ] );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2010-04-21 19:31:29 +00:00
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
// enable all tabs
|
|
|
|
element.tabs( "option", "disabled", [] );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-05-09 21:01:11 +00:00
|
|
|
test( "{ event: null }", function() {
|
|
|
|
expect( 5 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
event: null
|
|
|
|
});
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "active", 1 );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
// ensure default click handler isn't bound
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).click();
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "{ event: custom }", function() {
|
|
|
|
expect( 11 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
event: "custom1 custom2"
|
|
|
|
});
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
// ensure default click handler isn't bound
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "custom2" );
|
|
|
|
equal( element.tabs( "option", "active" ), 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
element.tabs( "option", "event", "custom3" );
|
|
|
|
|
|
|
|
// ensure old event handlers are unbound
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" );
|
|
|
|
equal( element.tabs( "option", "active" ), 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
2011-05-09 21:01:11 +00:00
|
|
|
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom3" );
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-05-09 21:10:36 +00:00
|
|
|
// TODO: add animation tests
|
2009-02-03 13:37:54 +00:00
|
|
|
|
2011-05-10 12:47:00 +00:00
|
|
|
}( jQuery ) );
|