Lightbox and RJS



I am trying to include lightbox functionality in my app, but there is
a slight complication. Apparently lightbox initializes all the links
to lightbox events on page load. However, in my case, some new links
to lightbox events will be rendered to the page through ajax events
(obviously this means after the page loads). So I figure I need to
find a way to call lightbox’s initialize() function with every ajax
response. So I am trying to call this function from RJS. Here’s my code:
page << ‘intialize()’

This gives me the following error (in Firefox):
RJS error:
Reference Error: initialize is not defined.

So I guess it’s interpreting as an rjs call rather than simply
javascript. In a previous post I read that the syntax above would
allow one to using custom javascript, but it doesn’t seem to be the
case here. Any ideas?



page << “initLightbox();”

Works for me. :slight_smile:



Thanks Ilya,

In my case, that still throws an RJS error:
Reference Error: initLightbox is not defined.

I have another RJS declaration above:
page[“release#{}”].replace_html :partial =>
‘edit_release’, :object => @release

Maybe it’s no good to mix RJS with custom javascript? Did you define
initLightbox anywhere?



Glad it worked… Just out of curiosity, are you using lightbox gone

You might want to check out the new/fresher release (v.2.x) over at:

Gone wild is based on v.1




I take it back. The double quotes worked fine with my original
declaration. I guess we’re using different Lightbox scripts. I using
particle tree’s which has a function named initialize rather than

Take care,


Or you might want to use the original modal that I wrote :slight_smile:


Ah, I see… No I don’t need that functionality in my current project…
But again, you may want to take a look at:



Hi Ilya,

Have you been able to deactivate a lightbox through rjs? I’ve tried
page << “lightbox.deactivate;”
page << “deactivate;”
page << “lightbox.end;”

None of this do the trick. There is a deactivate function in the
lightbox script that I am using, but I can’t seem to call it (unlike
the initialize function. Any thoughts?



Hi Ilya,

Yes, I’m using lightbox gone wild because it supports the use
lightboxes for non-image content. I didn’t see any mention of that at
the lightbox v.2 page. Have you used it for non-image content such as
partials, etc.?



Another solution would be to use an AJAX auto responder where in you
would run the lightbox intialize whenever an AJAX request (on)Complete.
This is useful when there are a large number of lightbox links involved
in each AJAX result.


Hi All,

I found the answer to my own question. It’s simply:
page << “lightbox.prototype.deactivate();”



For regular divs I prefer my lightbox solution over particle tree’s,
because it’s quite a bit simpler.



Thanks PJ. Indeed your solution fits my needs far better because it’s
much simpler. No need to run the initialize() function every time new
content is added to the page through ajax requests.

Take care,