Skip to content

Commit d4318a5

Browse files
committed
Tabs: Replaced fx option with show and hide options. Fixes #8319 - Tabs: Deprecate fx option.
1 parent 1304c50 commit d4318a5

File tree

3 files changed

+81
-28
lines changed

3 files changed

+81
-28
lines changed

tests/unit/tabs/tabs_common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ TestHelpers.commonWidgetTests( "tabs", {
44
collapsible: false,
55
disabled: false,
66
event: "click",
7-
fx: null,
7+
hide: null,
8+
show: null,
89

910
// callbacks
1011
activate: null,

tests/unit/tabs/tabs_common_deprecated.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ TestHelpers.commonWidgetTests( "tabs", {
77
cookie: null,
88
disabled: false,
99
event: "click",
10+
hide: null,
1011
fx: null,
1112
idPrefix: "ui-tabs-",
1213
panelTemplate: "<div></div>",
14+
// show: null, // conflicts with old show callback
1315
spinner: "<em>Loading&#8230;</em>",
1416
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>",
1517

ui/jquery.ui.tabs.js

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ $.widget( "ui.tabs", {
3434
active: null,
3535
collapsible: false,
3636
event: "click",
37-
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
37+
hide: null,
38+
show: null,
3839

3940
// callbacks
4041
activate: null,
@@ -101,8 +102,6 @@ $.widget( "ui.tabs", {
101102
) ).sort();
102103
}
103104

104-
this._setupFx( options.fx );
105-
106105
this._refresh();
107106

108107
// highlight selected tab
@@ -151,10 +150,6 @@ $.widget( "ui.tabs", {
151150
if ( key === "event" ) {
152151
this._setupEvents( value );
153152
}
154-
155-
if ( key === "fx" ) {
156-
this._setupFx( value );
157-
}
158153
},
159154

160155
_tabId: function( a ) {
@@ -278,18 +273,6 @@ $.widget( "ui.tabs", {
278273
this.options.disabled = disabled;
279274
},
280275

281-
_setupFx: function( fx ) {
282-
// set up animations
283-
if ( fx ) {
284-
if ( $.isArray( fx ) ) {
285-
this.hideFx = fx[ 0 ];
286-
this.showFx = fx[ 1 ];
287-
} else {
288-
this.hideFx = this.showFx = fx;
289-
}
290-
}
291-
},
292-
293276
_setupEvents: function( event ) {
294277
// attach tab event handler, unbind to avoid duplicates from former tabifying...
295278
this.anchors.unbind( ".tabs" );
@@ -364,7 +347,7 @@ $.widget( "ui.tabs", {
364347
toShow = eventData.newPanel,
365348
toHide = eventData.oldPanel;
366349

367-
that.running = true;
350+
this.running = true;
368351

369352
function complete() {
370353
that.running = false;
@@ -374,20 +357,17 @@ $.widget( "ui.tabs", {
374357
function show() {
375358
eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
376359

377-
if ( toShow.length && that.showFx ) {
378-
toShow
379-
.animate( that.showFx, that.showFx.duration || "normal", function() {
380-
complete();
381-
});
360+
if ( toShow.length && that.options.show ) {
361+
that._show( toShow, that.options.show, complete );
382362
} else {
383363
toShow.show();
384364
complete();
385365
}
386366
}
387367

388368
// start out by hiding, then showing, then completing
389-
if ( toHide.length && that.hideFx ) {
390-
toHide.animate( that.hideFx, that.hideFx.duration || "normal", function() {
369+
if ( toHide.length && this.options.hide ) {
370+
this._hide( toHide, this.options.hide, function() {
391371
eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
392372
show();
393373
});
@@ -995,6 +975,76 @@ if ( $.uiBackCompat !== false ) {
995975
return this._super( type, event, _data );
996976
}
997977
});
978+
979+
// fx option
980+
// The new animation options (show, hide) conflict with the old show callback.
981+
// The old fx option wins over show/hide anyway (always favor back-compat).
982+
// If a user wants to use the new animation API, they must give up the old API.
983+
$.widget( "ui.tabs", $.ui.tabs, {
984+
options: {
985+
fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 }
986+
},
987+
988+
_getFx: function() {
989+
var hide, show,
990+
fx = this.options.fx;
991+
992+
if ( fx ) {
993+
if ( $.isArray( fx ) ) {
994+
hide = fx[ 0 ];
995+
show = fx[ 1 ];
996+
} else {
997+
hide = show = fx;
998+
}
999+
}
1000+
1001+
return fx ? { show: show, hide: hide } : null;
1002+
},
1003+
1004+
_toggle: function( event, eventData ) {
1005+
var that = this,
1006+
toShow = eventData.newPanel,
1007+
toHide = eventData.oldPanel,
1008+
fx = this._getFx();
1009+
1010+
if ( !fx ) {
1011+
return this._super( event, eventData );
1012+
}
1013+
1014+
that.running = true;
1015+
1016+
function complete() {
1017+
that.running = false;
1018+
that._trigger( "activate", event, eventData );
1019+
}
1020+
1021+
function show() {
1022+
eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
1023+
1024+
if ( toShow.length && fx.show ) {
1025+
toShow
1026+
.animate( fx.show, fx.show.duration, function() {
1027+
complete();
1028+
});
1029+
} else {
1030+
toShow.show();
1031+
complete();
1032+
}
1033+
}
1034+
1035+
// start out by hiding, then showing, then completing
1036+
if ( toHide.length && fx.hide ) {
1037+
toHide.animate( fx.hide, fx.hide.duration, function() {
1038+
eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
1039+
show();
1040+
});
1041+
} else {
1042+
eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
1043+
toHide.hide();
1044+
show();
1045+
}
1046+
}
1047+
});
9981048
}
9991049

10001050
})( jQuery );

0 commit comments

Comments
 (0)