Skip to content

Commit 7fddb1c

Browse files
committed
Tabs: Fixed show event.
1 parent 319c5eb commit 7fddb1c

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

tests/unit/tabs/tabs_deprecated.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,45 @@ test( "disable", function() {
251251
element.tabs( "disable", 1 );
252252
});
253253

254-
test('show', function() {
255-
expect(5);
256254

257-
var uiObj, eventObj;
258-
el = $('#tabs1').tabs({
259-
show: function(event, ui) {
260-
uiObj = ui;
261-
eventObj = event;
262-
}
255+
test( "show", function() {
256+
expect( 13 );
257+
258+
var element = $( "#tabs1" ).tabs({
259+
active: false,
260+
collapsible: true
261+
}),
262+
tabs = element.find( ".ui-tabs-nav a" ),
263+
panels = element.find( ".ui-tabs-panel" );
264+
265+
// from collapsed
266+
element.one( "tabsshow", function( event, ui ) {
267+
ok( !( "originalEvent" in event ), "originalEvent" );
268+
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
269+
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
270+
equal( ui.index, 0 );
271+
tabs_state( element, 1, 0, 0 );
263272
});
264-
ok(uiObj !== undefined, 'trigger callback after initialization');
265-
equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
266-
equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
267-
equals(uiObj.index, 0, 'contain index');
273+
element.tabs( "option", "active", 0 );
274+
tabs_state( element, 1, 0, 0 );
268275

269-
el.find( "li:eq(1) a" ).simulate( "click" );
270-
equals( eventObj.originalEvent.type, "click", "show triggered by click" );
276+
// switching tabs
277+
element.one( "tabsshow", function( event, ui ) {
278+
equals( event.originalEvent.type, "click", "originalEvent" );
279+
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
280+
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
281+
equal( ui.index, 1 );
282+
tabs_state( element, 0, 1, 0 );
283+
});
284+
tabs.eq( 1 ).click();
285+
tabs_state( element, 0, 1, 0 );
271286

287+
// collapsing
288+
element.one( "tabsshow", function( event, ui ) {
289+
ok( false, "collapsing" );
290+
});
291+
element.tabs( "option", "active", false );
292+
tabs_state( element, 0, 0, 0 );
272293
});
273294

274295
test('select', function() {

ui/jquery.ui.tabs.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,7 @@ $.widget( "ui.tabs", {
108108
var panel = that._getPanelForTab( this.active );
109109

110110
panel.show();
111-
112111
this.lis.eq( options.active ).addClass( "ui-tabs-active ui-state-active" );
113-
114-
// TODO: we need to remove this or add it to accordion
115-
// seems to be expected behavior that the activate callback is fired
116-
that.element.queue( "tabs", function() {
117-
that._trigger( "activate", null, that._ui( that.active[ 0 ], panel[ 0 ] ) );
118-
});
119-
120112
this.load( options.active );
121113
} else {
122114
this.active = $();
@@ -968,8 +960,16 @@ if ( $.uiBackCompat !== false ) {
968960
show: null,
969961
select: null
970962
});
971-
var _trigger = prototype._trigger;
963+
var _create = prototype._create,
964+
_trigger = prototype._trigger;
972965

966+
prototype._create = function() {
967+
_create.call( this );
968+
if ( this.options.active !== false ) {
969+
this._trigger( "show", null, this._ui(
970+
this.active[ 0 ], this._getPanelForTab( this.active )[ 0 ] ) );
971+
}
972+
}
973973
prototype._trigger = function( type, event, data ) {
974974
var ret = _trigger.apply( this, arguments );
975975
if ( !ret ) {
@@ -981,8 +981,12 @@ if ( $.uiBackCompat !== false ) {
981981
panel: data.newPanel[ 0 ],
982982
index: data.newTab.closest( "li" ).index()
983983
});
984-
} else if ( type === "activate" ) {
985-
ret = _trigger.call( this, "show", event, data );
984+
} else if ( type === "activate" && data.newTab.length ) {
985+
ret = _trigger.call( this, "show", event, {
986+
tab: data.newTab[ 0 ],
987+
panel: data.newPanel[ 0 ],
988+
index: data.newTab.closest( "li" ).index()
989+
});
986990
}
987991
};
988992
}( jQuery, jQuery.ui.tabs.prototype ) );

0 commit comments

Comments
 (0)