@@ -104,6 +104,8 @@ $.widget( "ui.tabs", {
104
104
} ) ;
105
105
106
106
this . load ( o . active ) ;
107
+ } else {
108
+ this . active = $ ( ) ;
107
109
}
108
110
109
111
// clean up to avoid memory leaks in certain versions of IE 6
@@ -329,73 +331,80 @@ $.widget( "ui.tabs", {
329
331
} ,
330
332
331
333
_eventHandler : function ( event ) {
332
- event . preventDefault ( ) ;
333
- var self = this ,
334
- o = this . options ,
334
+ var that = this ,
335
+ options = that . options ,
336
+ active = that . active ,
335
337
clicked = $ ( event . currentTarget ) ,
336
- $li = clicked . closest ( "li" ) ,
337
- $hide = self . element . find ( self . _sanitizeSelector ( $ ( this . active ) . attr ( "aria-controls" ) ) ) ,
338
- $show = self . element . find ( self . _sanitizeSelector ( clicked . attr ( "aria-controls" ) ) ) ;
339
-
340
- // tab is already selected, but not collapsible
341
- if ( ( $li . hasClass ( "ui-tabs-active" ) && ! o . collapsible ) ||
342
- // can't switch durning an animation
343
- self . running ||
344
- // tab is disabled
345
- $li . hasClass ( "ui-state-disabled" ) ||
346
- // tab is already loading
347
- $li . hasClass ( "ui-tabs-loading" ) ||
348
- // allow canceling by beforeActivate event
349
- self . _trigger ( "beforeActivate" , event , self . _ui ( clicked [ 0 ] , $show [ 0 ] ) ) === false ) {
338
+ clickedIsActive = clicked [ 0 ] === active [ 0 ] ,
339
+ collapsing = clickedIsActive && options . collapsible ,
340
+ toShow = collapsing ? $ ( ) : that . element . find ( that . _sanitizeSelector ( clicked . attr ( "aria-controls" ) ) ) ,
341
+ toHide = ! active . length ? $ ( ) : that . element . find ( that . _sanitizeSelector ( active . attr ( "aria-controls" ) ) ) ,
342
+ tab = clicked . closest ( "li" ) ,
343
+ eventData = {
344
+ oldTab : active ,
345
+ oldPanel : toHide ,
346
+ newTab : collapsing ? $ ( ) : clicked ,
347
+ newPanel : toShow
348
+ } ;
349
+
350
+ event . preventDefault ( ) ;
351
+
352
+ if ( tab . hasClass ( "ui-state-disabled" ) ||
353
+ // tab is already loading
354
+ tab . hasClass ( "ui-tabs-loading" ) ||
355
+ // can't switch durning an animation
356
+ that . running ||
357
+ // click on active header, but not collapsible
358
+ ( clickedIsActive && ! options . collapsible ) ||
359
+ // allow canceling activation
360
+ ( that . _trigger ( "beforeActivate" , event , eventData ) === false ) ) {
350
361
clicked [ 0 ] . blur ( ) ;
351
362
return ;
352
363
}
353
364
354
- o . active = self . anchors . index ( clicked ) ;
355
-
356
- self . active = clicked ;
365
+ options . active = collapsing ? false : that . anchors . index ( clicked ) ;
357
366
358
- if ( self . xhr ) {
359
- self . xhr . abort ( ) ;
367
+ that . active = clicked ;
368
+ if ( that . xhr ) {
369
+ that . xhr . abort ( ) ;
360
370
}
361
371
362
372
// if tab may be closed
363
- if ( o . collapsible ) {
364
- if ( $li . hasClass ( "ui-tabs-active" ) ) {
365
- o . active = - 1 ;
366
- self . active = null ;
373
+ if ( options . collapsible ) {
374
+ if ( collapsing ) {
375
+ options . active = false ;
367
376
368
- self . element . queue ( "tabs" , function ( ) {
369
- self . _hideTab ( clicked , $hide ) ;
377
+ that . element . queue ( "tabs" , function ( ) {
378
+ that . _hideTab ( clicked , toHide ) ;
370
379
} ) . dequeue ( "tabs" ) ;
371
380
372
381
clicked [ 0 ] . blur ( ) ;
373
382
return ;
374
- } else if ( ! $hide . length ) {
375
- self . element . queue ( "tabs" , function ( ) {
376
- self . _showTab ( clicked , $show , event ) ;
383
+ } else if ( ! toHide . length ) {
384
+ that . element . queue ( "tabs" , function ( ) {
385
+ that . _showTab ( clicked , toShow , event ) ;
377
386
} ) ;
378
387
379
388
// TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
380
- self . load ( self . anchors . index ( clicked ) ) ;
389
+ that . load ( that . anchors . index ( clicked ) ) ;
381
390
382
391
clicked [ 0 ] . blur ( ) ;
383
392
return ;
384
393
}
385
394
}
386
395
387
396
// show new tab
388
- if ( $show . length ) {
389
- if ( $hide . length ) {
390
- self . element . queue ( "tabs" , function ( ) {
391
- self . _hideTab ( clicked , $hide ) ;
397
+ if ( toShow . length ) {
398
+ if ( toHide . length ) {
399
+ that . element . queue ( "tabs" , function ( ) {
400
+ that . _hideTab ( clicked , toHide ) ;
392
401
} ) ;
393
402
}
394
- self . element . queue ( "tabs" , function ( ) {
395
- self . _showTab ( clicked , $show , event ) ;
403
+ that . element . queue ( "tabs" , function ( ) {
404
+ that . _showTab ( clicked , toShow , event ) ;
396
405
} ) ;
397
406
398
- self . load ( self . anchors . index ( clicked ) ) ;
407
+ that . load ( that . anchors . index ( clicked ) ) ;
399
408
} else {
400
409
throw "jQuery UI Tabs: Mismatching fragment identifier." ;
401
410
}
@@ -919,7 +928,11 @@ if ( $.uiBackCompat !== false ) {
919
928
return false ;
920
929
}
921
930
if ( type === "beforeActivate" ) {
922
- ret = _trigger . call ( this , "select" , event , data ) ;
931
+ ret = _trigger . call ( this , "select" , event , {
932
+ tab : data . newTab [ 0 ] ,
933
+ panel : data . newPanel [ 0 ] ,
934
+ index : data . newTab . closest ( "li" ) . index ( )
935
+ } ) ;
923
936
} else if ( type === "activate" ) {
924
937
ret = _trigger . call ( this , "show" , event , data ) ;
925
938
}
0 commit comments