left/right arrow keys on photo show page go to prev/next
This commit is contained in:
parent
2355947d8e
commit
37a67b29a4
2 changed files with 19 additions and 6 deletions
|
|
@ -4,11 +4,11 @@ module PhotosHelper
|
|||
link_to (image_tag photo.url(:scaled_full)), photo_path(album.next_photo(photo)), :rel => "prefetch"
|
||||
end
|
||||
|
||||
def link_to_prev(photo, album)
|
||||
link_to "<< prev", photo_path(album.prev_photo(photo)), :rel => "prefetch"
|
||||
def url_to_prev(photo, album)
|
||||
photo_path(album.prev_photo(photo))
|
||||
end
|
||||
|
||||
def link_to_next(photo, album)
|
||||
link_to "next >>", photo_path(album.next_photo(photo)), :rel => "prefetch"
|
||||
def url_to_next(photo, album)
|
||||
photo_path(album.next_photo(photo))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,16 @@
|
|||
:javascript
|
||||
$(document).keydown(function(e){
|
||||
switch(e.keyCode) {
|
||||
case 37:
|
||||
window.location.replace( "#{url_to_prev(@photo,@album)}" );
|
||||
break;
|
||||
case 39:
|
||||
window.location.replace( "#{url_to_next(@photo,@album)}" );
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
.back= link_to "⇧ #{@album.name}", album_path(@album)
|
||||
%h1.big_text
|
||||
= @photo.image
|
||||
|
|
@ -6,11 +19,11 @@
|
|||
= link_to 'Edit Photo', edit_photo_path(@photo), :class => "button"
|
||||
|
||||
.sub_header
|
||||
= link_to_prev @photo, @album
|
||||
= link_to "<< prev", url_to_prev(@photo, @album)
|
||||
|
|
||||
= link_to "full size", @photo.url
|
||||
|
|
||||
= link_to_next @photo, @album
|
||||
= link_to "next >>", url_to_next(@photo, @album)
|
||||
|
||||
%div{:id => @photo.id}
|
||||
#show_photo
|
||||
|
|
|
|||
Loading…
Reference in a new issue