Javascript event handling after ajax call

I'm using link_to_remote to populate a div with some data from the db
and then show the div. The problem is that I need to show it
reasonably close to the place where I clicked. As you know, Firefox
passes its event object to each event handler and because the onclick
event is taken by the Ajax call, I don't have access to the event to
extract the mouse coordinates anytime in the process.

I'm thinking of doing link_to_function instead and then using my own
function to make the AJAX call, but it's not portable and I don't like
it. Another solution I've thought of is attaching a 'click observer'
for each link that uses link_to_remote but there could be potentially
many of those -- so I'm not crazy about this idea either.

Anybody have better ideas?

I'm using link_to_remote to populate a div with some data from the db
and then show the div. The problem is that I need to show it
reasonably close to the place where I clicked. As you know, Firefox
passes its event object to each event handler and because the onclick
event is taken by the Ajax call, I don't have access to the event to
extract the mouse coordinates anytime in the process.

I'm thinking of doing link_to_function instead and then using my own
function to make the AJAX call, but it's not portable and I don't like

You can always just generate the same javascript as link_to_remote
with (that just sets up an Ajax.Updater or and Ajax.Request) if you're
worried about working on different browsers and so on (the cleverness
for that isn't in link_to_remote, it's in the prototype javascript
library that it calls).

This sort of thing is rather easier when you write the javascript by
hand, however you could probably do it still using link_to_remote.
I'm not entirely sure what you're trying to do, but if you were trying
to submit the event coordinates with the request, then :with =>
"'x='+event.pointerX()+'&y='+event.pointerY() should do the trick

Fred

You can always just generate the same javascript as link_to_remote
with (that just sets up an Ajax.Updater or and Ajax.Request) if you're
worried about working on different browsers and so on (the cleverness
for that isn't in link_to_remote, it's in the prototype javascript
library that it calls).

Yep, that's what I was talking about when I said I was going to write
my own function to make the call. By "not portable" I meant that if
the definition of the function provided by Rails changes somehow
(e.g., it gets improved somehow), I would have to update my copy as
well. So, that's not ideal.

to submit the event coordinates with the request, then :with =>
"'x='+event.pointerX()+'&y='+event.pointerY() should do the trick

That is a true gem of Rails wisdom and it's exactly what I was looking
for! The only trouble is detecting whether it's Firefox or IE since
they handle events differently, but it's doable I think. Thanks a lot,
Fred!

Just tried it and it worked like a charm. Thanks once again!!!

You can always just generate the same javascript as link_to_remote
with (that just sets up an Ajax.Updater or and Ajax.Request) if
you're
worried about working on different browsers and so on (the cleverness
for that isn't in link_to_remote, it's in the prototype javascript
library that it calls).

Yep, that's what I was talking about when I said I was going to write
my own function to make the call. By "not portable" I meant that if
the definition of the function provided by Rails changes somehow
(e.g., it gets improved somehow), I would have to update my copy as
well. So, that's not ideal.

I think that's unlikely. Prototype might change internally but the
public interface is unlikely to change any time soon.