-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
61 lines (48 loc) · 1.31 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use like this:
$('#things').infinitescroll({next: '#next'});
Using it with Rails:
things_controller.rb
======================
def index
@items_per_page = 25
@offset = params[:offset] || 0
@things = Thing.where(:limit => @items_per_page + 1, :offset => @offset)
if @things.length == @items_per_page + 1
@things.pop
@has_more = true
@next_url = things_url(:offset => @offset + @items_per_page)
else
@has_more = false
@next_url = nil
end
respond_to do |format|
format.html # this will have the container div and render the partial below into
format.json {
render :json => {
:worked => true,
:html => render_to_string(:partial => 'things.html.haml', :collection => @things),
:has_more => @has_more,
:next_url => @next_url
}
}
end
end
index.html.haml
=======================
- if @things.length > 0
#things
= render(:partial => 'things', :collection => @things})
= link_to('next', @next_url, :id => 'next')
-else
no photos
_things.html.haml
========================
- things.each do |thing|
= thing.inspect
based off of pieces from
https://github.com/brianmario/jquery-infinite-scroll
and
https://github.com/paulirish/infinite-scroll
TODO:
- start hiding next link and add loading indicator
- convert this to markdown