Articles tagged “facebox”
Implementing an image gallery using facebox and will_paginate
On VisitaCSA we’re using defunkt’s facebox to show places images at large. Facebox is a great general-purpose lightbox, because it is fast, stable, is based on jQuery and has got a really clean API.
But we needed more than a simple display lightbox, because we wanted our users to navigate easily between all images, possibly without modifying facebox at all. The solution turned out to be pretty simple, thanks also to the will_paginate plugin we were already using. It all burns out to have:
- A Photo model, instrumented with the
has_attachment
method - Resource routes for photos (
map.resources :photos, :only => :show
inconfig/routes.rb
) - A
show
controller method in thePhotosController
that calls.paginate
with a:per_page
argument of 1 - An HTML view for the photo resource, that has pagination controls using the
will_paginate
helper - Some jQuery code hooks onto the pagination links and make the browser load via AJAX the next photo directly into the facebox.