Skip to content

Commit

Permalink
Set val before hide/show check and fix easing setting; also update at…
Browse files Browse the repository at this point in the history
…tributes test for autofocus

- The object passed should not change so it can be used in future animates, updated src and tests accordingly.
  • Loading branch information
timmywil committed May 8, 2011
1 parent 3d1c27d commit 8bb6e95
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
34 changes: 17 additions & 17 deletions src/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jQuery.fn.extend({
jQuery._mark( this );
}

var opt = jQuery.extend({}, optall),
var opt = jQuery.extend( {}, optall ),
isElement = this.nodeType === 1,
hidden = isElement && jQuery(this).is(":hidden"),
name, val, p,
Expand All @@ -153,10 +153,18 @@ jQuery.fn.extend({
delete prop[ p ];
}

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 ) {
return opt.complete.call(this);
return opt.complete.call( this );
}

if ( isElement && ( name === "height" || name === "width" ) ) {
Expand All @@ -175,7 +183,7 @@ jQuery.fn.extend({
this.style.display = "inline-block";

} else {
display = defaultDisplay(this.nodeName);
display = defaultDisplay( this.nodeName );

// inline-level elements accept inline-block;
// block-level elements need to be inline with layout
Expand All @@ -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 ) {
Expand All @@ -205,13 +205,13 @@ jQuery.fn.extend({

for ( p in prop ) {
e = new jQuery.fx( this, opt, p );
val = prop[p];
val = prop[ p ];

if ( rfxtypes.test(val) ) {
e[ val === "toggle" ? hidden ? "show" : "hide" : val ]();

} else {
parts = rfxnum.exec(val);
parts = rfxnum.exec( val );
start = e.cur();

if ( parts ) {
Expand All @@ -227,7 +227,7 @@ jQuery.fn.extend({

// If a +=/-= token was provided, we're doing a relative animation
if ( parts[1] ) {
end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
}

e.custom( start, end, unit );
Expand Down Expand Up @@ -503,10 +503,10 @@ jQuery.fx.prototype = {
this.now = t;
} else {
n = t - this.startTime;

this.state = n / options.duration;

// 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);
}
// Perform the next step of the animation
Expand Down
10 changes: 7 additions & 3 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ test("attr(Hash)", function() {
if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) pass = false;
});
ok( pass, "Set Multiple Attributes" );
equals( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
equals( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2");
equals( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
equals( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2");

});

Expand Down Expand Up @@ -211,7 +211,11 @@ test("attr(String, Object)", function() {
$p.removeAttr("nonexisting");

var $text = jQuery("#text1").attr("autofocus", true);
equals( $text.attr("autofocus"), "autofocus", "Set boolean attributes to the same name");
if ( "autofocus" in $text[0] ) {
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("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" );
Expand Down
27 changes: 12 additions & 15 deletions test/unit/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ jQuery.each( {
jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
return 0;
}
}, function(fn, f){
jQuery.each( {
}, function( fn, f ) {
jQuery.each({
"show": function(elem,prop){
jQuery(elem).hide().addClass("wide"+prop);
return "show";
Expand Down Expand Up @@ -923,16 +923,17 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()

test("animate with per-property easing", function(){

expect(5);
expect(3);
stop();

var data = {a:0,b:0,c:0};
var _test1_called = false;
var _test2_called = false;
var _default_test_called = false;
var data = { a:0, b:0, c:0 },
_test1_called = false,
_test2_called = false,
_default_test_called = false;

jQuery.easing["_test1"] = function() {
jQuery.easing["_test1"] = function(p) {
_test1_called = true;
return p;
};

jQuery.easing["_test2"] = function(p) {
Expand All @@ -952,13 +953,9 @@ test("animate with per-property easing", function(){
}, 400, "_default_test", function(){
start();

ok(_test1_called, "Easing function (1) 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(data.c == 100, "Easing function (_default) assigned correct value");
ok( _test1_called, "Easing function (_test1) called" );
ok( _test2_called, "Easing function (_test2) called" );
ok( _default_test_called, "Easing function (_default) called" );
});

});
Expand Down

0 comments on commit 8bb6e95

Please sign in to comment.