2011-04-04 15:22:32 +00:00
|
|
|
(function( $ ) {
|
|
|
|
|
|
|
|
module( "tabs: events" );
|
|
|
|
|
|
|
|
test( "beforeActivate", function() {
|
2011-04-04 18:27:38 +00:00
|
|
|
expect( 38 );
|
2011-04-04 15:22:32 +00:00
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
2011-04-05 20:53:52 +00:00
|
|
|
active: false,
|
2011-04-04 15:22:32 +00:00
|
|
|
collapsible: true
|
|
|
|
}),
|
|
|
|
tabs = element.find( ".ui-tabs-nav a" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
2011-04-04 18:27:38 +00:00
|
|
|
// from collapsed
|
2011-04-04 15:22:32 +00:00
|
|
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 0, "oldTab size" );
|
|
|
|
equals( ui.oldPanel.size(), 0, "oldPanel size" );
|
|
|
|
equals( ui.newTab.size(), 1, "newTab size" );
|
|
|
|
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
|
|
|
equals( ui.newPanel.size(), 1, "newPanel size" );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
2011-04-04 15:22:32 +00:00
|
|
|
tabs_state( element, 0, 0, 0 );
|
2010-07-21 00:51:09 +00:00
|
|
|
});
|
2011-04-04 15:22:32 +00:00
|
|
|
element.tabs( "option", "active", 0 );
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
2011-02-08 00:32:32 +00:00
|
|
|
|
2011-04-04 18:27:38 +00:00
|
|
|
// switching tabs
|
2011-04-04 15:22:32 +00:00
|
|
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 1, "oldTab size" );
|
|
|
|
strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" );
|
|
|
|
equals( ui.oldPanel.size(), 1, "oldPanel size" );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" );
|
|
|
|
equals( ui.newTab.size(), 1, "newTab size" );
|
|
|
|
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
|
|
|
equals( ui.newPanel.size(), 1, "newPanel size" );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
2011-04-04 15:22:32 +00:00
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
});
|
2011-04-04 18:27:38 +00:00
|
|
|
tabs.eq( 1 ).click();
|
2011-04-04 15:22:32 +00:00
|
|
|
tabs_state( element, 0, 1, 0 );
|
|
|
|
|
2011-04-04 18:27:38 +00:00
|
|
|
// collapsing
|
2011-04-04 15:22:32 +00:00
|
|
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 1, "oldTab size" );
|
|
|
|
strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" );
|
|
|
|
equals( ui.oldPanel.size(), 1, "oldPanel size" );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
|
|
|
equals( ui.newTab.size(), 0, "newTab size" );
|
|
|
|
equals( ui.newPanel.size(), 0, "newPanel size" );
|
2011-04-04 15:22:32 +00:00
|
|
|
tabs_state( element, 0, 1, 0 );
|
2011-03-29 02:28:59 +00:00
|
|
|
});
|
2011-04-04 15:22:32 +00:00
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2011-04-04 18:27:38 +00:00
|
|
|
|
|
|
|
// prevent activation
|
|
|
|
element.one( "tabsbeforeactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 0, "oldTab size" );
|
|
|
|
equals( ui.oldPanel.size(), 0, "oldTab" );
|
|
|
|
equals( ui.newTab.size(), 1, "newTab size" );
|
|
|
|
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
|
|
|
equals( ui.newPanel.size(), 1, "newPanel size" );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
2011-04-04 18:27:38 +00:00
|
|
|
event.preventDefault();
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
|
|
|
});
|
|
|
|
element.tabs( "option", "active", 1 );
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
2009-02-03 13:37:54 +00:00
|
|
|
});
|
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
test( "activate", function() {
|
|
|
|
expect( 30 );
|
|
|
|
|
|
|
|
var element = $( "#tabs1" ).tabs({
|
2011-04-05 20:53:52 +00:00
|
|
|
active: false,
|
2011-04-04 19:28:33 +00:00
|
|
|
collapsible: true
|
|
|
|
}),
|
|
|
|
tabs = element.find( ".ui-tabs-nav a" ),
|
|
|
|
panels = element.find( ".ui-tabs-panel" );
|
|
|
|
|
|
|
|
// from collapsed
|
|
|
|
element.one( "tabsactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 0, "oldTab size" );
|
|
|
|
equals( ui.oldPanel.size(), 0, "oldPanel size" );
|
|
|
|
equals( ui.newTab.size(), 1, "newTab size" );
|
|
|
|
strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" );
|
|
|
|
equals( ui.newPanel.size(), 1, "newPanel size" );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
|
2011-04-04 19:28:33 +00:00
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
});
|
|
|
|
element.tabs( "option", "active", 0 );
|
|
|
|
tabs_state( element, 1, 0, 0 );
|
|
|
|
|
|
|
|
// switching tabs
|
|
|
|
element.one( "tabsactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 1, "oldTab size" );
|
|
|
|
strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" );
|
|
|
|
equals( ui.oldPanel.size(), 1, "oldPanel size" );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" );
|
|
|
|
equals( ui.newTab.size(), 1, "newTab size" );
|
|
|
|
strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" );
|
|
|
|
equals( ui.newPanel.size(), 1, "newPanel size" );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
|
2011-04-04 19:28:33 +00:00
|
|
|
tabs_state( element, 0, 1, 0 );
|
|
|
|
});
|
|
|
|
tabs.eq( 1 ).click();
|
|
|
|
tabs_state( element, 0, 1, 0 );
|
|
|
|
|
|
|
|
// collapsing
|
|
|
|
element.one( "tabsactivate", function( event, ui ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.oldTab.size(), 1, "oldTab size" );
|
|
|
|
strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" );
|
|
|
|
equals( ui.oldPanel.size(), 1, "oldPanel size" );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" );
|
|
|
|
equals( ui.newTab.size(), 0, "newTab size" );
|
|
|
|
equals( ui.newPanel.size(), 0, "newPanel size" );
|
2011-04-04 19:28:33 +00:00
|
|
|
tabs_state( element, 0, 0, 0 );
|
|
|
|
});
|
|
|
|
element.tabs( "option", "active", false );
|
|
|
|
tabs_state( element, 0, 0, 0 );
|
|
|
|
|
|
|
|
// prevent activation
|
|
|
|
element.one( "tabsbeforeactivate", function( event ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( true, "tabsbeforeactivate" );
|
2011-04-04 19:28:33 +00:00
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
element.one( "tabsactivate", function() {
|
2011-04-05 20:53:52 +00:00
|
|
|
ok( false, "tabsactivate" );
|
2011-04-04 19:28:33 +00:00
|
|
|
});
|
|
|
|
element.tabs( "option", "active", 1 );
|
|
|
|
});
|
|
|
|
|
2011-04-04 21:06:13 +00:00
|
|
|
test( "beforeLoad", function() {
|
2011-05-09 21:38:34 +00:00
|
|
|
expect( 32 );
|
2011-04-05 15:28:05 +00:00
|
|
|
|
|
|
|
var tab, panelId, panel,
|
2011-05-09 21:38:34 +00:00
|
|
|
element = $( "#tabs2" );
|
2011-04-05 15:28:05 +00:00
|
|
|
|
2011-05-09 21:38:34 +00:00
|
|
|
// init
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
ok( "abort" in ui.jqXHR, "jqXHR" );
|
|
|
|
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
equals( ui.panel.html(), "", "panel html" );
|
|
|
|
event.preventDefault();
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
|
|
|
});
|
|
|
|
element.tabs({ active: 2 });
|
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
|
|
|
equals( panel.html(), "", "panel html after" );
|
|
|
|
element.tabs( "destroy" );
|
2011-04-05 15:28:05 +00:00
|
|
|
|
|
|
|
// .option()
|
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
ok( "abort" in ui.jqXHR, "jqXHR" );
|
|
|
|
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
equals( ui.panel.html(), "", "panel html" );
|
|
|
|
event.preventDefault();
|
2011-04-07 17:53:20 +00:00
|
|
|
tabs_state( element, 1, 0, 0, 0, 0 );
|
2011-04-05 15:28:05 +00:00
|
|
|
});
|
2011-05-09 21:38:34 +00:00
|
|
|
element.tabs();
|
2011-04-05 15:28:05 +00:00
|
|
|
element.tabs( "option", "active", 2 );
|
2011-04-07 17:53:20 +00:00
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
2011-04-05 15:28:05 +00:00
|
|
|
equals( panel.html(), "", "panel html after" );
|
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
// click, change panel content
|
2011-04-05 15:28:05 +00:00
|
|
|
element.one( "tabsbeforeload", function( event, ui ) {
|
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
|
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
panel = $( "#" + panelId );
|
|
|
|
|
|
|
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
|
|
|
ok( "abort" in ui.jqXHR, "jqXHR" );
|
|
|
|
ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
ui.panel.html( "<p>testing</p>" );
|
|
|
|
event.preventDefault();
|
2011-04-07 17:53:20 +00:00
|
|
|
tabs_state( element, 0, 0, 1, 0, 0 );
|
2011-03-26 19:00:39 +00:00
|
|
|
});
|
2011-04-05 15:28:05 +00:00
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 3 ).click();
|
2011-04-07 17:53:20 +00:00
|
|
|
tabs_state( element, 0, 0, 0, 1, 0 );
|
2011-04-05 15:28:05 +00:00
|
|
|
equals( panel.html(), "<p>testing</p>", "panel html after" );
|
2011-03-26 19:00:39 +00:00
|
|
|
});
|
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
asyncTest( "load", function() {
|
|
|
|
expect( 21 );
|
2011-05-09 19:42:24 +00:00
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
var tab, panelId, panel,
|
|
|
|
element = $( "#tabs2" );
|
2011-05-09 19:42:24 +00:00
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
// init
|
2011-05-09 19:42:24 +00:00
|
|
|
element.one( "tabsload", function( event, ui ) {
|
2011-05-17 19:46:41 +00:00
|
|
|
tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
|
2011-05-09 19:42:24 +00:00
|
|
|
panelId = tab.attr( "aria-controls" );
|
|
|
|
panel = $( "#" + panelId );
|
2011-05-17 19:46:41 +00:00
|
|
|
|
2011-05-09 19:42:24 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
equals( 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();
|
2011-05-09 19:42:24 +00:00
|
|
|
});
|
2011-05-17 19:46:41 +00:00
|
|
|
element.tabs({ active: 2 });
|
2011-05-09 19:42:24 +00:00
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
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 );
|
2011-05-09 19:42:24 +00:00
|
|
|
|
2011-05-17 19:46:41 +00:00
|
|
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
equals( ui.panel.find( "p" ).length, 1, "panel html" );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
|
|
|
equals( ui.tab.size(), 1, "tab size" );
|
|
|
|
strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
|
|
|
|
equals( ui.panel.size(), 1, "panel size" );
|
|
|
|
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
|
|
|
|
equals( ui.panel.find( "p" ).length, 1, "panel html" );
|
|
|
|
tabs_state( element, 0, 0, 0, 0, 1 );
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-02-03 13:37:54 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
}( jQuery ) );
|