2011-04-15 12:53:05 +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-15 12:53:05 +00:00
|
|
|
module( "tabs: methods" );
|
2010-09-29 17:32:43 +00:00
|
|
|
|
2011-05-09 21:41:43 +00:00
|
|
|
test( "destroy", function() {
|
|
|
|
domEqual( "#tabs1", function() {
|
|
|
|
$( "#tabs1" ).tabs().tabs( "destroy" );
|
|
|
|
});
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-04-28 16:04:08 +00:00
|
|
|
test( "enable", function() {
|
|
|
|
expect( 8 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({ disabled: true });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "enable" );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
|
|
|
element.tabs({ disabled: [ 0, 1 ] });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0, 1 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "enable" );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-04-28 16:04:08 +00:00
|
|
|
});
|
2011-04-18 01:09:47 +00:00
|
|
|
|
2011-04-28 16:04:08 +00:00
|
|
|
test( "enable( index )", function() {
|
|
|
|
expect( 10 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({ disabled: true });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2011-04-28 16:04:08 +00:00
|
|
|
// fully disabled -> partially disabled
|
|
|
|
element.tabs( "enable", 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0, 2 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// partially disabled -> partially disabled
|
|
|
|
element.tabs( "enable", 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// already enabled tab, no change
|
|
|
|
element.tabs( "enable", 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// partially disabled -> fully enabled
|
|
|
|
element.tabs( "enable", 0 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-04-28 16:04:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test( "disable", function() {
|
|
|
|
expect( 8 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({ disabled: false });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "disable" );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "destroy" );
|
|
|
|
|
|
|
|
element.tabs({ disabled: [ 0, 1 ] });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 0, 1 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
element.tabs( "disable" );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-04-28 16:04:08 +00:00
|
|
|
test( "disable( index )", function() {
|
|
|
|
expect( 10 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({ disabled: false });
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, false );
|
2011-04-28 16:04:08 +00:00
|
|
|
// fully enabled -> partially disabled
|
|
|
|
element.tabs( "disable", 1 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 1 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// partially disabled -> partially disabled
|
|
|
|
element.tabs( "disable", 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 1, 2 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// already disabled tab, no change
|
|
|
|
element.tabs( "disable", 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, [ 1, 2 ] );
|
2011-04-28 16:04:08 +00:00
|
|
|
// partially disabled -> fully disabled
|
|
|
|
element.tabs( "disable", 0 );
|
2012-04-19 16:53:06 +00:00
|
|
|
disabled( element, true );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-05-03 11:14:33 +00:00
|
|
|
test( "refresh", function() {
|
2011-04-28 18:38:57 +00:00
|
|
|
expect( 27 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs();
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
|
|
|
disabled( element, false );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// disable tab via markup
|
|
|
|
element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" );
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0 );
|
|
|
|
disabled( element, [ 1 ] );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// add remote tab
|
|
|
|
element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" );
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0, 0 );
|
|
|
|
disabled( element, [ 1 ] );
|
2012-05-18 20:11:14 +00:00
|
|
|
equal( element.find( "#" + $( "#newTab" ).attr( "aria-controls" ) ).length, 1,
|
2011-04-28 18:38:57 +00:00
|
|
|
"panel added for remote tab" );
|
|
|
|
|
|
|
|
// remove all tabs
|
|
|
|
element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove();
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( element.tabs( "option", "active" ), false, "no active tab" );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// add tabs
|
|
|
|
element.find( ".ui-tabs-nav" )
|
|
|
|
.append( "<li class='ui-state-disabled'><a href='#newTab2'>new 2</a></li>" )
|
|
|
|
.append( "<li><a href='#newTab3'>new 3</a></li>" )
|
|
|
|
.append( "<li><a href='#newTab4'>new 4</a></li>" )
|
|
|
|
.append( "<li><a href='#newTab5'>new 5</a></li>" );
|
|
|
|
element
|
|
|
|
.append( "<div id='newTab2'>new 2</div>" )
|
|
|
|
.append( "<div id='newTab3'>new 3</div>" )
|
|
|
|
.append( "<div id='newTab4'>new 4</div>" )
|
|
|
|
.append( "<div id='newTab5'>new 5</div>" );
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0, 0 );
|
|
|
|
disabled( element, [ 0 ] );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// activate third tab
|
|
|
|
element.tabs( "option", "active", 2 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1, 0 );
|
|
|
|
disabled( element, [ 0 ] );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// remove fourth tab, third tab should stay active
|
|
|
|
element.find( ".ui-tabs-nav li" ).eq( 3 ).remove();
|
|
|
|
element.find( ".ui-tabs-panel" ).eq( 3 ).remove();
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 1 );
|
|
|
|
disabled( element, [ 0 ] );
|
2011-04-28 18:38:57 +00:00
|
|
|
|
|
|
|
// remove third (active) tab, second tab should become active
|
|
|
|
element.find( ".ui-tabs-nav li" ).eq( 2 ).remove();
|
|
|
|
element.find( ".ui-tabs-panel" ).eq( 2 ).remove();
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 1 );
|
|
|
|
disabled( element, [ 0 ] );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2011-04-28 18:38:57 +00:00
|
|
|
// remove first tab, previously active tab (now first) should stay active
|
|
|
|
element.find( ".ui-tabs-nav li" ).eq( 0 ).remove();
|
|
|
|
element.find( ".ui-tabs-panel" ).eq( 0 ).remove();
|
|
|
|
element.tabs( "refresh" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1 );
|
|
|
|
disabled( element, false );
|
2011-03-27 00:37:26 +00:00
|
|
|
});
|
|
|
|
|
2011-05-16 18:41:27 +00:00
|
|
|
asyncTest( "load", function() {
|
|
|
|
expect( 30 );
|
|
|
|
|
|
|
|
var element = $( "#tabs2" ).tabs();
|
|
|
|
|
|
|
|
// load content of inactive tab
|
|
|
|
// useful for preloading content with custom caching
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
2012-05-18 20:11:14 +00:00
|
|
|
var tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
|
2011-05-16 18:41:27 +00:00
|
|
|
panelId = tab.attr( "aria-controls" ),
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.tab.length, 1, "tab length" );
|
2011-05-16 18:41:27 +00:00
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.panel.length, 1, "panel length" );
|
2011-05-16 18:41:27 +00:00
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0, 0, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
});
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
2011-05-17 19:46:41 +00:00
|
|
|
// TODO: remove wrapping in 2.0
|
|
|
|
var uiTab = $( ui.tab ),
|
2012-04-19 02:36:15 +00:00
|
|
|
uiPanel = $( ui.panel ),
|
2012-05-18 20:11:14 +00:00
|
|
|
tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
|
2011-05-16 18:41:27 +00:00
|
|
|
panelId = tab.attr( "aria-controls" ),
|
|
|
|
panel = $( "#" + panelId );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2011-05-16 18:41:27 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( uiTab.length, 1, "tab length" );
|
2012-05-18 20:11:14 +00:00
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
} else {
|
|
|
|
strictEqual( uiTab[ 0 ], tab.find( ".ui-tabs-anchor" )[ 0 ], "tab" );
|
|
|
|
}
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( uiPanel.length, 1, "panel length" );
|
2011-05-17 19:46:41 +00:00
|
|
|
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
2012-02-28 14:56:32 +00:00
|
|
|
equal( uiPanel.find( "p" ).length, 1, "panel html" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0, 0, 0 );
|
2011-11-02 13:35:20 +00:00
|
|
|
setTimeout( tabsload1, 100 );
|
2011-05-16 18:41:27 +00:00
|
|
|
});
|
|
|
|
element.tabs( "load", 3 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 1, 0, 0, 0, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
|
|
|
|
function tabsload1() {
|
|
|
|
// no need to test details of event (tested in events tests)
|
|
|
|
element.one( "tabsbeforeload", function() {
|
|
|
|
ok( true, "tabsbeforeload invoked" );
|
|
|
|
});
|
|
|
|
element.one( "tabsload", function() {
|
|
|
|
ok( true, "tabsload invoked" );
|
2011-11-02 13:35:20 +00:00
|
|
|
setTimeout( tabsload2, 100 );
|
2011-05-16 18:41:27 +00:00
|
|
|
});
|
|
|
|
element.tabs( "option", "active", 3 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0, 1, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function tabsload2() {
|
|
|
|
// reload content of active tab
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
2012-05-18 20:11:14 +00:00
|
|
|
var tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
|
2011-05-16 18:41:27 +00:00
|
|
|
panelId = tab.attr( "aria-controls" ),
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.tab.length, 1, "tab length" );
|
2011-05-16 18:41:27 +00:00
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.panel.length, 1, "panel length" );
|
2011-05-16 18:41:27 +00:00
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0, 1, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
});
|
|
|
|
element.one( "tabsload", function( event, ui ) {
|
2011-05-17 19:46:41 +00:00
|
|
|
// TODO: remove wrapping in 2.0
|
|
|
|
var uiTab = $( ui.tab ),
|
2012-04-19 02:36:15 +00:00
|
|
|
uiPanel = $( ui.panel ),
|
2012-05-18 20:11:14 +00:00
|
|
|
tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
|
2011-05-16 18:41:27 +00:00
|
|
|
panelId = tab.attr( "aria-controls" ),
|
|
|
|
panel = $( "#" + panelId );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2011-05-16 18:41:27 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( uiTab.length, 1, "tab length" );
|
2012-05-18 20:11:14 +00:00
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
} else {
|
|
|
|
strictEqual( uiTab[ 0 ], tab.find( ".ui-tabs-anchor" )[ 0 ], "tab" );
|
|
|
|
}
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( uiPanel.length, 1, "panel length" );
|
2011-05-17 19:46:41 +00:00
|
|
|
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0, 1, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
start();
|
|
|
|
});
|
|
|
|
element.tabs( "load", 3 );
|
2012-04-19 16:53:06 +00:00
|
|
|
state( element, 0, 0, 0, 1, 0 );
|
2011-05-16 18:41:27 +00:00
|
|
|
}
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-04-15 12:53:05 +00:00
|
|
|
}( jQuery ) );
|