Skip to content
Permalink
Browse files

Tabs: Fixed select event.

  • Loading branch information...
scottgonzalez committed May 10, 2011
1 parent 7fddb1c commit 85ac420a1e4281ee7f361e847d3cad72fa58525e
Showing with 47 additions and 27 deletions.
  1. +37 −18 tests/unit/tabs/tabs_deprecated.js
  2. +10 −9 ui/jquery.ui.tabs.js
@@ -267,7 +267,7 @@ test( "show", function() {
ok( !( "originalEvent" in event ), "originalEvent" );
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
equal( ui.index, 0 );
equal( ui.index, 0, "ui.index" );
tabs_state( element, 1, 0, 0 );
});
element.tabs( "option", "active", 0 );
@@ -278,7 +278,7 @@ test( "show", function() {
equals( event.originalEvent.type, "click", "originalEvent" );
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
equal( ui.index, 1 );
equal( ui.index, 1, "ui.index" );
tabs_state( element, 0, 1, 0 );
});
tabs.eq( 1 ).click();
@@ -292,25 +292,44 @@ test( "show", function() {
tabs_state( element, 0, 0, 0 );
});

test('select', function() {
expect(7);
test( "select", function() {
expect( 13 );

var eventObj;
el = $('#tabs1').tabs({
select: function(event, ui) {
ok(true, 'select triggered after initialization');
equals(this, el[0], "context of callback");
equals(event.type, 'tabsselect', 'event type in callback');
equals(ui.tab, el.find('a')[1], 'contain tab as DOM anchor element');
equals(ui.panel, el.find('div')[1], 'contain panel as DOM div element');
equals(ui.index, 1, 'contain index');
evenObj = event;
}
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 );
});
el.tabs('select', 1);
element.tabs( "option", "active", 0 );
tabs_state( element, 1, 0, 0 );

el.find( "li:eq(1) a" ).simulate( "click" );
equals( evenObj.originalEvent.type, "click", "select triggered by click" );
// switching tabs
element.one( "tabsselect", function( event, ui ) {
equals( event.originalEvent.type, "click", "originalEvent" );
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 );
});
tabs.eq( 1 ).click();
tabs_state( element, 0, 1, 0 );

// collapsing
element.one( "tabsselect", function( event, ui ) {
ok( false, "collapsing" );
});
element.tabs( "option", "active", false );
tabs_state( element, 0, 0, 0 );
});

module( "tabs (deprecated): methods" );
@@ -153,14 +153,6 @@ $.widget( "ui.tabs", {
return hash ? hash.replace( /:/g, "\\:" ) : "";
},

_ui: function( tab, panel ) {
return {
tab: tab,
panel: panel,
index: this.anchors.index( tab )
};
},

refresh: function() {
var self = this,
options = this.options,
@@ -651,6 +643,15 @@ $.extend( $.ui.tabs, {
// DEPRECATED
if ( $.uiBackCompat !== false ) {

// helper method for a lot of the back compat extensions
$.ui.tabs.prototype._ui = function( tab, panel ) {
return {
tab: tab,
panel: panel,
index: this.anchors.index( tab )
};
};

// url method
(function( $, prototype ) {
prototype.url = function( index, url ) {
@@ -975,7 +976,7 @@ if ( $.uiBackCompat !== false ) {
if ( !ret ) {
return false;
}
if ( type === "beforeActivate" ) {
if ( type === "beforeActivate" && data.newTab.length ) {
ret = _trigger.call( this, "select", event, {
tab: data.newTab[ 0],
panel: data.newPanel[ 0 ],

0 comments on commit 85ac420

Please sign in to comment.
You can’t perform that action at this time.