> What exactly do you mean when you say the handler doesn't know which 
> argument is passed via trigger versus bind? Can you give me an example 
> of this so I can better understand the problem?

I try. I take my tooltip plugin as an example, because I can avoid binding 
stuff to DOM elements.

Currently, the individual tooltip settings are saved as a property on each 
tooltipped element:
.each(function() {
        this.tSettings = settings;
})

That is ugly and may leak memory. Therefore I'd change to current bind to pass 
the settings:
.bind(mouseover, handle, settings);

Inside my "handle" function, I could now access the settings, and change this:
handle = function(event) {
        if( this.tSettings.delay ) [...]

to:
handle = function(event, settings) {
        if( settings.delay ) [...]

So far so good, but now I have an additional requirement: I need to trigger the 
handle event when I want to display the tooltip, eg. to display a message for 
an invalid form element. Because the event's mouse position can't be used to 
position the element, I need to pass an additional argument to indicate the 
position where the tooltip should appear.

Something like this:
$(invalidElement).trigger("mouseover", objectWithPositionInformation);

To rewrite my handler:
handle = function(event, settings, triggerOption) { ...

Now what if the handler is used with another event, and no "settings" is 
passed? How to decide what inside which parameter?

I'd prefer a solution where this question is absolutely clear. One solution 
would be to put that data into the event object:

handle = function(event) {
  // use event.bind to access settings, use event.trigger to access 
triggerOption...

The big drawback: That additional data has to be cleared after the handler was 
executed to prevent memory leaks. But that can pose a problem when the data is 
accessed inside a closure...

I hope that makes the problem clear. Any ideas?

--
Jörn Zaefferer

http://bassistance.de
-- 
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to