Skip to content
Judson edited this page Jul 5, 2011 · 3 revisions

Anatomy of a Behavior

NinjaScript applies “behaviors” to elements selected using jQuery’s CSS-like selectors. A behavior consists of three things:

  1. A transformer: a function called “transform” that take the element as its argument, and changes it in ways that are appropriate to the behavior. One prepackaged behavior “make_ajax_link” takes a form consisting of a single submit button and converts it into an anchor tag with appropriate attributes.
  2. A list of event handlers – functions in two arguments that take action based on the event and the element. By default, NinjaScript event handlers swallow the event, preventing the default behavior and preventing the event from bubbling back up the DOM. You can use an array of [handler_function, *strings] to have NinjaScript allow “default” behavior, allow the event to “propagate”, or allow the “immediate” propagation of the event (to other handlers on the same element).
  3. A list of helper methods, which are available to the event handlers.
Clone this wiki locally