Skip to content

Commit

Permalink
Render root box, add default url
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNicollet committed May 17, 2012
1 parent e992bdc commit 17b8ab3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
13 changes: 8 additions & 5 deletions ohmBox/assets/script.coffee
@@ -1,6 +1,6 @@
class OhmBoxStack

constructor: (ctx,sel,@url) ->
constructor: (ctx,sel,@url,@dflt) ->

@$l = $('<div/>').css { position: 'relative', overflow: 'hidden', left: '0px' }
@$c = $('<div/>').append(@$l).css { overflow: 'hidden' }
Expand All @@ -21,7 +21,6 @@ class OhmBoxStack
# Fetch box data from a remote URL

fetch: (url,cUrl,callback) ->
url = '/' + url if url[0] isnt '/'
rq = ++@rq
args = $.toJSON cUrl
$.ajax
Expand All @@ -35,6 +34,10 @@ class OhmBoxStack
# Load a box with a certain url.

load: (url,force) ->

url = '/' + url if url[0] isnt '/'
url = @dflt if url is '/'

if @current && @current.re.test url

# The requested URL is intended to be managed by the current box.
Expand Down Expand Up @@ -159,11 +162,11 @@ class OhmBoxStack

ohmBoxStack = null

#>> ohmBox_init(url:string)
#>> ohmBox_init(id:string,url:string,default:string)

@ohmBox_init = (url) ->
@ohmBox_init = (id,url,dflt) ->
ctx = { $: $('body') }
ohmBoxStack = new OhmBoxStack(ctx,'#box-root',url)
ohmBoxStack = new OhmBoxStack(ctx,'#'+id,url,dflt)
$.address.change (event) ->
ohmBoxStack.load event.path, false

Expand Down
8 changes: 8 additions & 0 deletions ohmBox/ohmBox.ml
Expand Up @@ -255,3 +255,11 @@ module Make = functor(Ctx:CTX) -> struct

end

let render ~url ~default =
let id = Id.gen () in
Html.(concat [
str "<div id=\"" ;
esc (Id.str id) ;
str "\"/>" ;
run (Js.ohmBox_init ~id:(Id.str id) ~url ~default ())
])
4 changes: 3 additions & 1 deletion ohmBox/ohmBox.mli
Expand Up @@ -56,7 +56,6 @@ end
(** The box module configurator. *)
module Make : functor(Ctx:CTX) -> sig


(** A box result. *)
type result

Expand Down Expand Up @@ -184,3 +183,6 @@ val reaction_json : 'fmt reaction -> 'fmt -> Json_type.t
and executes the returned code, within the box context.
*)
val reaction_js : 'fmt reaction -> 'fmt -> Ohm.JsCode.t

(** Render the hole where boxes are rendered. *)
val render : url:string -> default:string -> Ohm.Html.writer

0 comments on commit 17b8ab3

Please sign in to comment.