Skip to content

Commit d777d0e

Browse files
committed
Accordion: modified the _clickhandler and the _toggle routines so that called event.preventDefault() in the changestart event disables changing the state of the accordion. I have identified all of the changes with // **CHANGES** comments
Ticket #5910 Ticket Name: Accordion: check for event.preventDefault in changestart.
1 parent 3be1105 commit d777d0e

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

ui/jquery.ui.accordion.js

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,7 @@ $.widget( "ui.accordion", {
311311
if ( !options.collapsible ) {
312312
return;
313313
}
314-
this.active
315-
.removeClass( "ui-state-active ui-corner-top" )
316-
.addClass( "ui-state-default ui-corner-all" )
317-
.children( ".ui-icon" )
318-
.removeClass( options.icons.headerSelected )
319-
.addClass( options.icons.header );
320-
this.active.next().addClass( "ui-accordion-content-active" );
314+
// **CHANGE** Moved the class switch to the if statement below
321315
var toHide = this.active.next(),
322316
data = {
323317
options: options,
@@ -327,7 +321,16 @@ $.widget( "ui.accordion", {
327321
oldContent: toHide
328322
},
329323
toShow = ( this.active = $( [] ) );
330-
this._toggle( toShow, toHide, data );
324+
// **CHANGE** _toggle now returns a boolean
325+
if(this._toggle( toShow, toHide, data )){
326+
this.active
327+
.removeClass( "ui-state-active ui-corner-top" )
328+
.addClass( "ui-state-default ui-corner-all" )
329+
.children( ".ui-icon" )
330+
.removeClass( options.icons.headerSelected )
331+
.addClass( options.icons.header );
332+
this.active.next().addClass( "ui-accordion-content-active" );
333+
}
331334
return;
332335
}
333336

@@ -346,24 +349,8 @@ $.widget( "ui.accordion", {
346349
return;
347350
}
348351

349-
// switch classes
350-
this.active
351-
.removeClass( "ui-state-active ui-corner-top" )
352-
.addClass( "ui-state-default ui-corner-all" )
353-
.children( ".ui-icon" )
354-
.removeClass( options.icons.headerSelected )
355-
.addClass( options.icons.header );
356-
if ( !clickedIsActive ) {
357-
clicked
358-
.removeClass( "ui-state-default ui-corner-all" )
359-
.addClass( "ui-state-active ui-corner-top" )
360-
.children( ".ui-icon" )
361-
.removeClass( options.icons.header )
362-
.addClass( options.icons.headerSelected );
363-
clicked
364-
.next()
365-
.addClass( "ui-accordion-content-active" );
366-
}
352+
// **CHANGE** moved switch classes to if statement below
353+
367354

368355
// find elements to show and hide
369356
var toShow = clicked.next(),
@@ -376,17 +363,41 @@ $.widget( "ui.accordion", {
376363
oldContent: toHide
377364
},
378365
down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] );
379-
380-
this.active = clickedIsActive ? $([]) : clicked;
381-
this._toggle( toShow, toHide, data, clickedIsActive, down );
366+
// **CHANGE** _toggle now returns a boolean
367+
// **CHANGE** moved setting this.active = clickedIsActive ? $([]) : clicked; to inside the if statement
368+
if(this._toggle( toShow, toHide, data, clickedIsActive, down )){
369+
this.active = clickedIsActive ? $([]) : clicked;
370+
this.active
371+
.removeClass( "ui-state-active ui-corner-top" )
372+
.addClass( "ui-state-default ui-corner-all" )
373+
.children( ".ui-icon" )
374+
.removeClass( options.icons.headerSelected )
375+
.addClass( options.icons.header );
376+
if ( !clickedIsActive ) {
377+
clicked
378+
.removeClass( "ui-state-default ui-corner-all" )
379+
.addClass( "ui-state-active ui-corner-top" )
380+
.children( ".ui-icon" )
381+
.removeClass( options.icons.header )
382+
.addClass( options.icons.headerSelected );
383+
clicked
384+
.next()
385+
.addClass( "ui-accordion-content-active" );
386+
}
387+
}
382388

383389
return;
384390
},
385-
391+
386392
_toggle: function( toShow, toHide, data, clickedIsActive, down ) {
387393
var self = this,
388394
options = self.options;
389-
395+
396+
// **CHANGE** _toggle now returns a boolean
397+
// **CHANGE** moved the trigger changestart event
398+
// **CHANGE** if event.IsPreventDefaulted then return false
399+
if (self._trigger( "changestart", null, data )) return false;
400+
390401
self.toShow = toShow;
391402
self.toHide = toHide;
392403
self.data = data;
@@ -398,9 +409,6 @@ $.widget( "ui.accordion", {
398409
return self._completed.apply( self, arguments );
399410
};
400411

401-
// trigger changestart event
402-
self._trigger( "changestart", null, self.data );
403-
404412
// count elements to animate
405413
self.running = toHide.size() === 0 ? toShow.size() : toHide.size();
406414

@@ -482,6 +490,9 @@ $.widget( "ui.accordion", {
482490
tabIndex: 0
483491
})
484492
.focus();
493+
494+
// **CHANGE** return true so conditions fire correctly.
495+
return true;
485496
},
486497

487498
_completed: function( cancel ) {

0 commit comments

Comments
 (0)