Bug Tracker

Ticket #2042 (closed bug: fixed)

Opened 2 years ago

Last modified 4 months ago

callback parameter doesn't match on animate functions

Reported by: beat Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.4 Component: fx
Version: 1.2.1 Keywords: animate parameters
Cc: Needs: Commit

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.

Attachments

Change History

Changed 2 years ago by davidserduke

  • need changed from Review to Test Case
  • status changed from new to closed
  • resolution set to worksforme

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.

Changed 1 year ago by tgdavies

  • status changed from closed to reopened
  • resolution deleted

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

Changed 1 year 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?

Changed 1 year 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() { callback.@com.atlassian.crucible.gwt.client.JQuery.Callback::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.

Changed 1 year 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.

Changed 1 year ago by tgdavies

Hi David,

That change fixes the problem.

Will it get committed?

Regards,

Tom

Changed 1 year 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

Changed 1 year ago by davidserduke

  • need changed from Test Case to Commit
  • milestone changed from 1.2.2 to 1.2.3

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.

Changed 1 year 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! :)

Changed 1 year ago by flesler

  • milestone changed from 1.2.3 to 1.2.4

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

Changed 8 months ago by beat

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

But is now that fixed ?

Changed 5 months ago by dmethvin

  • status changed from reopened to closed
  • resolution set to fixed

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

Note: See TracTickets for help on using tickets.