Articles tagged “jquery”
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.
The jQuery ajax-upload-fu plugin
I recently wrote jQuery plug-in, that allows AJAX file uploads without using a fixed file input button. It achieves its goals by installing an OnMouseMove handler over the selected elements, and moving the input button under the mouse cursor.
The quote that inspired this code is: “If Muhammad won’t go to the the mountain, the mountain will come to Muhammad”,the opposite of the more known proverb :).
It has been spinned off from the Visita CSA application JavaScript codebase, see the gist for more information, and have a look onto the live app code for an example of its usage.
Here is the source code: