Adds event listener to a object.
on(type, handler)

type | string, name of the event
handler | function, JavaScript function

OR
on(edata, handler)

edata | object, parameters of the event
handler | function, JavaScript function

Returns undefined.

#### Description

The simplest way to add an event listener is to provide the name of the event and a handler function. For example if you have a layout (for grid, toolbar, etc. it is exactly the same) defined as follows: $('#layout').w2layout({ name : 'layout', panels : [ { type: 'top', size: 40 }, { type: 'main', content: 'This is main panel' }, { type: 'preview', size: 200 } ] }); You can add an event listener in the following way: w2ui['layout'].on('refresh', function (event) { console.log(event.target, event); }); Or to execute at the end of event cycle: w2ui['layout'].on('refresh:after', function (event) { console.log(event.target, event); }); You could also add event listener in the following way: w2ui['layout'].on({ type : 'refresh' }, function (event) { console.log(event.target, event); }); The first way is simple, but the second and third way provides additional functionality. You can add any property to event object and all of them will be passed to the event handlers function as the part of the event argument. The event object may also contain additional parameters, for example when to trigger event before or after, you can specify onComplete function that will be called at the end of the event.
Below is the list of properties of event object: event = { type : '', // event name or * for all events execute : 'before', // when to execute the handler, can be before or after target : null, // target of the event (target will be set when event is triggered) onComplete : null // function(event) to execute after event is processed. }

#### Event Namespace

While adding an event listener, you can provide a namespace for the event: w2ui['layout'].on('render.myplugin', function (event) { console.log(event.target, event); }); w2ui['layout'].on('refresh.myplugin', function (event) { console.log(event.target, event); }); It provides you with a convenience to remove events listener in an easy way without specifying all events and functions they were registered with: w2ui['layout'].off('.myplugin')

#### Event Names

All event names can be found on the event page of corresponding w2ui object. In order to use them with on() and off() methods, you need to drop "on" prefix and lower case first letter. For example, if the object has "onResize" event, you can use it as "resize". If it was "onColumnClick" it should be "columnClick".
You can attach event listener to all events if you do the following: w2ui['layout'].on('*', function (event) { console.log(event.type, event); }); There are several events that are common for all w2ui objects (except w2popup, w2field, w2utility). They are:

- onRender
- onRefresh
- onResize
- onDestroy

#### Event Handlers

When any of the event is triggered and it has an event handler, the event handler function will receive one argument - event, which is an object with useful data related to the event. function handler(event) { // body } Events can be cancelled, see w2utils.events page for more information.