Set val before hide/show check and fix easing setting; also update attributes test for autofocus

- The object passed should not change so it can be used in future animates, updated src and tests accordingly.
This commit is contained in:
timmywil 2011-05-07 20:46:38 -04:00
parent 3d1c27d52e
commit 8bb6e95b66
3 changed files with 36 additions and 35 deletions

18
src/effects.js vendored
View file

@ -155,6 +155,14 @@ jQuery.fn.extend({
val = prop[ name ]; val = prop[ name ];
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
if ( jQuery.isArray( val ) ) {
opt.animatedProperties[ name ] = val[ 1 ];
val = val[ 0 ];
} else {
opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || 'swing';
}
if ( val === "hide" && hidden || val === "show" && !hidden ) { if ( val === "hide" && hidden || val === "show" && !hidden ) {
return opt.complete.call( this ); return opt.complete.call( this );
} }
@ -189,14 +197,6 @@ jQuery.fn.extend({
} }
} }
} }
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
if(jQuery.isArray(val)) {
opt.animatedProperties[name] = val[1];
prop[name] = val[0];
} else {
opt.animatedProperties[name] = easing || opt.specialEasing && opt.specialEasing[name] || opt.easing || 'swing';
}
} }
if ( opt.overflow != null ) { if ( opt.overflow != null ) {
@ -503,8 +503,8 @@ jQuery.fx.prototype = {
this.now = t; this.now = t;
} else { } else {
n = t - this.startTime; n = t - this.startTime;
this.state = n / options.duration; this.state = n / options.duration;
// Perform the easing function, defaults to swing // Perform the easing function, defaults to swing
this.pos = jQuery.easing[ options.animatedProperties[ this.prop ] ]( this.state, n, 0, 1, options.duration ); this.pos = jQuery.easing[ options.animatedProperties[ this.prop ] ]( this.state, n, 0, 1, options.duration );
this.now = this.start + ((this.end - this.start) * this.pos); this.now = this.start + ((this.end - this.start) * this.pos);

View file

@ -211,7 +211,11 @@ test("attr(String, Object)", function() {
$p.removeAttr("nonexisting"); $p.removeAttr("nonexisting");
var $text = jQuery("#text1").attr("autofocus", true); var $text = jQuery("#text1").attr("autofocus", true);
if ( "autofocus" in $text[0] ) {
equals( $text.attr("autofocus"), "autofocus", "Set boolean attributes to the same name"); equals( $text.attr("autofocus"), "autofocus", "Set boolean attributes to the same name");
} else {
equals( $text.attr("autofocus"), undefined, "autofocus stays undefined in browsers that do not support it(F<4)");
}
equals( $text.attr("autofocus", false).attr("autofocus"), undefined, "Setting autofocus attribute to false removes it"); equals( $text.attr("autofocus", false).attr("autofocus"), undefined, "Setting autofocus attribute to false removes it");
equals( $text.attr("data-something", true).data("something"), true, "Setting data attributes are not affected by boolean settings"); equals( $text.attr("data-something", true).data("something"), true, "Setting data attributes are not affected by boolean settings");
equals( $text.attr("data-another", false).data("another"), false, "Setting data attributes are not affected by boolean settings" ); equals( $text.attr("data-another", false).data("another"), false, "Setting data attributes are not affected by boolean settings" );

21
test/unit/effects.js vendored
View file

@ -923,16 +923,17 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
test("animate with per-property easing", function(){ test("animate with per-property easing", function(){
expect(5); expect(3);
stop(); stop();
var data = {a:0,b:0,c:0}; var data = { a:0, b:0, c:0 },
var _test1_called = false; _test1_called = false,
var _test2_called = false; _test2_called = false,
var _default_test_called = false; _default_test_called = false;
jQuery.easing["_test1"] = function() { jQuery.easing["_test1"] = function(p) {
_test1_called = true; _test1_called = true;
return p;
}; };
jQuery.easing["_test2"] = function(p) { jQuery.easing["_test2"] = function(p) {
@ -952,13 +953,9 @@ test("animate with per-property easing", function(){
}, 400, "_default_test", function(){ }, 400, "_default_test", function(){
start(); start();
ok(_test1_called, "Easing function (1) called"); ok( _test1_called, "Easing function (_test1) called" );
ok( _test2_called, "Easing function (_test2) called" );
ok(_test2_called, "Easing function (2) called");
ok(data.b == 100, "Easing function (2) assigned correct value");
ok( _default_test_called, "Easing function (_default) called" ); ok( _default_test_called, "Easing function (_default) called" );
ok(data.c == 100, "Easing function (_default) assigned correct value");
}); });
}); });