Skip to content

Commit d808f93

Browse files
committed
Accordion: Simplify _toggle() implementation.
1 parent e2560f6 commit d808f93

File tree

1 file changed

+24
-52
lines changed

1 file changed

+24
-52
lines changed

ui/jquery.ui.accordion.js

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $.widget( "ui.accordion", {
3131
var self = this,
3232
options = self.options;
3333

34-
self.running = 0;
34+
self.running = false;
3535

3636
self.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
3737

@@ -344,47 +344,13 @@ $.widget( "ui.accordion", {
344344
toHide = data.oldContent,
345345
down = toShow.length && ( !toHide.length || ( toShow.index() < toHide.index() ) );
346346

347-
self.toShow = toShow;
348-
self.toHide = toHide;
349-
self.data = data;
350-
351-
var complete = function() {
352-
if ( !self ) {
353-
return;
354-
}
355-
return self._completed.apply( self, arguments );
356-
};
357-
358-
// count elements to animate
359-
self.running = toHide.size() === 0 ? toShow.size() : toHide.size();
347+
self.running = true;
348+
function complete() {
349+
self._completed( data );
350+
}
360351

361352
if ( options.animated ) {
362-
var animOptions = {
363-
toShow: toShow,
364-
toHide: toHide,
365-
complete: complete,
366-
down: down,
367-
autoHeight: options.heightStyle !== "content"
368-
};
369-
370-
if ( !options.proxied ) {
371-
options.proxied = options.animated;
372-
}
373-
374-
if ( !options.proxiedDuration ) {
375-
options.proxiedDuration = options.duration;
376-
}
377-
378-
options.animated = $.isFunction( options.proxied ) ?
379-
options.proxied( animOptions ) :
380-
options.proxied;
381-
382-
options.duration = $.isFunction( options.proxiedDuration ) ?
383-
options.proxiedDuration( animOptions ) :
384-
options.proxiedDuration;
385-
386353
var animations = $.ui.accordion.animations,
387-
duration = options.duration,
388354
easing = options.animated;
389355

390356
if ( easing && !animations[ easing ] && !$.easing[ easing ] ) {
@@ -394,16 +360,22 @@ $.widget( "ui.accordion", {
394360
animations[ easing ] = function( options ) {
395361
this.slide( options, {
396362
easing: easing,
397-
duration: duration || 700
363+
duration: 700
398364
});
399365
};
400366
}
401367

402-
animations[ easing ]( animOptions );
368+
animations[ easing ]({
369+
toShow: toShow,
370+
toHide: toHide,
371+
complete: complete,
372+
down: down,
373+
autoHeight: options.heightStyle !== "content"
374+
});
403375
} else {
404376
toHide.hide();
405377
toShow.show();
406-
complete( true );
378+
complete();
407379
}
408380

409381
// TODO assert that the blur and focus triggers are really necessary, remove otherwise
@@ -421,27 +393,27 @@ $.widget( "ui.accordion", {
421393
.focus();
422394
},
423395

424-
_completed: function( cancel ) {
425-
this.running = cancel ? 0 : --this.running;
426-
if ( this.running ) {
427-
return;
428-
}
396+
_completed: function( data ) {
397+
var toShow = data.newContent,
398+
toHide = data.oldContent;
399+
400+
this.running = false;
429401

430402
if ( this.options.heightStyle === "content" ) {
431-
this.toShow.add( this.toHide ).css({
403+
toShow.add( toHide ).css({
432404
height: "",
433405
overflow: ""
434406
});
435407
}
436408

437409
// other classes are removed before the animation; this one needs to stay until completed
438-
this.toHide.removeClass( "ui-accordion-content-active" );
410+
toHide.removeClass( "ui-accordion-content-active" );
439411
// Work around for rendering bug in IE (#5421)
440-
if ( this.toHide.length ) {
441-
this.toHide.parent()[0].className = this.toHide.parent()[0].className;
412+
if ( toHide.length ) {
413+
toHide.parent()[0].className = toHide.parent()[0].className;
442414
}
443415

444-
this._trigger( "activate", null, this.data );
416+
this._trigger( "activate", null, data );
445417
}
446418
});
447419

0 commit comments

Comments
 (0)