Expressions JavaScript API
Trace: » Appcelerator Entourage In Action » Get Started with App Engine » Tooltip » Rounded » Expressions JavaScript API

Expressions JavaScript API

Through JavaScript, it is possible to bind expressions to elements and capture common bits of expressions into “macros”. All available JavaScript hooks into Entourage Expressions are documented here.

App.on

Bind an expression to an element with the given ID.

App.on(id,expression);
Parameter Description
id A string which is the ID of the element to which you will bind the expression
expression A string which defines the Expression for this element, like “click then show”


$().on (jQuery only)

Bind an expression to any element returned by the given jQuery selector.

$(selector).on(expression);
Parameter Description
selector A string which defines the jQuery selector which will return one or more elements that the expression will be bound to. Check out the jQuery selector documentation for more on how to use selectors.
expression A string which defines the Expression for the returned elements, like “click then show”


$WEM (Expression Macros)

$WEM allows you to capture common bits of expression logic for reuse in multiple expressions. This allows you to avoid repeating yourself in expressions, and to make your expressions more readable by providing descriptive names. Expression Macros can be used in an Entourage Expression by prefixing the macro name with a # character. Macros can also take parameters to place dynamic values in the expression snippet using Ruby-style string interpolation (#{my_argument}), as in the example below the API description.

$WEM(macro_object);
Parameter Description
macro_object A JavaScript object that is a map of key/value pairs that bind an expression macro to a string. See below for an example.

Live Example

Waiting for message...

Source Code

<br/><br/>
<input id="sendMessage" type="button" value="Send Message"/>
<div id="messageBox" style="border:1px solid;padding:5px">
  Waiting for message...
</div>
 
<script>
jQuery(function() {
  //Define Macros
  $WEM({
    //Combine two effects into a single expression
    "combo_effect": "effect[highlight] and effect[pulsate]",
    //A contrived example of passing a parameter to a macro
    "print": "value[#{message}]"
  });
 
  //Bind Expressions
  App.on("sendMessage","click then l:msg");
  //This expression uses macros
  App.on("messageBox", "l:msg then #print[message=Hello World!] and #combo_effect");
});
</script>
expressions/api.txt · Last modified: 2009/03/09 19:05 by kwhinnery