Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Infinite scroll plugin

  • Loading branch information...
commit 0ca898d7f3cb60228d9638e6ef074bb28f87f95c 1 parent 1191f29
@VictorNicollet authored
View
31 ohmInfiniteScroll/assets/script.coffee
@@ -0,0 +1,31 @@
+@Ohm = {} if !('Ohm' of @)
+
+Ohm.infinitePage = ($x,url) ->
+
+ s = "scroll"
+ $w = $ window
+
+ f = () ->
+ if $x.is(":visible")
+
+ dt = $w.scrollTop()
+ db = dt + $w.height()
+ et = here.$point.offset().top
+ eb = et + here.$point.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
+ $x.remove()
+
+ else
+ $w.unbind s, f
+
+ $w.bind s, f
+
+ do onScroll
+
View
4 ohmInfiniteScroll/assets/trigger.htm
@@ -0,0 +1,4 @@
+<div class="ohm-ajax-infinite-page" {$t}></div>
+<script type="url:json">
+ Ohm.infinitePage here.$t, url
+</script>
View
16 ohmInfiniteScroll/ohmInfiniteScroll.ml
@@ -0,0 +1,16 @@
+(* Ohm is © 2013 Victor Nicollet *)
+
+open Ohm
+open Ohm.Universal
+
+let of_endpoint endpoint =
+ let json = JsCode.Endpoint.to_json endpoint in
+ Asset_OhmInfiniteScroll_Trigger.render (object
+ method url = json
+ end)
+
+let of_url url =
+ of_endpoint (JsCode.Endpoint.of_url url)
+
+let respond writer res =
+ Action.json [ "more", Html.to_json writer ] res
View
6 ohmInfiniteScroll/ohmInfiniteScroll.mli
@@ -0,0 +1,6 @@
+(* 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
+
+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.