(n.b. not compiled or tested, and there might be an easier way:)

class MySnippet {
     def handlers(ns: NodeSeq): NodeSeq = {
         val handleResize = SHtml.jsonCall(JE.JsObj("width" -> JE.JsVar 
("window", "screen", "width"),
                                                    "height" ->  
JE.JsVar("window", "screen", "height")),
                                           obj => {
             val result = for {
                m <- (Box!!obj).asA[scala.collection.immutable.Map 
[String, Any]]
                width  <- m.get("width").asA[Int]
                height <- m.get("height").asA[Int]
             } yield {
                // do stuff with the width and height

                // some JS command to send back to the browser
                JsCmds.Noop
             }

             result.openOr(/* JS command to send back to browser if we  
failed to get arguments and so on */ JsCmds.Noop)
         })._2

         <head>{ Script {
             Function("handleResize", Nil, handleResize)
         } }</head>
     }
}

Then in your template say onResize="handleResize()"

Hope that gives you some pointers,
-Ross


On Nov 18, 2009, at 4:19 AM, jhonig wrote:

> Hi All,
>
> Yet another question: I need to make Ajax calls when a page is loaded
> or resized.  The call would need to pass some local client information
> (browser size).  The return should be javascript code that populates a
> div on that page (in particular: an image that is scaled on the server
> to match the browser size).   Actually, local js code is in place that
> makes the call only after the user has stopped resizing (using a
> timeout).
>
> I guess I have to use AjaxCall, providing an expression that puts the
> window dimensions in an array or list, then return the javascript to
> add an <img> tag that downloads the scaled image from a generated url.
>
> Given the level of success I achieved so far, I thought I better ask
> if this would work our before I start trying endlessly.
>
> Thanks for any suggestions,
>
> Job
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Lift" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected] 
> .
> For more options, visit this group at 
> http://groups.google.com/group/liftweb?hl= 
> .
>
>

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=.


Reply via email to