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?
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
initLightbox.
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?
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.
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,
Sean
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.