Permalink
Browse files

lazy load and jpages added

  • Loading branch information...
1 parent 906b9f3 commit fe314f25a61eb63a2d9af552b30831acf02aa92f @zlorfi committed Apr 2, 2013
View
13 app.rb
@@ -102,10 +102,6 @@ def raw(text)
Rack::Utils.escape_html(text)
end
- def count_all_pictures
- Picture.count.to_s
- end
-
end
get "/stylesheets/*.css" do |path|
@@ -196,15 +192,6 @@ def count_all_pictures
end
end
- get '/gallery/:items/:skip' do
- if params[:items] && params[:skip]
- @pictures = Picture.all.asc(:image_date).limit(params[:items]).skip(params[:skip])
- haml :gallery, :layout => !request.xhr?
- else
- flash.now[:alert] = "ERROR!"
- end
- end
-
get '/' do
@pictures = Picture.all.asc(:image_date)
haml :index
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,9 +0,0 @@
-- @pictures.each do |key|
- %li
- %a{:href => "#{key.image.thumb('800x800').url}", :class => 'fancybox', 'data-fancybox-group' => 'button', :title => "#{key.image_title}"}
- %img{:src => "#{key.image.thumb('100x100#').url}"}
- -if admin?
- %form(action="/delete/#{key.id}" method="post")
- %input{:type => :hidden, :name => "_method", :value => "delete"}
- %a.tiny.button.info.radius{:href => "/i/#{key.id}"} Show
- %input.tiny.button.alert.radius{:type => "submit", :value => "Delete"}
View
@@ -1,48 +1,45 @@
.row
.large-8.columns
%ul#gallery.small-block-grid-4.large-block-grid-6
- =# haml :gallery if !request.xhr?
-
- #load_more
- .small.button.expand.radius
- %i.icon-cloud-download.icon-2x
- Load more
+ - @pictures.each do |key|
+ %li
+ %a{:href => "#{key.image.thumb('800x800').url}", :class => 'fancybox', 'data-fancybox-group' => 'button', :title => "#{key.image_title}"}
+ %img.lazy{'data-original' => "#{key.image.thumb('100x100#').url}", :src => "/image/grey.gif"}
+ -if admin?
+ %form(action="/delete/#{key.id}" method="post")
+ %input{:type => :hidden, :name => "_method", :value => "delete"}
+ -#%a.tiny.button.info.radius{:href => "/i/#{key.id}"} Show
+ %input.tiny.button.alert.radius{:type => "submit", :value => "Delete"}
+ .holder
= haml :sidebar
%script{:type => "text/javascript", :src => "/javascripts/vendor/jquery.mousewheel.js"}
%script{:type => "text/javascript", :src => "/javascripts/vendor/jquery.fancybox.pack.js"}
+%script{:src => "/javascripts/vendor/jquery.lazyload.min.js", :type => 'text/javascript'}
+%script{:src => "/javascripts/vendor/jPages.min.js", :type => 'text/javascript'}
:javascript
- $(document).ajaxStart(function() {
- $('#load_more i').removeClass('icon-cloud-download').addClass('icon-spinner icon-spin');
- }).ajaxStop(function() {
- $('#load_more i').removeClass('icon-spinner icon-spin').addClass('icon-cloud-download');
- });
-
$(document).ready(function() {
- var items = 12;
- var skip = items;
-
- $.get('/gallery/' + items + '/0', function(data){
- $(data).appendTo("#gallery");
- if (skip >= "#{count_all_pictures}") {
- $('#load_more').hide();
- }
+ $("img").lazyload({
+ event: "turnPage",
+ effect: "fadeIn"
});
- $('#load_more').click(function(data){
- if(skip < "#{count_all_pictures}") {
- console.log(skip);
- console.log("#{count_all_pictures}");
- $.get('/gallery/' + items + '/' + skip, function(data){
- $(data).appendTo("#gallery");
- skip += 12;
- });
- }
- else {
- $('#load_more').hide();
- }
+ $(".holder").jPages({
+ containerID: "gallery",
+ animation: "flipInY",
+ direction: "random",
+ perPage: 18,
+ keyBrowse: true,
+ previous : "←",
+ next : "→",
+ callback: function(pages, items ){
+ /* lazy load current images */
+ items.showing.find("img").trigger("turnPage");
+ /* lazy load next page images */
+ items.oncoming.find("img").trigger("turnPage");
+ }
});
$('.fancybox').fancybox({
Oops, something went wrong.

0 comments on commit fe314f2

Please sign in to comment.