Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accordion: Attempt at improving animation. #587

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Accordion: Changed option name to animate and added back-compat for a…
…nimated option.
  • Loading branch information
scottgonzalez committed Feb 16, 2012
commit af94c375085b0c800fbdfb4e7c945eb7b542ad08
2 changes: 1 addition & 1 deletion tests/unit/accordion/accordion_defaults.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
commonWidgetTests( "accordion", {
defaults: {
active: 0,
animated: "slide",
animate: {},
collapsible: false,
disabled: false,
event: "click",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/accordion/accordion_defaults_deprecated.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
commonWidgetTests( "accordion", {
defaults: {
active: 0,
animate: null,
animated: "slide",
autoHeight: true,
clearStyle: false,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/accordion/accordion_test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function accordion_equalHeights( accordion, min, max ) {
}

function accordion_setupTeardown() {
var animated = $.ui.accordion.prototype.options.animated;
var animate = $.ui.accordion.prototype.options.animate;
return {
setup: function() {
$.ui.accordion.prototype.options.animated = false;
$.ui.accordion.prototype.options.animate = false;
},
teardown: function() {
$.ui.accordion.prototype.options.animated = animated;
$.ui.accordion.prototype.options.animate = animate;
}
};
}
49 changes: 40 additions & 9 deletions ui/jquery.ui.accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ $.widget( "ui.accordion", {
version: "@VERSION",
options: {
active: 0,
// TODO: animation option
animated: "slide",
animate: {},
collapsible: false,
event: "click",
header: "> li > :first-child,> :not(li):even",
Expand Down Expand Up @@ -374,9 +373,7 @@ $.widget( "ui.accordion", {
this.prevShow = toShow;
this.prevHide = toHide;

if ( this.options.animated ) {
// TODO: back compat for animated option
// TODO: back compat for bounceslide
if ( this.options.animate ) {
this._animate( toShow, toHide, data );
} else {
toHide.hide();
Expand Down Expand Up @@ -406,8 +403,8 @@ $.widget( "ui.accordion", {
that = this,
down = toShow.length &&
( !toHide.length || ( toShow.index() < toHide.index() ) ),
animation = this.options.animation || {},
options = down && animation.down || animation,
animate = this.options.animate || {},
options = down && animate.down || animate,
complete = function() {
toShow.removeData( "accordionHeight" );
that._completed( data );
Expand All @@ -420,8 +417,8 @@ $.widget( "ui.accordion", {
easing = options;
}
// fall back from options to animation in case of partial down settings
easing = easing || options.easing || animation.easing;
duration = duration || options.duration || animation.duration;
easing = easing || options.easing || animate.easing;
duration = duration || options.duration || animate.duration;

if ( !toHide.size() ) {
return toShow.animate( showProps, duration, easing, complete );
Expand Down Expand Up @@ -613,6 +610,40 @@ if ( $.uiBackCompat !== false ) {
return ret;
};
}( jQuery, jQuery.ui.accordion.prototype ) );

// animated option
// NOTE: this only provides support for "slide", "bounceslide", and easings
// not the full $.ui.accordion.animations API
(function( $, prototype ) {
$.extend( prototype.options, {
animate: null,
animated: "slide"
});

var _create = prototype._create;
prototype._create = function() {
var options = this.options;
if ( options.animate === null ) {
if ( !options.animated ) {
options.animate = false;
} else if ( options.animated === "slide" ) {
options.animate = 300;
} else if ( options.animated === "bounceslide" ) {
options.animate = {
duration: 200,
down: {
easing: "easeOutBounce",
duration: 1000
}
}
} else {
options.animate = options.animated;
}
}

_create.call( this );
};
}( jQuery, jQuery.ui.accordion.prototype ) );
}

})( jQuery );