Extending Entourage Expressions
It is possible to modify the expression language with new conditions and actions using our JavaScript API. We'll cover how you would go about doing that in the following section.
Creating custom conditions
A condition determines how (and if) and web expression will function. To enable this, a condition will evaluate it's arguments and call an expression's action, taking into account any if or after clauses.
The following example shows the basic steps of creating a custom condition:
App.Wel.registerCustomCondition( function(element,condition,action,elseAction,delay,ifCond) { //Check to see if the condition passed should be handled by this function if (condition === "myCondition") { //Evaluate condition and determine whether or not it is met var conditionMet = true; //Create a function to be executed if the condition is net and the expression's //if clause evaluates to true var actionFunc = App.Wel.makeConditionalAction(id,action,ifCond); //Create a function to call if the condition evaluates to false, and an else action was speified var elseActionFunc = elseAction ? App.Wel.makeConditionalAction(id,elseAction,null) : null; //Execute one action or the other, taking delay into account if (conditionMet) { App.Wel.executeAfter(actionFunc,delay); } else { App.Wel.executeAfter(actionFunc,delay); } } } );
Creating custom actions
An action is any kind of behavior that happens when some condition is satisfied. You can create custom actions through our JavaScript API as well. The following example will alert any text passed to it:
App.Wel.registerCustomAction('a', { execute: function(id,action,params) { // get text name var arg1= params[0].key.split(","); var text = arg1[0]; alert(text); } });
The a action can now be accessed in Expressions using the following syntax:
<div on="click then a[Booyah!]">Click me to alert 'Booyah!'</div>