2011-03-26 19:00:39 +00:00
|
|
|
|
(function( $ ) {
|
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
module( "tabs (deprecated): core" );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
|
2011-04-06 01:39:02 +00:00
|
|
|
|
test( "panel ids", function() {
|
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs();
|
|
|
|
|
|
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
|
equal( ui.panel.attr( "id" ), "∫ßáö_Սե", "from title attribute" );
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
2011-04-07 17:53:20 +00:00
|
|
|
|
element.tabs( "option", "active", 4 );
|
2011-04-06 01:39:02 +00:00
|
|
|
|
|
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
|
ok( /^ui-tabs-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" );
|
|
|
|
|
event.preventDefault();
|
2011-03-27 02:14:17 +00:00
|
|
|
|
});
|
2011-04-06 01:39:02 +00:00
|
|
|
|
element.tabs( "option", "active", 2 );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 15:31:01 +00:00
|
|
|
|
module( "tabs (deprecated): options" );
|
2011-03-26 19:00:39 +00:00
|
|
|
|
|
2011-05-09 18:45:57 +00:00
|
|
|
|
asyncTest( "ajaxOptions", function() {
|
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs({
|
|
|
|
|
ajaxOptions: {
|
|
|
|
|
converters: {
|
|
|
|
|
"text html": function() {
|
|
|
|
|
return "test";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( $( ui.panel ).html(), "test" );
|
2011-05-09 18:45:57 +00:00
|
|
|
|
start();
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 2 );
|
2011-03-26 19:00:39 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 19:04:01 +00:00
|
|
|
|
asyncTest( "cache", function() {
|
|
|
|
|
expect( 5 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs({
|
|
|
|
|
cache: true
|
|
|
|
|
});
|
|
|
|
|
element.one( "tabsshow", function( event, ui ) {
|
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
|
|
|
|
});
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
|
|
|
|
ok( true, "tabsload" );
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
element.tabs( "option", "active", 0 );
|
|
|
|
|
tabs_state( element, 1, 0, 0, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
|
2011-05-09 19:04:01 +00:00
|
|
|
|
element.one( "tabsshow", function( event, ui ) {
|
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
|
|
|
|
});
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
|
|
|
|
ok( false, "should be cached" );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 2 );
|
|
|
|
|
start();
|
|
|
|
|
}, 1 );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 2 );
|
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
2011-03-26 19:00:39 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 15:31:01 +00:00
|
|
|
|
test( "idPrefix", function() {
|
|
|
|
|
expect( 1 );
|
2011-03-27 19:12:53 +00:00
|
|
|
|
|
2011-05-09 15:31:01 +00:00
|
|
|
|
$( "#tabs2" )
|
|
|
|
|
.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
|
ok( /^testing-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" );
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
})
|
|
|
|
|
.tabs({
|
|
|
|
|
idPrefix: "testing-",
|
|
|
|
|
active: 2
|
|
|
|
|
});
|
2011-03-27 19:12:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 15:31:01 +00:00
|
|
|
|
test( "tabTemplate + panelTemplate", function() {
|
|
|
|
|
// defaults are tested in the add method test
|
|
|
|
|
expect( 11 );
|
|
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var tab, anchor,
|
|
|
|
|
element = $( "#tabs2" ).tabs({
|
|
|
|
|
tabTemplate: "<li class='customTab'><a href='http://example.com/#{href}'>#{label}</a></li>",
|
|
|
|
|
panelTemplate: "<div class='customPanel'></div>"
|
|
|
|
|
});
|
2011-05-09 15:31:01 +00:00
|
|
|
|
element.one( "tabsadd", function( event, ui ) {
|
|
|
|
|
var anchor = $( ui.tab );
|
|
|
|
|
equal( ui.index, 5, "ui.index" );
|
|
|
|
|
equal( anchor.text(), "New", "ui.tab" );
|
|
|
|
|
equal( anchor.attr( "href" ), "http://example.com/#new", "tab href" );
|
|
|
|
|
ok( anchor.parent().hasClass( "customTab" ), "tab custom class" );
|
|
|
|
|
equal( ui.panel.id, "new", "ui.panel" );
|
|
|
|
|
ok( $( ui.panel ).hasClass( "customPanel" ), "panel custom class" );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "add", "#new", "New" );
|
2012-04-19 02:36:15 +00:00
|
|
|
|
tab = element.find( ".ui-tabs-nav li" ).last();
|
|
|
|
|
anchor = tab.find( "a" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( tab.text(), "New", "label" );
|
2011-05-09 15:31:01 +00:00
|
|
|
|
ok( tab.hasClass( "customTab" ), "tab custom class" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( anchor.attr( "href" ), "http://example.com/#new", "href" );
|
|
|
|
|
equal( anchor.attr( "aria-controls" ), "new", "aria-controls" );
|
2011-05-09 15:31:01 +00:00
|
|
|
|
ok( element.find( "#new" ).hasClass( "customPanel" ), "panel custom class" );
|
2011-03-27 19:12:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
test( "cookie", function() {
|
|
|
|
|
expect( 6 );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
var element = $( "#tabs1" ),
|
|
|
|
|
cookieName = "tabs_test",
|
|
|
|
|
cookieObj = { name: cookieName };
|
|
|
|
|
$.cookie( cookieName, null );
|
|
|
|
|
function cookie() {
|
|
|
|
|
return parseInt( $.cookie( cookieName ), 10 );
|
|
|
|
|
}
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs({ cookie: cookieObj });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( cookie(), 0, "initial cookie value" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
element.tabs({ active: 1, cookie: cookieObj });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( cookie(), 1, "initial cookie value, from active property" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs( "option", "active", 2 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( cookie(), 2, "cookie value updated after activating" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
$.cookie( cookieName, 1 );
|
|
|
|
|
element.tabs({ cookie: cookieObj });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( cookie(), 1, "initial cookie value, from existing cookie" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
element.tabs({ cookie: cookieObj, collapsible: true });
|
|
|
|
|
element.tabs( "option", "active", false );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( cookie(), -1, "cookie value for all tabs unselected" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-10 13:15:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
ok( $.cookie( cookieName ) === null, "erase cookie after destroy" );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 16:52:00 +00:00
|
|
|
|
asyncTest( "spinner", function() {
|
|
|
|
|
expect( 2 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs();
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
2011-05-09 16:52:00 +00:00
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 1, "beforeload" );
|
2011-05-09 16:52:00 +00:00
|
|
|
|
});
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
2011-05-09 20:04:33 +00:00
|
|
|
|
// wait until after the load finishes before checking for the spinner to be removed
|
|
|
|
|
setTimeout(function() {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 0, "load" );
|
2011-05-09 20:04:33 +00:00
|
|
|
|
start();
|
|
|
|
|
}, 1 );
|
2011-03-26 19:48:53 +00:00
|
|
|
|
});
|
2011-05-09 16:52:00 +00:00
|
|
|
|
element.tabs( "option", "active", 2 );
|
2011-03-26 19:48:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
test( "selected", function() {
|
|
|
|
|
expect( 19 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 0, "should be 0 by default" );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
|
|
|
|
|
location.hash = "#fragment-3";
|
|
|
|
|
element = $( "#tabs1" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 0, 0, 1 );
|
|
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
|
|
|
|
|
el = $('#tabs1').tabs({
|
|
|
|
|
selected: -1,
|
|
|
|
|
collapsible: true
|
|
|
|
|
});
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
|
|
|
|
equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" );
|
|
|
|
|
strictEqual( element.tabs( "option", "selected" ), -1 );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.tabs( "option", "collapsible", false );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 0 );
|
|
|
|
|
element.tabs( "destroy" );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.tabs({
|
|
|
|
|
selected: -1
|
|
|
|
|
});
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
strictEqual( element.tabs( "option", "selected" ), 0 );
|
|
|
|
|
element.tabs( "destroy" );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.tabs({ selected: 2 });
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 2 );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 0, 0, 1 );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.tabs( "option", "selected", 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 0 );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 1 ).click();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 1 );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
element.tabs( "option", "selected", 10 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "selected" ), 1 );
|
2011-05-03 11:14:19 +00:00
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
2011-05-03 11:14:19 +00:00
|
|
|
|
location.hash = "#";
|
2011-03-27 20:37:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-03 10:31:12 +00:00
|
|
|
|
module( "tabs (deprecated): events" );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
|
asyncTest( "load", function() {
|
|
|
|
|
expect( 15 );
|
|
|
|
|
|
|
|
|
|
var tab, panelId, panel,
|
|
|
|
|
element = $( "#tabs2" );
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
|
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
|
|
|
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
2011-05-17 19:46:41 +00:00
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
|
|
|
|
tabsload1();
|
|
|
|
|
});
|
|
|
|
|
element.tabs({ active: 2 });
|
|
|
|
|
|
|
|
|
|
function tabsload1() {
|
|
|
|
|
// .option()
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
|
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
|
|
|
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
2011-05-17 19:46:41 +00:00
|
|
|
|
tabs_state( element, 0, 0, 0, 1, 0 );
|
|
|
|
|
tabsload2();
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 3 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tabsload2() {
|
|
|
|
|
// click, change panel content
|
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 4 );
|
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( event.originalEvent.type, "click", "originalEvent" );
|
2011-05-17 19:46:41 +00:00
|
|
|
|
strictEqual( ui.tab, tab[ 0 ], "tab" );
|
|
|
|
|
strictEqual( ui.panel, panel[ 0 ], "panel" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( $( ui.panel ).find( "p" ).length, 1, "panel html" );
|
2011-05-17 19:46:41 +00:00
|
|
|
|
tabs_state( element, 0, 0, 0, 0, 1 );
|
|
|
|
|
start();
|
|
|
|
|
});
|
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-05-03 10:31:12 +00:00
|
|
|
|
test( "enable", function() {
|
|
|
|
|
expect( 3 );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
|
2011-05-03 10:31:12 +00:00
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
2011-03-26 20:12:05 +00:00
|
|
|
|
disabled: [ 0, 1 ],
|
2012-02-01 21:59:26 +00:00
|
|
|
|
enable: function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
|
|
|
|
|
equal( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
|
|
|
|
|
equal( ui.index, 1, "ui.index" );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-05-03 10:31:12 +00:00
|
|
|
|
element.tabs( "enable", 1 );
|
|
|
|
|
// shouldn't trigger event
|
|
|
|
|
element.tabs( "enable", 2 );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-03 10:31:12 +00:00
|
|
|
|
test( "disable", function() {
|
|
|
|
|
expect( 3 );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
|
2011-05-03 10:31:12 +00:00
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
2012-02-01 21:59:26 +00:00
|
|
|
|
disable: function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
|
|
|
|
|
equal( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
|
|
|
|
|
equal( ui.index, 1, "ui.index" );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-05-03 10:31:12 +00:00
|
|
|
|
element.tabs( "disable", 1 );
|
|
|
|
|
// shouldn't trigger event
|
|
|
|
|
element.tabs( "disable", 1 );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-27 20:55:05 +00:00
|
|
|
|
|
2011-05-10 17:56:59 +00:00
|
|
|
|
test( "show", function() {
|
|
|
|
|
expect( 13 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
|
active: false,
|
|
|
|
|
collapsible: true
|
|
|
|
|
}),
|
|
|
|
|
tabs = element.find( ".ui-tabs-nav a" ),
|
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
|
|
|
|
|
// from collapsed
|
|
|
|
|
element.one( "tabsshow", function( event, ui ) {
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
|
|
|
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
2011-05-10 18:04:50 +00:00
|
|
|
|
equal( ui.index, 0, "ui.index" );
|
2011-05-10 17:56:59 +00:00
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2011-03-27 20:55:05 +00:00
|
|
|
|
});
|
2011-05-10 17:56:59 +00:00
|
|
|
|
element.tabs( "option", "active", 0 );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2011-03-27 20:55:05 +00:00
|
|
|
|
|
2011-05-10 17:56:59 +00:00
|
|
|
|
// switching tabs
|
|
|
|
|
element.one( "tabsshow", function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( event.originalEvent.type, "click", "originalEvent" );
|
2011-05-10 17:56:59 +00:00
|
|
|
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
|
|
|
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
2011-05-10 18:04:50 +00:00
|
|
|
|
equal( ui.index, 1, "ui.index" );
|
2011-05-10 17:56:59 +00:00
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
|
|
|
|
});
|
|
|
|
|
tabs.eq( 1 ).click();
|
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-27 20:55:05 +00:00
|
|
|
|
|
2011-05-10 17:56:59 +00:00
|
|
|
|
// collapsing
|
|
|
|
|
element.one( "tabsshow", function( event, ui ) {
|
|
|
|
|
ok( false, "collapsing" );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2011-03-27 20:55:05 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-10 18:04:50 +00:00
|
|
|
|
test( "select", function() {
|
|
|
|
|
expect( 13 );
|
2011-03-27 21:02:58 +00:00
|
|
|
|
|
2011-05-10 18:04:50 +00:00
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
|
|
|
|
active: false,
|
|
|
|
|
collapsible: true
|
|
|
|
|
}),
|
|
|
|
|
tabs = element.find( ".ui-tabs-nav a" ),
|
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
|
|
|
|
|
// from collapsed
|
|
|
|
|
element.one( "tabsselect", function( event, ui ) {
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
|
|
|
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
|
|
|
|
equal( ui.index, 0, "ui.index" );
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 0 );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
|
|
|
|
|
// switching tabs
|
|
|
|
|
element.one( "tabsselect", function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( event.originalEvent.type, "click", "originalEvent" );
|
2011-05-10 18:04:50 +00:00
|
|
|
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
|
|
|
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
|
|
|
|
equal( ui.index, 1, "ui.index" );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2011-03-27 21:02:58 +00:00
|
|
|
|
});
|
2011-05-10 18:04:50 +00:00
|
|
|
|
tabs.eq( 1 ).click();
|
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-27 21:02:58 +00:00
|
|
|
|
|
2011-05-10 18:04:50 +00:00
|
|
|
|
// collapsing
|
|
|
|
|
element.one( "tabsselect", function( event, ui ) {
|
|
|
|
|
ok( false, "collapsing" );
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2011-03-27 21:02:58 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-04-29 01:35:04 +00:00
|
|
|
|
module( "tabs (deprecated): methods" );
|
|
|
|
|
|
|
|
|
|
test( "add", function() {
|
2011-04-29 02:12:59 +00:00
|
|
|
|
expect( 27 );
|
2011-04-29 01:35:04 +00:00
|
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var tab, anchor,
|
|
|
|
|
element = $( "#tabs1" ).tabs();
|
2011-04-29 01:35:04 +00:00
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
|
|
|
|
|
// add without index
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsadd", function( event, ui ) {
|
|
|
|
|
equal( ui.index, 3, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "New", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, "new", "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "add", "#new", "New" );
|
|
|
|
|
tabs_state( element, 1, 0, 0, 0 );
|
2012-04-19 02:36:15 +00:00
|
|
|
|
tab = element.find( ".ui-tabs-nav li" ).last();
|
|
|
|
|
anchor = tab.find( "a" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( tab.text(), "New", "label" );
|
|
|
|
|
equal( anchor.attr( "href" ), "#new", "href" );
|
|
|
|
|
equal( anchor.attr( "aria-controls" ), "new", "aria-controls" );
|
2011-04-29 01:35:04 +00:00
|
|
|
|
ok( !tab.hasClass( "ui-state-hover" ), "not hovered" );
|
|
|
|
|
anchor.simulate( "mouseover" );
|
|
|
|
|
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
|
|
|
|
anchor.simulate( "click" );
|
|
|
|
|
tabs_state( element, 0, 0, 0, 1 );
|
|
|
|
|
|
|
|
|
|
// add remote tab with index
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsadd", function( event, ui ) {
|
|
|
|
|
equal( ui.index, 1, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "New Remote", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "add", "data/test.html", "New Remote", 1 );
|
|
|
|
|
tabs_state( element, 0, 0, 0, 0, 1 );
|
|
|
|
|
tab = element.find( ".ui-tabs-nav li" ).eq( 1 );
|
|
|
|
|
anchor = tab.find( "a" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( tab.text(), "New Remote", "label" );
|
|
|
|
|
equal( anchor.attr( "href" ), "data/test.html", "href" );
|
2011-04-29 01:35:04 +00:00
|
|
|
|
ok( /^ui-tabs-\d+$/.test( anchor.attr( "aria-controls" ) ), "aria controls" );
|
|
|
|
|
ok( !tab.hasClass( "ui-state-hover" ), "not hovered" );
|
|
|
|
|
anchor.simulate( "mouseover" );
|
|
|
|
|
ok( tab.hasClass( "ui-state-hover" ), "hovered" );
|
|
|
|
|
anchor.simulate( "click" );
|
|
|
|
|
tabs_state( element, 0, 1, 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
// add to empty tab set
|
|
|
|
|
element = $( "<div><ul></ul></div>" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), false, "active: false on init" );
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsadd", function( event, ui ) {
|
|
|
|
|
equal( ui.index, 0, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "First", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, "first", "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "add", "#first", "First" );
|
|
|
|
|
tabs_state( element, 1 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 0, "active: 0 after add" );
|
2011-04-29 01:35:04 +00:00
|
|
|
|
});
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 01:35:04 +00:00
|
|
|
|
test( "#5069 - ui.tabs.add creates two tab panels when using a full URL", function() {
|
|
|
|
|
expect( 2 );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 01:35:04 +00:00
|
|
|
|
var element = $( "#tabs2" ).tabs();
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length );
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "add", "/new", "New" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-04-29 01:35:04 +00:00
|
|
|
|
test( "remove", function() {
|
2011-04-29 02:12:59 +00:00
|
|
|
|
expect( 17 );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 01:35:04 +00:00
|
|
|
|
var element = $( "#tabs1" ).tabs({ active: 1 });
|
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsremove", function( event, ui ) {
|
|
|
|
|
equal( ui.index, -1, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "2", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, "fragment-2", "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "remove", 1 );
|
|
|
|
|
tabs_state( element, 0, 1 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 1 );
|
|
|
|
|
equal( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0,
|
2011-04-29 01:35:04 +00:00
|
|
|
|
"remove correct list item" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.find( "#fragment-2" ).length, 0, "remove correct panel" );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsremove", function( event, ui ) {
|
|
|
|
|
equal( ui.index, -1, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "3", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, "fragment-3", "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "remove", 1 );
|
|
|
|
|
tabs_state( element, 1 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active"), 0 );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2011-04-29 02:12:59 +00:00
|
|
|
|
element.one( "tabsremove", function( event, ui ) {
|
|
|
|
|
equal( ui.index, -1, "ui.index" );
|
|
|
|
|
equal( $( ui.tab ).text(), "1", "ui.tab" );
|
|
|
|
|
equal( ui.panel.id, "fragment-1", "ui.panel" );
|
|
|
|
|
});
|
2011-04-29 01:35:04 +00:00
|
|
|
|
element.tabs( "remove", 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), false );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
test( "select", function() {
|
|
|
|
|
expect( 23 );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
var element = $( "#tabs1" ).tabs();
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
element.tabs( "select", 1 );
|
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 1, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs({ collapsible: true });
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
element.tabs( "select", 0 );
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), false, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs({ collapsible: true });
|
|
|
|
|
element.tabs( "select", -1 );
|
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), false, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), -1, "selected" );
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "destroy" );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs();
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "select", 0 );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "select", -1 );
|
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 0, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 0, "selected" );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
2011-05-03 11:48:08 +00:00
|
|
|
|
element.tabs( "select", "#fragment-2" );
|
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( element.tabs( "option", "active" ), 1, "active" );
|
|
|
|
|
equal( element.tabs( "option", "selected" ), 1, "selected" );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-04-06 00:07:27 +00:00
|
|
|
|
test( "length", function() {
|
|
|
|
|
expect( 2 );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( $( "#tabs1" ).tabs().tabs( "length" ), 3, "basic tabs" );
|
|
|
|
|
equal( $( "#tabs2" ).tabs().tabs( "length" ), 5, "ajax tabs with missing panels" );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-04-06 01:39:02 +00:00
|
|
|
|
test( "url", function() {
|
|
|
|
|
expect( 2 );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
|
2011-04-06 01:39:02 +00:00
|
|
|
|
var element = $( "#tabs2" ).tabs(),
|
|
|
|
|
tab = element.find( "a" ).eq( 3 );
|
|
|
|
|
|
|
|
|
|
element.tabs( "url", 3, "data/test2.html" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( tab.attr( "href" ), "data/test2.html", "href was updated" );
|
2011-04-06 01:39:02 +00:00
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( ui.ajaxSettings.url, "data/test2.html", "ajaxSettings.url" );
|
2011-04-06 01:39:02 +00:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 3 );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-09 20:54:51 +00:00
|
|
|
|
asyncTest( "abort", function() {
|
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs();
|
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
|
ui.jqXHR.error(function( jqXHR, status ) {
|
2012-02-28 14:56:32 +00:00
|
|
|
|
equal( status, "abort", "aborted" );
|
2011-05-09 20:54:51 +00:00
|
|
|
|
start();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
element.tabs( "option", "active", 2 );
|
|
|
|
|
element.tabs( "abort" );
|
2011-05-09 18:45:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
|
}( jQuery ) );
|