Forum: Ruby on Rails Lightbox and RJS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-28 20:03
(Received via mailing list)
Hi,

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?

Thanks,
Sean
Baa493762803518bf4adfbeb75d98e76?d=identicon&s=25 Ilya Grigorik (igrigorik)
on 2006-05-28 20:17
page << "initLightbox();"

Works for me. :)

Ilya
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-28 20:28
(Received via mailing list)
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#{@release.id}"].replace_html :partial =>
'edit_release', :object => @release

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

Thanks,
Sean
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-28 20:31
(Received via mailing list)
Ilya,

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.

Take care,
Sean
Baa493762803518bf4adfbeb75d98e76?d=identicon&s=25 Ilya Grigorik (igrigorik)
on 2006-05-28 20:36
Glad it worked.. Just out of curiosity, are you using lightbox gone
wild?

You might want to check out the new/fresher release (v.2.x) over at:
http://www.huddletogether.com/projects/lightbox2/

Gone wild is based on v.1

Cheers,
Ilya
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 seth b. (subimage)
on 2006-05-28 21:02
(Received via mailing list)
Or you might want to use the original modal that I wrote :)

http://www.subimage.com/sublog/subModal
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-28 21:11
(Received via mailing list)
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.?

Best,
Sean
Baa493762803518bf4adfbeb75d98e76?d=identicon&s=25 Ilya Grigorik (igrigorik)
on 2006-05-29 00:21
Ah, I see.. No I don't need that functionality in my current project..
But again, you may want to take a look at:

http://codylindley.com/Javascript/257/thickbox-one...

Cheers,
Ilya
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-29 17:21
(Received via mailing list)
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?

Thanks,
Sean
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-29 17:40
(Received via mailing list)
Hi All,

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

Thanks,
Sean
Bc7279484cc8b64ab5fd643832873955?d=identicon&s=25 cyx (Guest)
on 2006-05-29 19:14
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.
290cf664d9e6f823fc3af57556493db7?d=identicon&s=25 PJ Hyett (Guest)
on 2006-05-30 00:10
(Received via mailing list)
For regular divs I prefer my lightbox solution over particle tree's,
because it's quite a bit simpler.

http://pjhyett.com/articles/2006/02/09/the-lightbo...

-PJ
9dbe5b9021bf8477a3b7e747b44bde48?d=identicon&s=25 Sean O'Hara (Guest)
on 2006-05-30 18:27
(Received via mailing list)
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 topic is locked and can not be replied to.