RJS referring to window.parent


Hi all,

I’ve been doing some work on the Ajax Scaffold
(http://www.ajaxscaffold.com/), to make it work with file uploads
(more specifically, the file_upload plugin).

The first logical step was to get rid of form_remote_tag, since it’s
impossible to send files via XMLHTTPRequests (to my best knowledge).
So I referred to the iframe hack, similar to the upload progress bar
here (http://sean.treadway.info/demo/upload/).

The way I found to perform an action upon successful form submission
was to include javascript code in the response view, which will be
rendered in the hidden iframe. It gets executed, it works perfectly

But here’s the problem: I wanted to simply “import” the RJS files that
come with the Ajax Scaffold. The way I figured to do that was to do
write my view (the one getting rendered in the hidden iframe) like


<%= javascript_include_tag :defaults %> <%= render :update do |page|
     # all the RJS goes here

     end %>
#### END CODE ####

Sounds like it will work. But here’s the catch: all the elements that
the RJS code above is referring to are supposed to be in the same page
where the output javascript is. The only way to refer to them is to
preceed their ID’s with “window.parent.document.getElementById”, so
the code inside the iframe is actually targetting the page “hosting”
it, and that’s where the elements we want to manipulate are.

So my question is: is there a way to do it via RJS? I thought that
something like “page.parent” existed, but it doesn’t. It also comes to
my mind a hack, where the parameters you supply to the RJS functions
don’t get quoted, meaning if I did something like this:

page.visual_effect :highlight,

It would output “window.parent…” with no surrounding quotes. If that
worked, Prototype would find the element just fine.

The only other choice I have here is actually fetching all the JS
output, and writing it all in the view, changing the target for the
Prototype functions. But that sounds cranky to me.

Any ideas?