Skip to content

Commit 5f02a8f

Browse files
committed
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
1 parent fb210ae commit 5f02a8f

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 )
@@ -319,8 +319,6 @@ $.widget( "ui.accordion", {
319319
event.preventDefault();
320320

321321
if ( options.disabled ||
322-
// can't switch during an animation
323-
this.running ||
324322
// click on active header, but not collapsible
325323
( clickedIsActive && !options.collapsible ) ||
326324
// allow canceling activation
@@ -361,7 +359,6 @@ $.widget( "ui.accordion", {
361359
toShow = data.newContent,
362360
toHide = data.oldContent;
363361

364-
self.running = true;
365362
function complete() {
366363
self._completed( data );
367364
}
@@ -382,6 +379,8 @@ $.widget( "ui.accordion", {
382379
animations[ animation ]({
383380
toShow: toShow,
384381
toHide: toHide,
382+
prevShow: lastToggle.toShow,
383+
prevHide: lastToggle.toHide,
385384
complete: complete,
386385
down: toShow.length && ( !toHide.length || ( toShow.index() < toHide.index() ) )
387386
}, additional );
@@ -412,8 +411,6 @@ $.widget( "ui.accordion", {
412411
var toShow = data.newContent,
413412
toHide = data.oldContent;
414413

415-
this.running = false;
416-
417414
if ( this.options.heightStyle === "content" ) {
418415
toShow.add( toHide ).css({
419416
height: "",
@@ -435,6 +432,11 @@ $.widget( "ui.accordion", {
435432
$.extend( $.ui.accordion, {
436433
animations: {
437434
slide: function( options, additions ) {
435+
if ( options.prevShow || options.prevHide ) {
436+
options.prevHide.stop( true, true );
437+
options.toHide = options.prevShow;
438+
}
439+
438440
var showOverflow = options.toShow.css( "overflow" ),
439441
hideOverflow = options.toHide.css( "overflow" ),
440442
percentDone = 0,
@@ -446,6 +448,9 @@ $.extend( $.ui.accordion, {
446448
easing: "swing",
447449
duration: 300
448450
}, options, additions );
451+
452+
lastToggle = options;
453+
449454
if ( !options.toHide.size() ) {
450455
originalWidth = options.toShow[0].style.width;
451456
options.toShow
@@ -502,10 +507,7 @@ $.extend( $.ui.accordion, {
502507
.filter( ":visible" )
503508
.animate( hideProps, {
504509
step: function( now, settings ) {
505-
// only calculate the percent when animating height
506-
// IE gets very inconsistent results when animating elements
507-
// with small values, which is common for padding
508-
if ( settings.prop == "height" ) {
510+
if ( settings.prop == "height" || settings.prop == "paddingTop" || settings.prop == "paddingBottom" ) {
509511
percentDone = ( settings.end - settings.start === 0 ) ? 0 :
510512
( settings.now - settings.start ) / ( settings.end - settings.start );
511513
}

0 commit comments

Comments
 (0)