Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve and fix infinite scrolling

  • Loading branch information...
commit 83f2595fbc4aa8f190623db0f6e4bb1c4e3e786c 1 parent 0ca898d
@VictorNicollet authored
View
10 ohmInfiniteScroll/assets/script.coffee
@@ -10,16 +10,16 @@ Ohm.infinitePage = ($x,url) ->
dt = $w.scrollTop()
db = dt + $w.height()
- et = here.$point.offset().top
- eb = et + here.$point.height()
+ et = $x.offset().top
+ eb = et + $x.height()
if (et <= db && eb >= dt)
$w.unbind s, f
Ohm.post url, null, (d) ->
if d.more
$x.before(d.more.html)
- call d.more.code
- call d.code
+ Ohm.call d.more.code
+ Ohm.call d.code
$x.remove()
else
@@ -27,5 +27,5 @@ Ohm.infinitePage = ($x,url) ->
$w.bind s, f
- do onScroll
+ do f
View
4 ohmInfiniteScroll/assets/table.htm
@@ -0,0 +1,4 @@
+<tr class="ohm-ajax-infinite-page" {$t}><td colspan="{cols|string_of_int|esc}"></td></tr>
+<script type="url:json">
+Ohm.infinitePage here.$t, url
+</script>
View
4 ohmInfiniteScroll/assets/trigger.htm
@@ -1,4 +1,4 @@
-<div class="ohm-ajax-infinite-page" {$t}></div>
+<{tag} class="ohm-ajax-infinite-page" {$t}></{tag}>
<script type="url:json">
- Ohm.infinitePage here.$t, url
+Ohm.infinitePage here.$t, url
</script>
View
30 ohmInfiniteScroll/ohmInfiniteScroll.ml
@@ -3,14 +3,32 @@
open Ohm
open Ohm.Universal
-let of_endpoint endpoint =
+type aspect = [ `DIV | `TR of int | `LI ]
+
+let render ?(aspect=`DIV) json =
+ match aspect with
+ | `DIV ->
+ Asset_OhmInfiniteScroll_Trigger.render (object
+ method tag = "div"
+ method url = json
+ end)
+ | `LI ->
+ Asset_OhmInfiniteScroll_Trigger.render (object
+ method tag = "li"
+ method url = json
+ end)
+ | `TR n ->
+ Asset_OhmInfiniteScroll_Table.render (object
+ method cols = n
+ method url = json
+ end)
+
+let of_endpoint ?aspect endpoint =
let json = JsCode.Endpoint.to_json endpoint in
- Asset_OhmInfiniteScroll_Trigger.render (object
- method url = json
- end)
+ render ?aspect json
-let of_url url =
- of_endpoint (JsCode.Endpoint.of_url url)
+let of_url ?aspect url =
+ of_endpoint ?aspect (JsCode.Endpoint.of_url url)
let respond writer res =
Action.json [ "more", Html.to_json writer ] res
View
6 ohmInfiniteScroll/ohmInfiniteScroll.mli
@@ -1,6 +1,8 @@
(* Ohm is © 2013 Victor Nicollet *)
-val of_url : string -> ('a, Ohm.Html.writer) Ohm.Run.t
-val of_endpoint : Ohm.JsCode.Endpoint.t -> ('a, Ohm.Html.writer) Ohm.Run.t
+type aspect = [ `DIV | `TR of int | `LI ]
+
+val of_url : ?aspect:aspect -> string -> ('a, Ohm.Html.writer) Ohm.Run.t
+val of_endpoint : ?aspect:aspect -> Ohm.JsCode.Endpoint.t -> ('a, Ohm.Html.writer) Ohm.Run.t
val respond : Ohm.Html.writer -> Ohm.Action.response -> Ohm.Action.response
Please sign in to comment.
Something went wrong with that request. Please try again.