js | R Documentation |
This function is a wrapper for id
similar to qp
that uses eval(substitute(alist(...)))
to preserve the value of ...
as-is to be able to
both keep operators like ">="
or "!="
unevaluated in the resulting output,
as well as translating
if/else
clauses from R to JavaScript.
js( ..., level = 2, indent.by = rk.get.indent(), linebreaks = TRUE, empty.e = rk.get.empty.e(), keep.ite = FALSE )
... |
One or several character strings and/or |
level |
Integer value, first indetation level. |
indent.by |
A character string defining the indentation string to use. |
linebreaks |
Logical, should there be line breaks between the elements in this call? |
empty.e |
For |
keep.ite |
Logical,
if |
Normally,
id
would simply evaluate the condition and then return the result of that evaluation, which
most of the time is not what you want. With this function,
you can test conditions in usual R syntax, yet
the operators and if/else
clauses will end up pasted in the result.
The following operators are supported: +, -, *, /, ==, !=, >, <, >=, <=, || and &&
These are currently unsupported and still need to be quoted: %, ++, –, =, +=, -=, *=, /=, %=, === and !==
A character string (or rk.JS.ite
,
if keep.ite=TRUE
and input is an if/else
condition).
The current approach to toggle code parts for previews on and off is to query the value of
the JavaScript variable is_preview
. Only if it is false or unset the code is executed. You can construct
code working this way by nesting it inside js(if("!is_preview"){<your code>})
. Note that you must not
place the exclamation mark before the quotes, but inside.
You should nest your plugin script inside rk.local
if you're
making use of js(), to be sure it can find all defined objects.
rk.local
,
rk.JS.vars
,
rk.JS.array
,
rk.JS.options
,
echo
,
id
,
and the Introduction to Writing Plugins for RKWard
# an example checkbox XML node cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID") cat(rk.paste.JS(js( if(cbox1 == "foo1") { echo("gotcha!") } else { echo("nothing!") } )))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.