Skip to content

Commit

Permalink
Accordion: modified the _clickhandler and the _toggle routines so tha…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
SirPyros committed Aug 6, 2010
1 parent 3be1105 commit d777d0e
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions ui/jquery.ui.accordion.js
Expand Up @@ -311,13 +311,7 @@ $.widget( "ui.accordion", {
if ( !options.collapsible ) {
return;
}
this.active
.removeClass( "ui-state-active ui-corner-top" )
.addClass( "ui-state-default ui-corner-all" )
.children( ".ui-icon" )
.removeClass( options.icons.headerSelected )
.addClass( options.icons.header );
this.active.next().addClass( "ui-accordion-content-active" );
// **CHANGE** Moved the class switch to the if statement below
var toHide = this.active.next(),
data = {
options: options,
Expand All @@ -327,7 +321,16 @@ $.widget( "ui.accordion", {
oldContent: toHide
},
toShow = ( this.active = $( [] ) );
this._toggle( toShow, toHide, data );
// **CHANGE** _toggle now returns a boolean
if(this._toggle( toShow, toHide, data )){
this.active
.removeClass( "ui-state-active ui-corner-top" )
.addClass( "ui-state-default ui-corner-all" )
.children( ".ui-icon" )
.removeClass( options.icons.headerSelected )
.addClass( options.icons.header );
this.active.next().addClass( "ui-accordion-content-active" );
}
return;
}

Expand All @@ -346,24 +349,8 @@ $.widget( "ui.accordion", {
return;
}

// switch classes
this.active
.removeClass( "ui-state-active ui-corner-top" )
.addClass( "ui-state-default ui-corner-all" )
.children( ".ui-icon" )
.removeClass( options.icons.headerSelected )
.addClass( options.icons.header );
if ( !clickedIsActive ) {
clicked
.removeClass( "ui-state-default ui-corner-all" )
.addClass( "ui-state-active ui-corner-top" )
.children( ".ui-icon" )
.removeClass( options.icons.header )
.addClass( options.icons.headerSelected );
clicked
.next()
.addClass( "ui-accordion-content-active" );
}
// **CHANGE** moved switch classes to if statement below


// find elements to show and hide
var toShow = clicked.next(),
Expand All @@ -376,17 +363,41 @@ $.widget( "ui.accordion", {
oldContent: toHide
},
down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] );

this.active = clickedIsActive ? $([]) : clicked;
this._toggle( toShow, toHide, data, clickedIsActive, down );
// **CHANGE** _toggle now returns a boolean
// **CHANGE** moved setting this.active = clickedIsActive ? $([]) : clicked; to inside the if statement
if(this._toggle( toShow, toHide, data, clickedIsActive, down )){
this.active = clickedIsActive ? $([]) : clicked;
this.active
.removeClass( "ui-state-active ui-corner-top" )
.addClass( "ui-state-default ui-corner-all" )
.children( ".ui-icon" )
.removeClass( options.icons.headerSelected )
.addClass( options.icons.header );
if ( !clickedIsActive ) {
clicked
.removeClass( "ui-state-default ui-corner-all" )
.addClass( "ui-state-active ui-corner-top" )
.children( ".ui-icon" )
.removeClass( options.icons.header )
.addClass( options.icons.headerSelected );
clicked
.next()
.addClass( "ui-accordion-content-active" );
}
}

return;
},

_toggle: function( toShow, toHide, data, clickedIsActive, down ) {
var self = this,
options = self.options;


// **CHANGE** _toggle now returns a boolean
// **CHANGE** moved the trigger changestart event
// **CHANGE** if event.IsPreventDefaulted then return false
if (self._trigger( "changestart", null, data )) return false;

This comment has been minimized.

Copy link
@SirPyros

SirPyros Oct 27, 2010

Author Owner

this line should be if (!self._trigger( "changestart", null, data )) return false;


self.toShow = toShow;
self.toHide = toHide;
self.data = data;
Expand All @@ -398,9 +409,6 @@ $.widget( "ui.accordion", {
return self._completed.apply( self, arguments );
};

// trigger changestart event
self._trigger( "changestart", null, self.data );

// count elements to animate
self.running = toHide.size() === 0 ? toShow.size() : toHide.size();

Expand Down Expand Up @@ -482,6 +490,9 @@ $.widget( "ui.accordion", {
tabIndex: 0
})
.focus();

// **CHANGE** return true so conditions fire correctly.
return true;
},

_completed: function( cancel ) {
Expand Down

1 comment on commit d777d0e

@SirPyros
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a small bug. The Icons aren't changing properly. Need to move line 368 to be under line 385. The this.active = clickedIsActive ? $([]) : clicked; line needs to be the last statement in the if block.

Please sign in to comment.