Skip to content

Instantly share code, notes, and snippets.

@Otann
Created May 5, 2012 05:53
Show Gist options
  • Save Otann/2600194 to your computer and use it in GitHub Desktop.
Save Otann/2600194 to your computer and use it in GitHub Desktop.
Lift to JavaScript mapping
trait JsHandlerSnippet {
val defaultFuncName = nextFuncName
// This will be called on server-side
def handleJs(param: String): JsCmd
def script(x: NodeSeq): NodeSeq = {
val funcName = S.attr("name") openOr defaultFuncName;
Script(ensure & OnLoad(SetExp(JsVar("window.lift", funcName), jsFunc)))
}
val params = "params"
val jsFunc = AnonFunc(params, SHtml.ajaxCall(JsVar(params), handleJs _)._2)
val ensure = JsRaw("if (typeof window.lift == 'undefined') window.lift = {}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment