Skip to content

Commit

Permalink
Tabs: Fixed select event.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed May 10, 2011
1 parent 7fddb1c commit 85ac420
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
55 changes: 37 additions & 18 deletions tests/unit/tabs/tabs_deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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();
Expand All @@ -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" );
Expand Down
19 changes: 10 additions & 9 deletions ui/jquery.ui.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ],
Expand Down

0 comments on commit 85ac420

Please sign in to comment.