From 17b8ab39502acea3bb951acbef2b77993bb337cc Mon Sep 17 00:00:00 2001 From: Victor Nicollet Date: Thu, 17 May 2012 18:08:30 +0200 Subject: [PATCH] Render root box, add default url --- ohmBox/assets/script.coffee | 13 ++++++++----- ohmBox/ohmBox.ml | 8 ++++++++ ohmBox/ohmBox.mli | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ohmBox/assets/script.coffee b/ohmBox/assets/script.coffee index 969dae1..10a0949 100644 --- a/ohmBox/assets/script.coffee +++ b/ohmBox/assets/script.coffee @@ -1,6 +1,6 @@ class OhmBoxStack - constructor: (ctx,sel,@url) -> + constructor: (ctx,sel,@url,@dflt) -> @$l = $('
').css { position: 'relative', overflow: 'hidden', left: '0px' } @$c = $('
').append(@$l).css { overflow: 'hidden' } @@ -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 @@ -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. @@ -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 diff --git a/ohmBox/ohmBox.ml b/ohmBox/ohmBox.ml index 1ba0319..431bfb9 100644 --- a/ohmBox/ohmBox.ml +++ b/ohmBox/ohmBox.ml @@ -255,3 +255,11 @@ module Make = functor(Ctx:CTX) -> struct end +let render ~url ~default = + let id = Id.gen () in + Html.(concat [ + str "
" ; + run (Js.ohmBox_init ~id:(Id.str id) ~url ~default ()) + ]) diff --git a/ohmBox/ohmBox.mli b/ohmBox/ohmBox.mli index c487369..ccb9518 100644 --- a/ohmBox/ohmBox.mli +++ b/ohmBox/ohmBox.mli @@ -56,7 +56,6 @@ end (** The box module configurator. *) module Make : functor(Ctx:CTX) -> sig - (** A box result. *) type result @@ -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