Jörn Zaefferer schrieb:
>> I'm thinking about extending the callback system in the Tabs plugin to
>> not only allow one callback, but different ones for more flexibility:
>>
>> onActivate (invoked on click), onHide (invoked after old tab got
>> hidden), onShow (invoked after new tab is revealed == callback as is now).
>>
>> First question: Does that make sense at all?
>
> I now sure if someone really gains anything when providing the callback to
> the tabs plugin instead of simply binding to the click event directly.
With simple binding you can only call the handler before the tab is
clicked or after (that would eliminate onActivate and onShow (ok, not
exactly because there's some more stuff going on after a tab is shown,
but that wouldn't make much difference)). I'm also not sure how well
that would integrate with history support.
But maybe I just drop that idea.
>> If yes, the way it is now is that the callback function is called with
>> the scope of the tab container (the div) that gets revealed and two
>> arguments which the first could also be referred to with "this" obviously:
>>
>> settings.callback.apply(toShow[0], [toShow[0], toHide[0]]);
>>
>> Seems redundant to me. The only advantage I see here is that I could
>> define a function without arguments if I only need to refer (via "this")
>> to the tab that gets shown.
>>
>> Wouldn't it be more reasonable to have "this" being the tab that was
>> clicked?
>>
>> settings.callback.apply(clicked, [toShow[0], toHide[0]]);
>
> Please: Just call the callback without modifying it's scope. Pass everything
> necessary as arguments and nothing more. You win to prizes at once: It's
> easiert to simply document and understand the arguments, instead of "and it
> is called in the scope of the clicked element". And you can use a method of a
> class as the callback. When the scope is untouched, the object can access
> other members or methods of itself, avoiding unecessary closures.
>
> A small example:
>
> var handler = function() {
> this.stuff = {};
> };
> handler.prototype.handleEvent = function(element, event) {
> // save the elements name via the event type
> this.stuff[event.type] = element.name;
> };
>
> This isn't possible when "this" refers to the current element.
Yes, that sounds reasonable to me.
Thanks, Jörn!
--
Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/