settting jquery plugin parameters - best practice?

30 views
Skip to first unread message

Damian Helme

unread,
Mar 12, 2013, 6:25:17 PM3/12/13
to lif...@googlegroups.com
Hi,
I'm wondering what's the most common / best practice for setting jquery plugin parameters from the server.

I'm using the jqueryFileTree, it's initialised with code like:

$(document).ready( function() {
$('#container_id').fileTree({
root: '/some/folder/',
script: '/listfiles'
}, function(file) {
alert(file);
});
});

I want to set the 'root' parameter with a value held on the server (actually taken from the properties file). 

How do people go about this kind of thing? E.g. Would you put the whole thing in a JsRaw instance? Or, would you keep it as embedded in the HTML template and apply some kind of CSS Selector Transform (I haven't been able to find one that would work).

Curious to hear people's thoughts.

Thanks

Damian.

Diego Medina

unread,
Mar 12, 2013, 6:44:12 PM3/12/13
to Lift
I normally have a snippet that will just render javascript, and I
include that snippet invocation where I want this script to be
included. Pretty much like using JsRaw
But there are times that as part of the render method, I would do

def render = {
"#title" #> "My super title" &
"#js" #> Script(Load(JE.JsRaw(...)))
}

Like I did here

https://github.com/fmpwizard/lift_starter_2.4/blob/lafutures/src/main/scala/com/fmpwizard/snippet/Sample.scala

"#js" #> AddFutureCallback

from :
https://github.com/fmpwizard/lift_starter_2.4/blob/lafutures/src/main/scala/com/fmpwizard/lib/FutureHelper.scala

Script(OnLoad( SHtml.ajaxInvoke( () => resultFunc(la, idSelector)
).exp.cmd ))




Thanks

Diego
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to liftweb+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://fmpwizard.telegr.am

Richard Dallaway

unread,
Mar 13, 2013, 5:13:04 AM3/13/13
to lif...@googlegroups.com
I usually extract out the settings to variables and supply them with the JavaScript.  E.g.,

"#js" #> Script(OnLoad(
  JsCrVar("root", Str("/some/folder") & Run("javascript that references root"))
))

If the JavaScript is long, I put it in a regular .js file, and just create the JsCrVar (without OnLoad)

--

Tyler Weir

unread,
Mar 13, 2013, 10:01:41 AM3/13/13
to lif...@googlegroups.com
I like a combo of Diego and Rich's ideas.

For scripts that live on a single page, I use a snippet to generate it.

For scripts that are used more than once, I put them in a .js and call them with a Run or Script.

Damian Helme

unread,
Mar 13, 2013, 5:24:29 PM3/13/13
to lif...@googlegroups.com
Thanks guys, that's given me lots of ideas to play with.


Reply all
Reply to author
Forward
0 new messages