@@ -262,7 +262,13 @@ $.widget( "ui.accordion", {
262
262
} ,
263
263
264
264
_activate : function ( index ) {
265
- var active = this . _findActive ( index ) [ 0 ] ;
265
+ var active = this . _findActive ( index ) [ 0 ] ,
266
+ eventData = {
267
+ oldHeader : this . active ,
268
+ oldContent : this . active . next ( ) ,
269
+ newHeader : $ ( ) ,
270
+ newContent : $ ( )
271
+ } ;
266
272
267
273
// we found a header to activate, just delegate to the event handler
268
274
if ( active ) {
@@ -282,34 +288,20 @@ $.widget( "ui.accordion", {
282
288
}
283
289
284
290
// allow the activation to be canceled
285
- var eventData = {
286
- oldHeader : this . active ,
287
- oldContent : this . active . next ( ) ,
288
- newHeader : $ ( ) ,
289
- newContent : $ ( )
290
- } ;
291
291
if ( this . _trigger ( "beforeActivate" , null , eventData ) === false ) {
292
292
return ;
293
293
}
294
294
295
- this . options . active = false ;
296
295
this . active
297
296
. removeClass ( "ui-state-active ui-corner-top" )
298
297
. addClass ( "ui-state-default ui-corner-all" )
299
298
. children ( ".ui-accordion-header-icon" )
300
299
. removeClass ( this . options . icons . activeHeader )
301
300
. addClass ( this . options . icons . header ) ;
302
301
this . active . next ( ) . addClass ( "ui-accordion-content-active" ) ;
303
- var toHide = this . active . next ( ) ,
304
- data = {
305
- options : this . options ,
306
- newHeader : $ ( ) ,
307
- oldHeader : this . active ,
308
- newContent : $ ( ) ,
309
- oldContent : toHide
310
- } ,
311
- toShow = ( this . active = $ ( ) ) ;
312
- this . _toggle ( toShow , toHide , data ) ;
302
+ this . options . active = false ;
303
+ this . active = $ ( ) ;
304
+ this . _toggle ( eventData ) ;
313
305
} ,
314
306
315
307
_findActive : function ( selector ) {
@@ -322,47 +314,33 @@ $.widget( "ui.accordion", {
322
314
clicked = $ ( event . currentTarget ) ,
323
315
clickedIsActive = clicked [ 0 ] === active [ 0 ] ,
324
316
collapsing = clickedIsActive && options . collapsible ,
325
- toShow = clicked . next ( ) ,
317
+ toShow = collapsing ? $ ( ) : clicked . next ( ) ,
326
318
toHide = active . next ( ) ,
327
319
eventData = {
328
320
oldHeader : active ,
329
321
oldContent : toHide ,
330
322
newHeader : collapsing ? $ ( ) : clicked ,
331
- newContent : collapsing ? $ ( ) : toShow
323
+ newContent : toShow
332
324
} ;
333
325
334
326
event . preventDefault ( ) ;
335
327
336
- if ( options . disabled ) {
337
- return ;
338
- }
339
-
340
- // if animations are still active, or the active header is the target, ignore click
341
- if ( this . running || ( ! options . collapsible && clickedIsActive ) ) {
342
- return ;
343
- }
344
-
345
- // allow the activation to be canceled
346
- if ( this . _trigger ( "beforeActivate" , null , eventData ) === false ) {
328
+ if ( options . disabled ||
329
+ // can't switch during an animation
330
+ this . running ||
331
+ // click on active header, but not collapsible
332
+ ( clickedIsActive && ! options . collapsible ) ||
333
+ // allow canceling activation
334
+ ( this . _trigger ( "beforeActivate" , null , eventData ) === false ) ) {
347
335
return ;
348
336
}
349
337
350
338
options . active = collapsing ? false : this . headers . index ( clicked ) ;
351
339
352
- // find elements to show and hide
353
- var data = {
354
- options : options ,
355
- newHeader : collapsing ? $ ( ) : clicked ,
356
- oldHeader : active ,
357
- newContent : collapsing ? $ ( ) : toShow ,
358
- oldContent : toHide
359
- } ,
360
- down = this . headers . index ( active [ 0 ] ) > this . headers . index ( clicked [ 0 ] ) ;
361
-
362
340
// when the call to ._toggle() comes after the class changes
363
341
// it causes a very odd bug in IE 8 (see #6720)
364
342
this . active = clickedIsActive ? $ ( ) : clicked ;
365
- this . _toggle ( toShow , toHide , data , clickedIsActive , down ) ;
343
+ this . _toggle ( eventData ) ;
366
344
367
345
// switch classes
368
346
active
@@ -384,9 +362,12 @@ $.widget( "ui.accordion", {
384
362
}
385
363
} ,
386
364
387
- _toggle : function ( toShow , toHide , data , clickedIsActive , down ) {
365
+ _toggle : function ( data ) {
388
366
var self = this ,
389
- options = self . options ;
367
+ options = self . options ,
368
+ toShow = data . newContent ,
369
+ toHide = data . oldContent ,
370
+ down = toShow . length && ( ! toHide . length || ( toShow . index ( ) < toHide . index ( ) ) ) ;
390
371
391
372
self . toShow = toShow ;
392
373
self . toHide = toHide ;
@@ -403,25 +384,13 @@ $.widget( "ui.accordion", {
403
384
self . running = toHide . size ( ) === 0 ? toShow . size ( ) : toHide . size ( ) ;
404
385
405
386
if ( options . animated ) {
406
- var animOptions = { } ;
407
-
408
- if ( options . collapsible && clickedIsActive ) {
409
- animOptions = {
410
- toShow : $ ( ) ,
411
- toHide : toHide ,
412
- complete : complete ,
413
- down : down ,
414
- autoHeight : options . heightStyle !== "content"
415
- } ;
416
- } else {
417
- animOptions = {
418
- toShow : toShow ,
419
- toHide : toHide ,
420
- complete : complete ,
421
- down : down ,
422
- autoHeight : options . heightStyle !== "content"
423
- } ;
424
- }
387
+ var animOptions = {
388
+ toShow : toShow ,
389
+ toHide : toHide ,
390
+ complete : complete ,
391
+ down : down ,
392
+ autoHeight : options . heightStyle !== "content"
393
+ } ;
425
394
426
395
if ( ! options . proxied ) {
427
396
options . proxied = options . animated ;
@@ -457,13 +426,8 @@ $.widget( "ui.accordion", {
457
426
458
427
animations [ easing ] ( animOptions ) ;
459
428
} else {
460
- if ( options . collapsible && clickedIsActive ) {
461
- toShow . toggle ( ) ;
462
- } else {
463
- toHide . hide ( ) ;
464
- toShow . show ( ) ;
465
- }
466
-
429
+ toHide . hide ( ) ;
430
+ toShow . show ( ) ;
467
431
complete ( true ) ;
468
432
}
469
433
0 commit comments