Pushing Javascript Helper to external file.

Rube
Tue, 11 Oct 2005 17:24:08 -0000

I have a table and when I mouseover a row I want a pop-up with some
additional information for that specific row (called remotely).

I can do this easily with something along the lines of...

onmouseover="<%= remote_function(:updated => "notediv",
:loading => "
Element.show(''note'');", :url => {:action =>
''get_note'', :id =>
inventory.id<http://inventory.id>})
-%>" onmouseout="Element.hide(''note'')".

Okay, the problem with that is, when someone moves the mouse over several
rows and then settles on one row, it loads the data from all those rows,
causing a lagged response. I need to abort the remote call in onmouseover.
This isn''t a huge problem. I have to remove the :loading part from my
helper
function and do it myself, but in the end I can do something like this...

onmouseover="abortCallandShowDiv(); tempvar =
<%remote_function(:update=>''notediv'', :url =>
{:action => ''get_note'', :id =>
inventory.id <http://inventory.id>}) -%>"

And that works, but now I''m serving twice as much data as I need to.
The
purist in me really wants to move all this javascript into a single function
in an external file. onmouseover would just call one function passing the
event and the id as arguments. And I can do this, but I have to hardcode the
call to new Ajax.Updater, so it looks something like this...

tempvar = new Ajax.Updater(''notediv'',
''/store_room/get_note/'' + id,
{asynchronous:true, evalScripts:true});

I just copied the result of remote_function. Anyhow, as you can probably
tell this is going to cause a problem if my app is deployed to a
subdirectory, say /inventory, then the Ajax.Updater should call
''/inventory/store_room/get_note'' + id, but it won''t.
I need that :url magic
in my external .js file.

Is there a solution to this?


_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org