@@ -277,14 +277,37 @@ $.widget( "ui.accordion", {
277
277
278
278
_activate : function ( index ) {
279
279
var active = this . _findActive ( index ) [ 0 ] ;
280
- if ( ! active ) {
281
- if ( ! this . options . collapsible ) {
282
- return ;
280
+
281
+ // we found a header to activate, just delegate to the event handler
282
+ if ( active ) {
283
+ if ( active !== this . active [ 0 ] ) {
284
+ this . _eventHandler ( { target : active , currentTarget : active } ) ;
283
285
}
284
- index = false ;
286
+ return ;
285
287
}
286
- this . options . active = index ;
287
- this . _eventHandler ( { target : active , currentTarget : active } ) ;
288
+
289
+ // no header to activate, check if we can collapse
290
+ if ( ! this . options . collapsible ) {
291
+ return ;
292
+ }
293
+
294
+ this . active
295
+ . removeClass ( "ui-state-active ui-corner-top" )
296
+ . addClass ( "ui-state-default ui-corner-all" )
297
+ . children ( ".ui-icon" )
298
+ . removeClass ( this . options . icons . activeHeader )
299
+ . addClass ( this . options . icons . header ) ;
300
+ this . active . next ( ) . addClass ( "ui-accordion-content-active" ) ;
301
+ var toHide = this . active . next ( ) ,
302
+ data = {
303
+ options : this . options ,
304
+ newHeader : $ ( [ ] ) ,
305
+ oldHeader : this . active ,
306
+ newContent : $ ( [ ] ) ,
307
+ oldContent : toHide
308
+ } ,
309
+ toShow = ( this . active = $ ( [ ] ) ) ;
310
+ this . _toggle ( toShow , toHide , data ) ;
288
311
} ,
289
312
290
313
// TODO: add tests/docs for negative values in 2.0 (#6854)
@@ -293,51 +316,23 @@ $.widget( "ui.accordion", {
293
316
} ,
294
317
295
318
_eventHandler : function ( event ) {
296
- var options = this . options ;
319
+ var options = this . options ,
320
+ clicked = $ ( event . currentTarget ) ,
321
+ clickedIsActive = clicked [ 0 ] === this . active [ 0 ] ;
322
+
297
323
if ( options . disabled ) {
298
324
return ;
299
325
}
300
326
301
- // called only when using activate(false) to close all parts programmatically
302
- if ( ! event . target ) {
303
- if ( ! options . collapsible ) {
304
- return ;
305
- }
306
- this . active
307
- . removeClass ( "ui-state-active ui-corner-top" )
308
- . addClass ( "ui-state-default ui-corner-all" )
309
- . children ( ".ui-icon" )
310
- . removeClass ( options . icons . activeHeader )
311
- . addClass ( options . icons . header ) ;
312
- this . active . next ( ) . addClass ( "ui-accordion-content-active" ) ;
313
- var toHide = this . active . next ( ) ,
314
- data = {
315
- options : options ,
316
- newHeader : $ ( [ ] ) ,
317
- oldHeader : options . active ,
318
- newContent : $ ( [ ] ) ,
319
- oldContent : toHide
320
- } ,
321
- toShow = ( this . active = $ ( [ ] ) ) ;
322
- this . _toggle ( toShow , toHide , data ) ;
327
+ // if animations are still active, or the active header is the target, ignore click
328
+ if ( this . running || ( ! options . collapsible && clickedIsActive ) ) {
323
329
return ;
324
330
}
325
331
326
- // get the click target
327
- var clicked = $ ( event . currentTarget ) ,
328
- clickedIsActive = clicked [ 0 ] === this . active [ 0 ] ;
329
-
330
- // TODO the option is changed, is that correct?
331
- // TODO if it is correct, shouldn't that happen after determining that the click is valid?
332
332
options . active = options . collapsible && clickedIsActive ?
333
333
false :
334
334
this . headers . index ( clicked ) ;
335
335
336
- // if animations are still active, or the active header is the target, ignore click
337
- if ( this . running || ( ! options . collapsible && clickedIsActive ) ) {
338
- return ;
339
- }
340
-
341
336
// find elements to show and hide
342
337
var active = this . active ,
343
338
toShow = clicked . next ( ) ,
@@ -374,8 +369,6 @@ $.widget( "ui.accordion", {
374
369
. next ( )
375
370
. addClass ( "ui-accordion-content-active" ) ;
376
371
}
377
-
378
- return ;
379
372
} ,
380
373
381
374
_toggle : function ( toShow , toHide , data , clickedIsActive , down ) {
0 commit comments