views:

24

answers:

1

I have some jQuery code that runs fine until I add the jQuery UI library (1.7.2) and this causes the show() method to fail when I specify a callback.

$('#main.home ul#promotions').show(function() {
    if (typeof f == "function") f();
});

It would seem that jQuery UI overrides show and now I need to specify an additional parameter for "effect", the following code fixes the issue:

$('#main.home ul#promotions').show('blind', function() {
    if (typeof f == "function") f();
});

However this is part of a script that shouldn't be dependent on the jQuery UI library so ideally I want to stop jQuery UI overriding show in this case.

Can anyone suggest how this can be done?

Dave

+1  A: 
Pointy
Due to the way the logic is (and I agree the API doesn't say anything about this), passing just a function is equivalent to `.show("normal", func)`, so his current code is actually a 400ms animation.
Nick Craver
Are you sure? It looks to me like the function passed as the "speed" argument will essentially be ignored. That code is kind-of confusing, however, so I could be wrong. I'm looking at the little "speed()" utility in jQuery, which *I think* will try to use the function as a lookup into the named speed array.
Pointy
@Pointy - The easiest way is to test, you can see the behavior here: http://jsfiddle.net/nick_craver/7sr4b/ :)
Nick Craver
Never mind Nick, you're of course correct :-) I still don't see how the function ends up being called, but whatever. (edit - oh I see it now, line 5682 or so right at the top of "speed()")
Pointy
@Pointy - They key is here: http://github.com/jquery/jquery/blob/master/src/effects.js#L17 As long as speed is anything but 0 it gets translated to `.animate(effect, speed, callback)` and since it checks for optional params it works :)
Nick Craver
+1 to your answer - whatever you can get away with...there isn't an overload that matches what he's calling in the API, so the fact that anything breaks, well that's ok...the documented functions work, this just isn't one of them.
Nick Craver
You are indeed correct about the number of arguments - strange how it was working before adding jQuery UI however. Now added 'normal' as a argument and all is working well. Thanks.
Digital Rant