@@ -34,7 +34,8 @@ $.widget( "ui.tabs", {
34
34
active : null ,
35
35
collapsible : false ,
36
36
event : "click" ,
37
- fx : null , // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
37
+ hide : null ,
38
+ show : null ,
38
39
39
40
// callbacks
40
41
activate : null ,
@@ -101,8 +102,6 @@ $.widget( "ui.tabs", {
101
102
) ) . sort ( ) ;
102
103
}
103
104
104
- this . _setupFx ( options . fx ) ;
105
-
106
105
this . _refresh ( ) ;
107
106
108
107
// highlight selected tab
@@ -151,10 +150,6 @@ $.widget( "ui.tabs", {
151
150
if ( key === "event" ) {
152
151
this . _setupEvents ( value ) ;
153
152
}
154
-
155
- if ( key === "fx" ) {
156
- this . _setupFx ( value ) ;
157
- }
158
153
} ,
159
154
160
155
_tabId : function ( a ) {
@@ -278,18 +273,6 @@ $.widget( "ui.tabs", {
278
273
this . options . disabled = disabled ;
279
274
} ,
280
275
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
-
293
276
_setupEvents : function ( event ) {
294
277
// attach tab event handler, unbind to avoid duplicates from former tabifying...
295
278
this . anchors . unbind ( ".tabs" ) ;
@@ -364,7 +347,7 @@ $.widget( "ui.tabs", {
364
347
toShow = eventData . newPanel ,
365
348
toHide = eventData . oldPanel ;
366
349
367
- that . running = true ;
350
+ this . running = true ;
368
351
369
352
function complete ( ) {
370
353
that . running = false ;
@@ -374,20 +357,17 @@ $.widget( "ui.tabs", {
374
357
function show ( ) {
375
358
eventData . newTab . closest ( "li" ) . addClass ( "ui-tabs-active ui-state-active" ) ;
376
359
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 ) ;
382
362
} else {
383
363
toShow . show ( ) ;
384
364
complete ( ) ;
385
365
}
386
366
}
387
367
388
368
// 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 ( ) {
391
371
eventData . oldTab . closest ( "li" ) . removeClass ( "ui-tabs-active ui-state-active" ) ;
392
372
show ( ) ;
393
373
} ) ;
@@ -995,6 +975,76 @@ if ( $.uiBackCompat !== false ) {
995
975
return this . _super ( type , event , _data ) ;
996
976
}
997
977
} ) ;
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
+ } ) ;
998
1048
}
999
1049
1000
1050
} ) ( jQuery ) ;
0 commit comments