Tabs: Style updates

Ref #14246
This commit is contained in:
Alexander Schmitz 2015-08-24 08:57:25 -04:00
parent a0892eca70
commit 6c0bb24918
7 changed files with 202 additions and 164 deletions

View File

@ -26,6 +26,6 @@ common.testWidget( "tabs", {
create: null, create: null,
load: null load: null
} }
}); } );
} ); } );

View File

@ -40,9 +40,9 @@ test( "markup structure", function( assert ) {
assert.hasClasses( panels[ 1 ], "ui-tabs-panel ui-widget-content" ); assert.hasClasses( panels[ 1 ], "ui-tabs-panel ui-widget-content" );
assert.hasClasses( panels[ 2 ], "ui-tabs-panel ui-widget-content" ); assert.hasClasses( panels[ 2 ], "ui-tabs-panel ui-widget-content" );
equal( panels.length, 3, "There are exactly 3 tab panels" ); equal( panels.length, 3, "There are exactly 3 tab panels" );
}); } );
$.each({ $.each( {
"deep ul": "#tabs3", "deep ul": "#tabs3",
"multiple lists, ul first": "#tabs4", "multiple lists, ul first": "#tabs4",
"multiple lists, ol first": "#tabs5", "multiple lists, ol first": "#tabs5",
@ -53,8 +53,8 @@ $.each({
var element = $( selector ).tabs(); var element = $( selector ).tabs();
assert.hasClasses( element, "ui-tabs" ); assert.hasClasses( element, "ui-tabs" );
assert.hasClasses( $( selector + "-list" ), "ui-tabs-nav" ); assert.hasClasses( $( selector + "-list" ), "ui-tabs-nav" );
}); } );
}); } );
// #5893 - Sublist in the tab list are considered as tab // #5893 - Sublist in the tab list are considered as tab
test( "nested list", function() { test( "nested list", function() {
@ -62,7 +62,7 @@ test( "nested list", function() {
var element = $( "#tabs6" ).tabs(); var element = $( "#tabs6" ).tabs();
equal( element.tabs( "instance" ).anchors.length, 2, "should contain 2 tab" ); equal( element.tabs( "instance" ).anchors.length, 2, "should contain 2 tab" );
}); } );
test( "disconnected from DOM", function() { test( "disconnected from DOM", function() {
expect( 2 ); expect( 2 );
@ -70,7 +70,7 @@ test( "disconnected from DOM", function() {
var element = $( "#tabs1" ).remove().tabs(); var element = $( "#tabs1" ).remove().tabs();
equal( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" ); equal( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" );
equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" ); equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" );
}); } );
test( "non-tab list items", function() { test( "non-tab list items", function() {
expect( 2 ); expect( 2 );
@ -79,17 +79,17 @@ test( "non-tab list items", function() {
equal( element.tabs( "option", "active" ), 0, "defaults to first tab" ); equal( element.tabs( "option", "active" ), 0, "defaults to first tab" );
equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1, equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1,
"first actual tab is active" ); "first actual tab is active" );
}); } );
test( "aria-controls", function() { test( "aria-controls", function() {
expect( 7 ); expect( 7 );
var element = $( "#tabs1" ).tabs(), var element = $( "#tabs1" ).tabs(),
tabs = element.find( ".ui-tabs-nav li" ); tabs = element.find( ".ui-tabs-nav li" );
tabs.each(function() { tabs.each( function() {
var tab = $( this ), var tab = $( this ),
anchor = tab.find( ".ui-tabs-anchor" ); anchor = tab.find( ".ui-tabs-anchor" );
equal( anchor.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) ); equal( anchor.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) );
}); } );
element = $( "#tabs2" ).tabs(); element = $( "#tabs2" ).tabs();
tabs = element.find( ".ui-tabs-nav li" ); tabs = element.find( ".ui-tabs-nav li" );
@ -97,20 +97,20 @@ test( "aria-controls", function() {
equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" ); equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" );
ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" ); ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" );
equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" ); equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" );
}); } );
test( "accessibility", function() { test( "accessibility", function() {
expect( 49 ); expect( 49 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: 1, active: 1,
disabled: [ 2 ] disabled: [ 2 ]
}), } ),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
anchors = tabs.find( ".ui-tabs-anchor" ), anchors = tabs.find( ".ui-tabs-anchor" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
equal( element.find( ".ui-tabs-nav" ).attr( "role" ), "tablist", "tablist role" ); equal( element.find( ".ui-tabs-nav" ).attr( "role" ), "tablist", "tablist role" );
tabs.each(function( index ) { tabs.each( function( index ) {
var tab = tabs.eq( index ), var tab = tabs.eq( index ),
anchor = anchors.eq( index ), anchor = anchors.eq( index ),
anchorId = anchor.attr( "id" ), anchorId = anchor.attr( "id" ),
@ -121,7 +121,7 @@ test( "accessibility", function() {
equal( anchor.attr( "tabindex" ), -1, "anchor " + index + " tabindex" ); equal( anchor.attr( "tabindex" ), -1, "anchor " + index + " tabindex" );
equal( panel.attr( "role" ), "tabpanel", "panel " + index + " role" ); equal( panel.attr( "role" ), "tabpanel", "panel " + index + " role" );
equal( panel.attr( "aria-labelledby" ), anchorId, "panel " + index + " aria-labelledby" ); equal( panel.attr( "aria-labelledby" ), anchorId, "panel " + index + " aria-labelledby" );
}); } );
equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" ); equal( tabs.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected=true" );
equal( tabs.eq( 1 ).attr( "tabindex" ), 0, "active tab has tabindex=0" ); equal( tabs.eq( 1 ).attr( "tabindex" ), 0, "active tab has tabindex=0" );
@ -155,7 +155,7 @@ test( "accessibility", function() {
equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" ); equal( tabs.eq( 2 ).attr( "aria-disabled" ), "true", "disabled tab has aria-disabled=true" );
equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" ); equal( tabs.eq( 2 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded=false" );
equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" ); equal( panels.eq( 2 ).attr( "aria-hidden" ), "true", "inactive panel has aria-hidden=true" );
}); } );
asyncTest( "accessibility - ajax", function( assert ) { asyncTest( "accessibility - ajax", function( assert ) {
expect( 6 ); expect( 6 );
@ -169,19 +169,19 @@ asyncTest( "accessibility - ajax", function( assert ) {
assert.hasClasses( tab, "ui-tabs-loading" ); assert.hasClasses( tab, "ui-tabs-loading" );
equal( panel.attr( "aria-busy" ), "true", "panel has aria-busy during load" ); equal( panel.attr( "aria-busy" ), "true", "panel has aria-busy during load" );
element.one( "tabsload", function() { element.one( "tabsload", function() {
setTimeout(function() { setTimeout( function() {
equal( panel.attr( "aria-busy" ), null, "panel does not have aria-busy after load" ); equal( panel.attr( "aria-busy" ), null, "panel does not have aria-busy after load" );
assert.lacksClasses( tab, "ui-tabs-loading" ); assert.lacksClasses( tab, "ui-tabs-loading" );
start(); start();
}, 1 ); }, 1 );
}); } );
}); } );
asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER", function( assert ) { asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER", function( assert ) {
expect( 92 ); expect( 92 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
collapsible: true collapsible: true
}), } ),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
panels = element.find( ".ui-tabs-panel" ), panels = element.find( ".ui-tabs-panel" ),
keyCode = $.ui.keyCode; keyCode = $.ui.keyCode;
@ -328,10 +328,10 @@ asyncTest( "keyboard support - LEFT, RIGHT, UP, DOWN, HOME, END, SPACE, ENTER",
} }
setTimeout( step1 ); setTimeout( step1 );
}); } );
// Navigation with CTRL and COMMAND (both behave the same) // Navigation with CTRL and COMMAND (both behave the same)
$.each({ $.each( {
ctrl: "CTRL", ctrl: "CTRL",
meta: "COMMAND" meta: "COMMAND"
}, function( modifier, label ) { }, function( modifier, label ) {
@ -547,8 +547,8 @@ $.each({
} }
setTimeout( step1 ); setTimeout( step1 );
}); } );
}); } );
asyncTest( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( assert ) { asyncTest( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( assert ) {
expect( 50 ); expect( 50 );
@ -640,34 +640,34 @@ asyncTest( "keyboard support - CTRL+UP, ALT+PAGE_DOWN, ALT+PAGE_UP", function( a
} }
setTimeout( step1 ); setTimeout( step1 );
}); } );
test( "#3627 - Ajax tab with url containing a fragment identifier fails to load", function() { test( "#3627 - Ajax tab with url containing a fragment identifier fails to load", function() {
expect( 1 ); expect( 1 );
$( "#tabs2" ).tabs({ $( "#tabs2" ).tabs( {
active: 2, active: 2,
beforeLoad: function( event, ui ) { beforeLoad: function( event, ui ) {
event.preventDefault(); event.preventDefault();
ok( /test.html$/.test( ui.ajaxSettings.url ), "should ignore fragment identifier" ); ok( /test.html$/.test( ui.ajaxSettings.url ), "should ignore fragment identifier" );
} }
}); } );
}); } );
test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function() { test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function() {
expect( 2 ); expect( 2 );
var element = $("<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>"); var element = $( "<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>" );
element.appendTo("#qunit-fixture"); element.appendTo( "#qunit-fixture" );
element.tabs({ element.tabs( {
beforeLoad: function() { beforeLoad: function() {
event.preventDefault(); event.preventDefault();
ok( false, "should not be an ajax tab" ); ok( false, "should not be an ajax tab" );
} }
}); } );
equal( element.find(".ui-tabs-nav li").attr("aria-controls"), "tab", "aria-contorls attribute is correct" ); equal( element.find( ".ui-tabs-nav li" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" );
state( element, 1 ); state( element, 1 );
}); } );
} ); } );

View File

@ -15,17 +15,17 @@ test( "create", function() {
tabs = element.find( "ul li" ), tabs = element.find( "ul li" ),
panels = element.children( "div" ); panels = element.children( "div" );
element.tabs({ element.tabs( {
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 1, "tab length" ); equal( ui.tab.length, 1, "tab length" );
strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" ); strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" );
equal( ui.panel.length, 1, "panel length" ); equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" ); strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" );
} }
}); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs({ element.tabs( {
active: 2, active: 2,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 1, "tab length" ); equal( ui.tab.length, 1, "tab length" );
@ -33,27 +33,27 @@ test( "create", function() {
equal( ui.panel.length, 1, "panel length" ); equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" ); strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" );
} }
}); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs({ element.tabs( {
active: false, active: false,
collapsible: true, collapsible: true,
create: function( event, ui ) { create: function( event, ui ) {
equal( ui.tab.length, 0, "tab length" ); equal( ui.tab.length, 0, "tab length" );
equal( ui.panel.length, 0, "panel length" ); equal( ui.panel.length, 0, "panel length" );
} }
}); } );
element.tabs( "destroy" ); element.tabs( "destroy" );
}); } );
test( "beforeActivate", function() { test( "beforeActivate", function() {
expect( 38 ); expect( 38 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: false, active: false,
collapsible: true collapsible: true
}), } ),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
anchors = tabs.find( ".ui-tabs-anchor" ), anchors = tabs.find( ".ui-tabs-anchor" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
@ -68,7 +68,7 @@ test( "beforeActivate", function() {
equal( ui.newPanel.length, 1, "newPanel length" ); equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); } );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
@ -84,7 +84,7 @@ test( "beforeActivate", function() {
equal( ui.newPanel.length, 1, "newPanel length" ); equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
}); } );
anchors.eq( 1 ).trigger( "click" ); anchors.eq( 1 ).trigger( "click" );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
@ -98,7 +98,7 @@ test( "beforeActivate", function() {
equal( ui.newTab.length, 0, "newTab length" ); equal( ui.newTab.length, 0, "newTab length" );
equal( ui.newPanel.length, 0, "newPanel length" ); equal( ui.newPanel.length, 0, "newPanel length" );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
@ -113,18 +113,18 @@ test( "beforeActivate", function() {
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); } );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); } );
test( "activate", function() { test( "activate", function() {
expect( 30 ); expect( 30 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: false, active: false,
collapsible: true collapsible: true
}), } ),
tabs = element.find( ".ui-tabs-nav li" ), tabs = element.find( ".ui-tabs-nav li" ),
anchors = element.find( ".ui-tabs-anchor" ), anchors = element.find( ".ui-tabs-anchor" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
@ -139,7 +139,7 @@ test( "activate", function() {
equal( ui.newPanel.length, 1, "newPanel length" ); equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
}); } );
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
@ -155,7 +155,7 @@ test( "activate", function() {
equal( ui.newPanel.length, 1, "newPanel length" ); equal( ui.newPanel.length, 1, "newPanel length" );
strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
anchors.eq( 1 ).trigger( "click" ); anchors.eq( 1 ).trigger( "click" );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
@ -169,7 +169,7 @@ test( "activate", function() {
equal( ui.newTab.length, 0, "newTab length" ); equal( ui.newTab.length, 0, "newTab length" );
equal( ui.newPanel.length, 0, "newPanel length" ); equal( ui.newPanel.length, 0, "newPanel length" );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
@ -177,12 +177,12 @@ test( "activate", function() {
element.one( "tabsbeforeactivate", function( event ) { element.one( "tabsbeforeactivate", function( event ) {
ok( true, "tabsbeforeactivate" ); ok( true, "tabsbeforeactivate" );
event.preventDefault(); event.preventDefault();
}); } );
element.one( "tabsactivate", function() { element.one( "tabsactivate", function() {
ok( false, "tabsactivate" ); ok( false, "tabsactivate" );
}); } );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
}); } );
test( "beforeLoad", function() { test( "beforeLoad", function() {
expect( 32 ); expect( 32 );
@ -206,8 +206,8 @@ test( "beforeLoad", function() {
equal( ui.panel.html(), "", "panel html" ); equal( ui.panel.html(), "", "panel html" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 1, 0, 0 ); state( element, 0, 0, 1, 0, 0 );
}); } );
element.tabs({ active: 2 }); element.tabs( { active: 2 } );
state( element, 0, 0, 1, 0, 0 ); state( element, 0, 0, 1, 0, 0 );
equal( panel.html(), "", "panel html after" ); equal( panel.html(), "", "panel html after" );
element.tabs( "destroy" ); element.tabs( "destroy" );
@ -228,7 +228,7 @@ test( "beforeLoad", function() {
equal( ui.panel.html(), "", "panel html" ); equal( ui.panel.html(), "", "panel html" );
event.preventDefault(); event.preventDefault();
state( element, 1, 0, 0, 0, 0 ); state( element, 1, 0, 0, 0, 0 );
}); } );
element.tabs(); element.tabs();
element.tabs( "option", "active", 2 ); element.tabs( "option", "active", 2 );
state( element, 0, 0, 1, 0, 0 ); state( element, 0, 0, 1, 0, 0 );
@ -250,12 +250,13 @@ test( "beforeLoad", function() {
ui.panel.html( "<p>testing</p>" ); ui.panel.html( "<p>testing</p>" );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 1, 0, 0 ); state( element, 0, 0, 1, 0, 0 );
}); } );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 3 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 3 ).trigger( "click" );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
// .toLowerCase() is needed to convert <P> to <p> in old IEs // .toLowerCase() is needed to convert <P> to <p> in old IEs
equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" ); equal( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" );
}); } );
asyncTest( "load", function() { asyncTest( "load", function() {
expect( 21 ); expect( 21 );
@ -277,10 +278,11 @@ asyncTest( "load", function() {
equal( ui.panel.find( "p" ).length, 1, "panel html" ); equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 1, 0, 0 ); state( element, 0, 0, 1, 0, 0 );
tabsload1(); tabsload1();
}); } );
element.tabs({ active: 2 }); element.tabs( { active: 2 } );
function tabsload1() { function tabsload1() {
// .option() // .option()
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
tab = element.find( ".ui-tabs-nav li" ).eq( 3 ); tab = element.find( ".ui-tabs-nav li" ).eq( 3 );
@ -295,11 +297,12 @@ asyncTest( "load", function() {
equal( ui.panel.find( "p" ).length, 1, "panel html" ); equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
tabsload2(); tabsload2();
}); } );
element.tabs( "option", "active", 3 ); element.tabs( "option", "active", 3 );
} }
function tabsload2() { function tabsload2() {
// click, change panel content // click, change panel content
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
tab = element.find( ".ui-tabs-nav li" ).eq( 4 ); tab = element.find( ".ui-tabs-nav li" ).eq( 4 );
@ -314,9 +317,9 @@ asyncTest( "load", function() {
equal( ui.panel.find( "p" ).length, 1, "panel html" ); equal( ui.panel.find( "p" ).length, 1, "panel html" );
state( element, 0, 0, 0, 0, 1 ); state( element, 0, 0, 0, 0, 1 );
start(); start();
}); } );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 4 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 4 ).trigger( "click" );
} }
}); } );
} ); } );

View File

@ -15,7 +15,7 @@ return $.extend( helper, {
if ( internalState === true ) { if ( internalState === true ) {
internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) { internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) {
return index; return index;
}); } );
} }
expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) {
@ -24,9 +24,9 @@ return $.extend( helper, {
} else { } else {
return $.inArray( index, state ) !== -1 ? 1 : 0; return $.inArray( index, state ) !== -1 ? 1 : 0;
} }
}); } );
actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) { actual = tabs.find( ".ui-tabs-nav li" ).map( function( index ) {
var tab = $( this ), var tab = $( this ),
tabIsDisabled = tab.hasClass( "ui-state-disabled" ); tabIsDisabled = tab.hasClass( "ui-state-disabled" );
@ -36,23 +36,24 @@ return $.extend( helper, {
if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) { if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) {
return 0; return 0;
} }
// mixed state - invalid // mixed state - invalid
return -1; return -1;
}).get(); } ).get();
deepEqual( tabs.tabs( "option", "disabled" ), state ); deepEqual( tabs.tabs( "option", "disabled" ), state );
deepEqual( actual, expected ); deepEqual( actual, expected );
}, },
equalHeight: function( tabs, height ) { equalHeight: function( tabs, height ) {
tabs.find( ".ui-tabs-panel" ).each(function() { tabs.find( ".ui-tabs-panel" ).each( function() {
equal( $( this ).outerHeight(), height ); equal( $( this ).outerHeight(), height );
}); } );
}, },
state: function( tabs ) { state: function( tabs ) {
var expected = $.makeArray( arguments ).slice( 1 ), var expected = $.makeArray( arguments ).slice( 1 ),
actual = tabs.find( ".ui-tabs-nav li" ).map(function() { actual = tabs.find( ".ui-tabs-nav li" ).map( function() {
var tab = $( this ), var tab = $( this ),
panel = $( $.ui.tabs.prototype._sanitizeSelector( panel = $( $.ui.tabs.prototype._sanitizeSelector(
"#" + tab.attr( "aria-controls" ) ) ), "#" + tab.attr( "aria-controls" ) ) ),
@ -66,7 +67,7 @@ return $.extend( helper, {
return 0; return 0;
} }
return -1; // mixed state - invalid return -1; // mixed state - invalid
}).get(); } ).get();
deepEqual( actual, expected ); deepEqual( actual, expected );
} }
} ); } );

View File

@ -13,95 +13,103 @@ test( "destroy", function( assert ) {
expect( 2 ); expect( 2 );
assert.domEqual( "#tabs1", function() { assert.domEqual( "#tabs1", function() {
$( "#tabs1" ).tabs().tabs( "destroy" ); $( "#tabs1" ).tabs().tabs( "destroy" );
}); } );
assert.domEqual( "#tabs2", function() { assert.domEqual( "#tabs2", function() {
$( "#tabs2" ).tabs().tabs( "destroy" ); $( "#tabs2" ).tabs().tabs( "destroy" );
}); } );
}); } );
asyncTest( "destroy - ajax", function( assert ) { asyncTest( "destroy - ajax", function( assert ) {
expect( 1 ); expect( 1 );
assert.domEqual( "#tabs2", function( done ) { assert.domEqual( "#tabs2", function( done ) {
var element = $( "#tabs2" ).tabs({ var element = $( "#tabs2" ).tabs( {
load: function() { load: function() {
setTimeout(function() { setTimeout( function() {
element.tabs( "destroy" ); element.tabs( "destroy" );
done(); done();
start(); start();
}); } );
} }
}); } );
element.tabs( "option", "active", 2 ); element.tabs( "option", "active", 2 );
}); } );
}); } );
test( "enable", function() { test( "enable", function() {
expect( 8 ); expect( 8 );
var element = $( "#tabs1" ).tabs({ disabled: true }); var element = $( "#tabs1" ).tabs( { disabled: true } );
disabled( element, true ); disabled( element, true );
element.tabs( "enable" ); element.tabs( "enable" );
disabled( element, false ); disabled( element, false );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs({ disabled: [ 0, 1 ] }); element.tabs( { disabled: [ 0, 1 ] } );
disabled( element, [ 0, 1 ] ); disabled( element, [ 0, 1 ] );
element.tabs( "enable" ); element.tabs( "enable" );
disabled( element, false ); disabled( element, false );
}); } );
test( "enable( index )", function() { test( "enable( index )", function() {
expect( 10 ); expect( 10 );
var element = $( "#tabs1" ).tabs({ disabled: true }); var element = $( "#tabs1" ).tabs( { disabled: true } );
disabled( element, true ); disabled( element, true );
// fully disabled -> partially disabled // fully disabled -> partially disabled
element.tabs( "enable", 1 ); element.tabs( "enable", 1 );
disabled( element, [ 0, 2 ] ); disabled( element, [ 0, 2 ] );
// partially disabled -> partially disabled // partially disabled -> partially disabled
element.tabs( "enable", 2 ); element.tabs( "enable", 2 );
disabled( element, [ 0 ] ); disabled( element, [ 0 ] );
// already enabled tab, no change // already enabled tab, no change
element.tabs( "enable", 2 ); element.tabs( "enable", 2 );
disabled( element, [ 0 ] ); disabled( element, [ 0 ] );
// partially disabled -> fully enabled // partially disabled -> fully enabled
element.tabs( "enable", 0 ); element.tabs( "enable", 0 );
disabled( element, false ); disabled( element, false );
}); } );
test( "disable", function() { test( "disable", function() {
expect( 8 ); expect( 8 );
var element = $( "#tabs1" ).tabs({ disabled: false }); var element = $( "#tabs1" ).tabs( { disabled: false } );
disabled( element, false ); disabled( element, false );
element.tabs( "disable" ); element.tabs( "disable" );
disabled( element, true ); disabled( element, true );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs({ disabled: [ 0, 1 ] }); element.tabs( { disabled: [ 0, 1 ] } );
disabled( element, [ 0, 1 ] ); disabled( element, [ 0, 1 ] );
element.tabs( "disable" ); element.tabs( "disable" );
disabled( element, true ); disabled( element, true );
}); } );
test( "disable( index )", function() { test( "disable( index )", function() {
expect( 10 ); expect( 10 );
var element = $( "#tabs1" ).tabs({ disabled: false }); var element = $( "#tabs1" ).tabs( { disabled: false } );
disabled( element, false ); disabled( element, false );
// fully enabled -> partially disabled // fully enabled -> partially disabled
element.tabs( "disable", 1 ); element.tabs( "disable", 1 );
disabled( element, [ 1 ] ); disabled( element, [ 1 ] );
// partially disabled -> partially disabled // partially disabled -> partially disabled
element.tabs( "disable", 2 ); element.tabs( "disable", 2 );
disabled( element, [ 1, 2 ] ); disabled( element, [ 1, 2 ] );
// already disabled tab, no change // already disabled tab, no change
element.tabs( "disable", 2 ); element.tabs( "disable", 2 );
disabled( element, [ 1, 2 ] ); disabled( element, [ 1, 2 ] );
// partially disabled -> fully disabled // partially disabled -> fully disabled
element.tabs( "disable", 0 ); element.tabs( "disable", 0 );
disabled( element, true ); disabled( element, true );
}); } );
test( "refresh", function() { test( "refresh", function() {
expect( 27 ); expect( 27 );
@ -170,15 +178,15 @@ test( "refresh", function() {
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 1 ); state( element, 1 );
disabled( element, false ); disabled( element, false );
}); } );
test( "refresh - looping", function() { test( "refresh - looping", function() {
expect( 6 ); expect( 6 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
disabled: [ 0 ], disabled: [ 0 ],
active: 1 active: 1
}); } );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
disabled( element, [ 0 ] ); disabled( element, [ 0 ] );
@ -190,7 +198,7 @@ test( "refresh - looping", function() {
element.tabs( "refresh" ); element.tabs( "refresh" );
state( element, 0, 1 ); state( element, 0, 1 );
disabled( element, [ 0 ] ); disabled( element, [ 0 ] );
}); } );
asyncTest( "load", function() { asyncTest( "load", function() {
expect( 30 ); expect( 30 );
@ -210,8 +218,9 @@ asyncTest( "load", function() {
equal( ui.panel.length, 1, "panel length" ); equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
state( element, 1, 0, 0, 0, 0 ); state( element, 1, 0, 0, 0, 0 );
}); } );
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
// TODO: remove wrapping in 2.0 // TODO: remove wrapping in 2.0
var uiTab = $( ui.tab ), var uiTab = $( ui.tab ),
uiPanel = $( ui.panel ), uiPanel = $( ui.panel ),
@ -227,24 +236,26 @@ asyncTest( "load", function() {
equal( uiPanel.find( "p" ).length, 1, "panel html" ); equal( uiPanel.find( "p" ).length, 1, "panel html" );
state( element, 1, 0, 0, 0, 0 ); state( element, 1, 0, 0, 0, 0 );
setTimeout( tabsload1 ); setTimeout( tabsload1 );
}); } );
element.tabs( "load", 3 ); element.tabs( "load", 3 );
state( element, 1, 0, 0, 0, 0 ); state( element, 1, 0, 0, 0, 0 );
function tabsload1() { function tabsload1() {
// no need to test details of event (tested in events tests) // no need to test details of event (tested in events tests)
element.one( "tabsbeforeload", function() { element.one( "tabsbeforeload", function() {
ok( true, "tabsbeforeload invoked" ); ok( true, "tabsbeforeload invoked" );
}); } );
element.one( "tabsload", function() { element.one( "tabsload", function() {
ok( true, "tabsload invoked" ); ok( true, "tabsload invoked" );
setTimeout( tabsload2 ); setTimeout( tabsload2 );
}); } );
element.tabs( "option", "active", 3 ); element.tabs( "option", "active", 3 );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
} }
function tabsload2() { function tabsload2() {
// reload content of active tab // reload content of active tab
element.one( "tabsbeforeload", function( event, ui ) { element.one( "tabsbeforeload", function( event, ui ) {
var tab = element.find( ".ui-tabs-nav li" ).eq( 3 ), var tab = element.find( ".ui-tabs-nav li" ).eq( 3 ),
@ -257,8 +268,9 @@ asyncTest( "load", function() {
equal( ui.panel.length, 1, "panel length" ); equal( ui.panel.length, 1, "panel length" );
strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
}); } );
element.one( "tabsload", function( event, ui ) { element.one( "tabsload", function( event, ui ) {
// TODO: remove wrapping in 2.0 // TODO: remove wrapping in 2.0
var uiTab = $( ui.tab ), var uiTab = $( ui.tab ),
uiPanel = $( ui.panel ), uiPanel = $( ui.panel ),
@ -273,11 +285,11 @@ asyncTest( "load", function() {
strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
start(); start();
}); } );
element.tabs( "load", 3 ); element.tabs( "load", 3 );
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
} }
}); } );
test( "widget", function() { test( "widget", function() {
expect( 2 ); expect( 2 );
@ -285,6 +297,6 @@ test( "widget", function() {
widgetElement = element.tabs( "widget" ); widgetElement = element.tabs( "widget" );
equal( widgetElement.length, 1, "one element" ); equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
}); } );
} ); } );

View File

@ -30,15 +30,15 @@ test( "{ active: default }", function() {
state( element, 0, 0, 0, 1, 0 ); state( element, 0, 0, 0, 1, 0 );
element.tabs( "destroy" ); element.tabs( "destroy" );
location.hash = "#"; location.hash = "#";
}); } );
test( "{ active: false }", function() { test( "{ active: false }", function() {
expect( 7 ); expect( 7 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: false, active: false,
collapsible: true collapsible: true
}); } );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
equal( element.find( ".ui-tabs-nav .ui-state-active" ).length, 0, "no tabs selected" ); equal( element.find( ".ui-tabs-nav .ui-state-active" ).length, 0, "no tabs selected" );
strictEqual( element.tabs( "option", "active" ), false ); strictEqual( element.tabs( "option", "active" ), false );
@ -48,19 +48,19 @@ test( "{ active: false }", function() {
equal( element.tabs( "option", "active" ), 0 ); equal( element.tabs( "option", "active" ), 0 );
element.tabs( "destroy" ); element.tabs( "destroy" );
element.tabs({ element.tabs( {
active: false active: false
}); } );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
strictEqual( element.tabs( "option", "active" ), 0 ); strictEqual( element.tabs( "option", "active" ), 0 );
}); } );
test( "{ active: Number }", function() { test( "{ active: Number }", function() {
expect( 8 ); expect( 8 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: 2 active: 2
}); } );
equal( element.tabs( "option", "active" ), 2 ); equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( element, 0, 0, 1 );
@ -75,14 +75,14 @@ test( "{ active: Number }", function() {
element.tabs( "option", "active", 10 ); element.tabs( "option", "active", 10 );
equal( element.tabs( "option", "active" ), 1 ); equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
test( "{ active: -Number }", function() { test( "{ active: -Number }", function() {
expect( 8 ); expect( 8 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: -1 active: -1
}); } );
equal( element.tabs( "option", "active" ), 2 ); equal( element.tabs( "option", "active" ), 2 );
state( element, 0, 0, 1 ); state( element, 0, 0, 1 );
@ -97,7 +97,7 @@ test( "{ active: -Number }", function() {
element.tabs( "option", "active", -3 ); element.tabs( "option", "active", -3 );
equal( element.tabs( "option", "active" ), 0 ); equal( element.tabs( "option", "active" ), 0 );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
}); } );
test( "active - mismatched tab/panel order", function() { test( "active - mismatched tab/panel order", function() {
expect( 3 ); expect( 3 );
@ -109,15 +109,15 @@ test( "active - mismatched tab/panel order", function() {
element.tabs( "option", "active", 0 ); element.tabs( "option", "active", 0 );
state( element, 1, 0 ); state( element, 1, 0 );
location.hash = "#"; location.hash = "#";
}); } );
test( "collapsible", function( assert ) { test( "collapsible", function( assert ) {
expect( 13 ); expect( 13 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
active: 1, active: 1,
collapsible: true collapsible: true
}); } );
assert.hasClasses( element, "ui-tabs-collapsible" ); assert.hasClasses( element, "ui-tabs-collapsible" );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
equal( element.tabs( "option", "active" ), false ); equal( element.tabs( "option", "active" ), false );
@ -138,10 +138,10 @@ test( "collapsible", function( assert ) {
assert.hasClasses( element, "ui-tabs-collapsible" ); assert.hasClasses( element, "ui-tabs-collapsible" );
element.tabs({ element.tabs( {
active: 1, active: 1,
collapsible: false collapsible: false
}); } );
element.tabs( "option", "active", false ); element.tabs( "option", "active", false );
equal( element.tabs( "option", "active" ), 1 ); equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
@ -150,7 +150,7 @@ test( "collapsible", function( assert ) {
equal( element.tabs( "option", "active" ), 1 ); equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
test( "disabled", function( assert ) { test( "disabled", function( assert ) {
expect( 23 ); expect( 23 );
@ -195,14 +195,14 @@ test( "disabled", function( assert ) {
// Enable all tabs // Enable all tabs
element.tabs( "option", "disabled", [] ); element.tabs( "option", "disabled", [] );
disabled( element, false ); disabled( element, false );
}); } );
test( "{ event: null }", function() { test( "{ event: null }", function() {
expect( 5 ); expect( 5 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
event: null event: null
}); } );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
@ -213,14 +213,14 @@ test( "{ event: null }", function() {
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 2 ).trigger( "click" );
equal( element.tabs( "option", "active" ), 1 ); equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
test( "{ event: custom }", function() { test( "{ event: custom }", function() {
expect( 11 ); expect( 11 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
event: "custom1 custom2" event: "custom1 custom2"
}); } );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom1" );
@ -246,88 +246,88 @@ test( "{ event: custom }", function() {
element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom3" ); element.find( ".ui-tabs-nav .ui-tabs-anchor" ).eq( 1 ).trigger( "custom3" );
equal( element.tabs( "option", "active" ), 1 ); equal( element.tabs( "option", "active" ), 1 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); } );
test( "{ heightStyle: 'auto' }", function() { test( "{ heightStyle: 'auto' }", function() {
expect( 2 ); expect( 2 );
var element = $( "#tabs8" ).tabs({ heightStyle: "auto" }); var element = $( "#tabs8" ).tabs( { heightStyle: "auto" } );
equalHeight( element, 45 ); equalHeight( element, 45 );
}); } );
test( "{ heightStyle: 'content' }", function() { test( "{ heightStyle: 'content' }", function() {
expect( 2 ); expect( 2 );
var element = $( "#tabs8" ).tabs({ heightStyle: "content" }), var element = $( "#tabs8" ).tabs( { heightStyle: "content" } ),
sizes = element.find( ".ui-tabs-panel" ).map(function() { sizes = element.find( ".ui-tabs-panel" ).map( function() {
return $( this ).height(); return $( this ).height();
}).get(); } ).get();
equal( sizes[ 0 ], 45 ); equal( sizes[ 0 ], 45 );
equal( sizes[ 1 ], 15 ); equal( sizes[ 1 ], 15 );
}); } );
test( "{ heightStyle: 'fill' }", function() { test( "{ heightStyle: 'fill' }", function() {
expect( 4 ); expect( 4 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
var element = $( "#tabs8" ).tabs({ heightStyle: "fill" }); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 485 ); equalHeight( element, 485 );
element.tabs( "destroy" ); element.tabs( "destroy" );
element = $( "#tabs8" ).css({ element = $( "#tabs8" ).css( {
"border": "1px solid black", "border": "1px solid black",
"padding": "1px 0" "padding": "1px 0"
}); } );
element.tabs({ heightStyle: "fill" }); element.tabs( { heightStyle: "fill" } );
equalHeight( element, 481 ); equalHeight( element, 481 );
}); } );
test( "{ heightStyle: 'fill' } with sibling", function() { test( "{ heightStyle: 'fill' } with sibling", function() {
expect( 2 ); expect( 2 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css({ .css( {
height: 50, height: 50,
marginTop: 20, marginTop: 20,
marginBottom: 30 marginBottom: 30
}) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
var element = $( "#tabs8" ).tabs({ heightStyle: "fill" }); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 385 ); equalHeight( element, 385 );
}); } );
test( "{ heightStyle: 'fill' } with multiple siblings", function() { test( "{ heightStyle: 'fill' } with multiple siblings", function() {
expect( 2 ); expect( 2 );
$( "#tabs8Wrapper" ).height( 500 ); $( "#tabs8Wrapper" ).height( 500 );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css({ .css( {
height: 50, height: 50,
marginTop: 20, marginTop: 20,
marginBottom: 30 marginBottom: 30
}) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css({ .css( {
height: 50, height: 50,
marginTop: 20, marginTop: 20,
marginBottom: 30, marginBottom: 30,
position: "absolute" position: "absolute"
}) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
$( "<p>Lorem Ipsum</p>" ) $( "<p>Lorem Ipsum</p>" )
.css({ .css( {
height: 25, height: 25,
marginTop: 10, marginTop: 10,
marginBottom: 15 marginBottom: 15
}) } )
.prependTo( "#tabs8Wrapper" ); .prependTo( "#tabs8Wrapper" );
var element = $( "#tabs8" ).tabs({ heightStyle: "fill" }); var element = $( "#tabs8" ).tabs( { heightStyle: "fill" } );
equalHeight( element, 335 ); equalHeight( element, 335 );
}); } );
test( "hide and show: false", function() { test( "hide and show: false", function() {
expect( 3 ); expect( 3 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
show: false, show: false,
hide: false hide: false
}), } ),
widget = element.tabs( "instance" ), widget = element.tabs( "instance" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
widget._show = function() { widget._show = function() {
@ -341,34 +341,34 @@ test( "hide and show: false", function() {
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" ); ok( panels.eq( 0 ).is( ":hidden" ), "first panel hidden" );
ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" ); ok( panels.eq( 1 ).is( ":visible" ), "second panel visible" );
}); } );
asyncTest( "hide and show - animation", function() { asyncTest( "hide and show - animation", function() {
expect( 5 ); expect( 5 );
var element = $( "#tabs1" ).tabs({ var element = $( "#tabs1" ).tabs( {
show: "drop", show: "drop",
hide: 2000 hide: 2000
}), } ),
widget = element.tabs( "instance" ), widget = element.tabs( "instance" ),
panels = element.find( ".ui-tabs-panel" ); panels = element.find( ".ui-tabs-panel" );
widget._show = function( element, options, callback ) { widget._show = function( element, options, callback ) {
strictEqual( element[ 0 ], panels[ 1 ], "correct element in _show()" ); strictEqual( element[ 0 ], panels[ 1 ], "correct element in _show()" );
equal( options, "drop", "correct options in _show()" ); equal( options, "drop", "correct options in _show()" );
setTimeout(function() { setTimeout( function() {
callback(); callback();
}); } );
}; };
widget._hide = function( element, options, callback ) { widget._hide = function( element, options, callback ) {
strictEqual( element[ 0 ], panels[ 0 ], "correct element in _hide()" ); strictEqual( element[ 0 ], panels[ 0 ], "correct element in _hide()" );
equal( options, 2000, "correct options in _hide()" ); equal( options, 2000, "correct options in _hide()" );
setTimeout(function() { setTimeout( function() {
callback(); callback();
start(); start();
}); } );
}; };
ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" ); ok( panels.eq( 0 ).is( ":visible" ), "first panel visible" );
element.tabs( "option", "active", 1 ); element.tabs( "option", "active", 1 );
}); } );
} ); } );

View File

@ -123,6 +123,7 @@ $.widget( "ui.tabs", {
locationHash = location.hash.substring( 1 ); locationHash = location.hash.substring( 1 );
if ( active === null ) { if ( active === null ) {
// check the fragment identifier in the URL // check the fragment identifier in the URL
if ( locationHash ) { if ( locationHash ) {
this.tabs.each( function( i, tab ) { this.tabs.each( function( i, tab ) {
@ -193,15 +194,18 @@ $.widget( "ui.tabs", {
selectedIndex = 0; selectedIndex = 0;
break; break;
case $.ui.keyCode.SPACE: case $.ui.keyCode.SPACE:
// Activate only, no collapsing // Activate only, no collapsing
event.preventDefault(); event.preventDefault();
clearTimeout( this.activating ); clearTimeout( this.activating );
this._activate( selectedIndex ); this._activate( selectedIndex );
return; return;
case $.ui.keyCode.ENTER: case $.ui.keyCode.ENTER:
// Toggle (cancel delayed activation, allow collapsing) // Toggle (cancel delayed activation, allow collapsing)
event.preventDefault(); event.preventDefault();
clearTimeout( this.activating ); clearTimeout( this.activating );
// Determine if we should collapse or activate // Determine if we should collapse or activate
this._activate( selectedIndex === this.options.active ? false : selectedIndex ); this._activate( selectedIndex === this.options.active ? false : selectedIndex );
return; return;
@ -281,12 +285,14 @@ $.widget( "ui.tabs", {
_setOption: function( key, value ) { _setOption: function( key, value ) {
if ( key === "active" ) { if ( key === "active" ) {
// _activate() will handle invalid values and update this.options // _activate() will handle invalid values and update this.options
this._activate( value ); this._activate( value );
return; return;
} }
if ( key === "disabled" ) { if ( key === "disabled" ) {
// don't use the widget factory's disabled handling // don't use the widget factory's disabled handling
this._setupDisabled( value ); this._setupDisabled( value );
return; return;
@ -332,18 +338,23 @@ $.widget( "ui.tabs", {
if ( options.active === false || !this.anchors.length ) { if ( options.active === false || !this.anchors.length ) {
options.active = false; options.active = false;
this.active = $(); this.active = $();
// was active, but active tab is gone // was active, but active tab is gone
} else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) { } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
// all remaining tabs are disabled // all remaining tabs are disabled
if ( this.tabs.length === options.disabled.length ) { if ( this.tabs.length === options.disabled.length ) {
options.active = false; options.active = false;
this.active = $(); this.active = $();
// activate previous tab // activate previous tab
} else { } else {
this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) ); this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
} }
// was active, active tab still exists // was active, active tab still exists
} else { } else {
// make sure active index is correct // make sure active index is correct
options.active = this.tabs.index( this.active ); options.active = this.tabs.index( this.active );
} }
@ -445,8 +456,10 @@ $.widget( "ui.tabs", {
selector = anchor.hash; selector = anchor.hash;
panelId = selector.substring( 1 ); panelId = selector.substring( 1 );
panel = that.element.find( that._sanitizeSelector( selector ) ); panel = that.element.find( that._sanitizeSelector( selector ) );
// remote tab // remote tab
} else { } else {
// If the tab doesn't already have aria-controls, // If the tab doesn't already have aria-controls,
// generate an id by using a throw-away element // generate an id by using a throw-away element
panelId = tab.attr( "aria-controls" ) || $( {} ).uniqueId()[ 0 ].id; panelId = tab.attr( "aria-controls" ) || $( {} ).uniqueId()[ 0 ].id;
@ -529,6 +542,7 @@ $.widget( "ui.tabs", {
} }
this._off( this.anchors.add( this.tabs ).add( this.panels ) ); this._off( this.anchors.add( this.tabs ).add( this.panels ) );
// Always prevent the default action, even when disabled // Always prevent the default action, even when disabled
this._on( true, this.anchors, { this._on( true, this.anchors, {
click: function( event ) { click: function( event ) {
@ -597,12 +611,16 @@ $.widget( "ui.tabs", {
event.preventDefault(); event.preventDefault();
if ( tab.hasClass( "ui-state-disabled" ) || if ( tab.hasClass( "ui-state-disabled" ) ||
// tab is already loading // tab is already loading
tab.hasClass( "ui-tabs-loading" ) || tab.hasClass( "ui-tabs-loading" ) ||
// can't switch durning an animation // can't switch durning an animation
this.running || this.running ||
// click on active header, but not collapsible // click on active header, but not collapsible
( clickedIsActive && !options.collapsible ) || ( clickedIsActive && !options.collapsible ) ||
// allow canceling activation // allow canceling activation
( this._trigger( "beforeActivate", event, eventData ) === false ) ) { ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
return; return;
@ -668,6 +686,7 @@ $.widget( "ui.tabs", {
"aria-selected": "false", "aria-selected": "false",
"aria-expanded": "false" "aria-expanded": "false"
} ); } );
// If we're switching tabs, remove the old tab from the tab order. // If we're switching tabs, remove the old tab from the tab order.
// If we're opening from collapsed state, remove the previous tab from the tab order. // If we're opening from collapsed state, remove the previous tab from the tab order.
// If we're collapsing, then keep the collapsing tab in the tab order. // If we're collapsing, then keep the collapsing tab in the tab order.
@ -715,6 +734,7 @@ $.widget( "ui.tabs", {
}, },
_getIndex: function( index ) { _getIndex: function( index ) {
// meta-function to give users option to provide a href string instead of a numerical index. // meta-function to give users option to provide a href string instead of a numerical index.
if ( typeof index === "string" ) { if ( typeof index === "string" ) {
index = this.anchors.index( this.anchors.filter( "[href$='" + $.ui.escapeSelector( index ) + "']" ) ); index = this.anchors.index( this.anchors.filter( "[href$='" + $.ui.escapeSelector( index ) + "']" ) );
@ -848,6 +868,7 @@ $.widget( "ui.tabs", {
this.xhr this.xhr
.done( function( response, status, jqXHR ) { .done( function( response, status, jqXHR ) {
// support: jQuery <1.8 // support: jQuery <1.8
// http://bugs.jquery.com/ticket/11778 // http://bugs.jquery.com/ticket/11778
setTimeout( function() { setTimeout( function() {
@ -858,6 +879,7 @@ $.widget( "ui.tabs", {
}, 1 ); }, 1 );
} ) } )
.fail( function( jqXHR, status ) { .fail( function( jqXHR, status ) {
// support: jQuery <1.8 // support: jQuery <1.8
// http://bugs.jquery.com/ticket/11778 // http://bugs.jquery.com/ticket/11778
setTimeout( function() { setTimeout( function() {