Skip to content

Commit

Permalink
Infinite scroll plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNicollet committed Mar 31, 2013
1 parent 1191f29 commit 0ca898d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 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

4 changes: 4 additions & 0 deletions 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>
16 changes: 16 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions 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

0 comments on commit 0ca898d

Please sign in to comment.