Bug Tracker

Opened 15 years ago

Closed 14 years ago

#2042 closed bug (fixed)

callback parameter doesn't match on animate functions

Reported by: beat Owned by:
Priority: major Milestone: 1.2.4
Component: effects Version: 1.2.1
Keywords: animate parameters Cc:
Blocked by: Blocking:

Description

Sorry to bother, maybe i'm seing wrong, but callback parameter doesn't match on animate function's parameter, it goes into "easing":

fadeTo: function(speed,to,callback){

return this.animate({opacity: to}, speed, callback);

},

animate: function( prop, speed, easing, callback ) {

slideDown, slideUp, slideToggle, fadeIn, fadeO, fadeTo functions seem to have same bug.

Change History (12)

comment:1 Changed 15 years ago by davidserduke

need: ReviewTest Case
Resolution: worksforme
Status: newclosed

Are you seeing a bug associated with this or is this from looking at the code?

If it is the former then please put together a descrition or test case of the problem. If it is the latter then read on.

If you look at the wiki documentation:

http://docs.jquery.com/Effects/animate#paramsdurationeasingcallback

You'll see the easing parameter is optional. The way jQuery handles optional parameter is through parameter testing. So in this case, if you look at the first line of the animate() function:

http://dev.jquery.com/browser/trunk/jquery/src/fx.js#L69

You'll see

var optall = jQuery.speed(speed, easing, callback);

which is the optional parameters passed in to the .speed() function.

Now if you look at the .speed() function

http://dev.jquery.com/browser/trunk/jquery/src/fx.js#L212

you'll see various parameter checking to make sure functions exist and such. It can get pretty complicated with multiple optional parameters which most of jQuery does not do. Typically there is only one optional parameter.

var opt = speed && speed.constructor == Object ? speed : { 
        complete: fn || !fn && easing ||  
                  jQuery.isFunction( speed ) && speed, 
        duration: speed, 
        easing: fn && easing || easing && easing.constructor != Function && easing 
     }; 

This code above handles the optional parameters.

That said, if you see an actual problem please feel free to reopen the ticket with a test case. Hope that helps explain what's going on because I agree it can be complicated in this instance.

comment:2 Changed 15 years ago by tgdavies

Resolution: worksforme
Status: closedreopened

This does cause a problem, as hide(), for instance, doesn't pass an easing parameter, so if the callback is provided, then animate() gets confused.

The error message I get is: Value undefined (result of expression jQuery.easing[this.options.easing
(jQuery.easing.swing ? "swing" : "linear")]) is not object.

And the element disappears all at once. I think the problem is that hide() doesn't pass an 'easing' parameter to animate() -- this is ok when there's no callback, but when there is a callback animate() confuses the callback with the easing param. I can fix the problem by passing null for the easing param at line 2888

comment:3 Changed 15 years ago by davidserduke

Can you provide a test case or some code that shows what the problem is? What exactly are you writing that gives you an error?

comment:4 Changed 15 years ago by tgdavies

I'm getting this problem when I wrap hide() using GWT. The GWT code is:

public class JQuery
{
    public static interface Callback {
        public void fn();
    }
    public static native void hide(Element e, int speed, Callback callback) /*-{
       $wnd.jQuery(e).hide(speed, function() { [email protected]::fn()(); });
    }-*/;
}

Which may not mean too much to you if you aren't familiar with GWT.

The generated code is:

function hide(e, speed, callback){
  $wnd.jQuery(e).hide(speed, function(){
    callback.fn();
  }
  );
}

Note the use of $wnd -- the compiled GWT Javascript runs in a nested frame, and $wnd refers to the host window -- perhaps that's the problem?

Note that I *can* fix the problem by modifying hide() so that it explicitly passes null to animate for the easing parameter.

comment:5 Changed 15 years ago by davidserduke

Hmm, I haven't done much more with GWT then install it and run a few examples so...

But I agree it sounds like a frame issue. I see in jQuery.speed() it says:

  easing: fn && easing || easing && easing.constructor != Function && easing

I wonder why that last easing is there? Anyway that's off topic. Can you try patching it to this?

  easing: fn && easing || easing && !jQuery.isFunction(easing.constructor)

The != Function part looks to me like it would fail across frames.

comment:6 Changed 15 years ago by tgdavies

Hi David,

That change fixes the problem.

Will it get committed?

Regards,

Tom

comment:7 Changed 15 years ago by tgdavies

easing: fn && easing || easing && !jQuery.isFunction(easing.constructor)

assigns 'true' or 'false' to the 'easing' attribute, instead of the value of 'easing' -- that was why the last easing is there.

so

easing: fn && easing || easing && !jQuery.isFunction(easing.constructor) && easing

would be correct

comment:8 Changed 15 years ago by davidserduke

Milestone: 1.2.21.2.3
need: Test CaseCommit

Ahh good point. I should have known it wasn't a mistake. :)

In fact it could also be

easing: fn && easing || !jQuery.isFunction(easing.constructor) && easing

since jQuery.isFunction() checks the parameter is truthy.

As for getting committed, I'm sure it will eventually. Right now our main goal is to get a stable build out that has some fixes/changes necessary for other projects like Drupal and AIR.

comment:9 Changed 15 years ago by davidserduke

Ok I'm going mental I think. Let me try again.

easing: fn && easing || !jQuery.isFunction(easing) && easing

or maybe!

easing: ( fn || !jQuery.isFunction(easing) ) && easing

I'll make sure I actually test the fix before it gets commited. I promise! :)

comment:10 Changed 15 years ago by flesler

Milestone: 1.2.31.2.4

So.. do we have a consistent bug or fix ?

comment:12 Changed 14 years ago by beat

the comment above is a spam, to be deleted....

But is now that fixed ?

comment:13 Changed 14 years ago by dmethvin

Resolution: fixed
Status: reopenedclosed

Yes, the fix suggested by tgdavies was applied at some point.

Note: See TracTickets for help on using tickets.