Skip to content

Commit e2a9b0c

Browse files
committed
Merge pull request jquery#368 from kborchers/bug_3532_2
Accordion: Stop current hide animation, jump to last animation and calculate percentages for padding in addition to height. Fixes #3532 - Accordion: Activating a panel during animation fails
2 parents 8224c67 + 5f02a8f commit e2a9b0c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

ui/jquery.ui.accordion.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* jquery.ui.widget.js
1313
*/
1414
(function( $, undefined ) {
15+
16+
var lastToggle = {};
1517

1618
// TODO: use ui-accordion-header-active class and fix styling
1719
$.widget( "ui.accordion", {
@@ -37,8 +39,6 @@ $.widget( "ui.accordion", {
3739
var self = this,
3840
options = self.options;
3941

40-
self.running = false;
41-
4242
self.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
4343

4444
self.headers = self.element.find( options.header )
@@ -321,8 +321,6 @@ $.widget( "ui.accordion", {
321321
event.preventDefault();
322322

323323
if ( options.disabled ||
324-
// can't switch during an animation
325-
this.running ||
326324
// click on active header, but not collapsible
327325
( clickedIsActive && !options.collapsible ) ||
328326
// allow canceling activation
@@ -363,7 +361,6 @@ $.widget( "ui.accordion", {
363361
toShow = data.newContent,
364362
toHide = data.oldContent;
365363

366-
self.running = true;
367364
function complete() {
368365
self._completed( data );
369366
}
@@ -384,6 +381,8 @@ $.widget( "ui.accordion", {
384381
animations[ animation ]({
385382
toShow: toShow,
386383
toHide: toHide,
384+
prevShow: lastToggle.toShow,
385+
prevHide: lastToggle.toHide,
387386
complete: complete,
388387
down: toShow.length && ( !toHide.length || ( toShow.index() < toHide.index() ) )
389388
}, additional );
@@ -414,8 +413,6 @@ $.widget( "ui.accordion", {
414413
var toShow = data.newContent,
415414
toHide = data.oldContent;
416415

417-
this.running = false;
418-
419416
if ( this.options.heightStyle === "content" ) {
420417
toShow.add( toHide ).css({
421418
height: "",
@@ -437,6 +434,11 @@ $.widget( "ui.accordion", {
437434
$.extend( $.ui.accordion, {
438435
animations: {
439436
slide: function( options, additions ) {
437+
if ( options.prevShow || options.prevHide ) {
438+
options.prevHide.stop( true, true );
439+
options.toHide = options.prevShow;
440+
}
441+
440442
var showOverflow = options.toShow.css( "overflow" ),
441443
hideOverflow = options.toHide.css( "overflow" ),
442444
percentDone = 0,
@@ -448,6 +450,9 @@ $.extend( $.ui.accordion, {
448450
easing: "swing",
449451
duration: 300
450452
}, options, additions );
453+
454+
lastToggle = options;
455+
451456
if ( !options.toHide.size() ) {
452457
originalWidth = options.toShow[0].style.width;
453458
options.toShow
@@ -504,10 +509,7 @@ $.extend( $.ui.accordion, {
504509
.filter( ":visible" )
505510
.animate( hideProps, {
506511
step: function( now, settings ) {
507-
// only calculate the percent when animating height
508-
// IE gets very inconsistent results when animating elements
509-
// with small values, which is common for padding
510-
if ( settings.prop == "height" ) {
512+
if ( settings.prop == "height" || settings.prop == "paddingTop" || settings.prop == "paddingBottom" ) {
511513
percentDone = ( settings.end - settings.start === 0 ) ? 0 :
512514
( settings.now - settings.start ) / ( settings.end - settings.start );
513515
}

0 commit comments

Comments
 (0)