Interface zebkit.EventProducer <zebkit>

Event producer interface. This interface provides number of methods to register, un-register, fire events. It follows on/off notion like JQuery does it. It is expected an event producer class implementation has a special field "_" that keeps listeners.

var MyClass = zebkit.Class(zebkit.EventProducer, [
    function() {
        // "fired" events listeners container
        this._ = new zebkit.Listeners();
    }
]);

var a = new MyClass();
a.on("fired", function(arg) {
    // handle "fired" events
});

a.fire(10);



public void fire (event, [path], [params])

Fire event with the given parameters.


Parameters:
  • event <String>

    an event name

  • [path] <String>

    a path if the event has to be send to multiple destination in the tree

  • [params] <Object | Array>

    array of parameters or single parameter to be passed to an event handler or handlers.

public void off ([eventName], [path], [cb])

Stop listening the given event type.


Parameters:
  • [eventName] <String>

    an event type name to stop listening. If the event name is not passed then stop listening all events types.

  • [path] <String>

    a xpath-like path to traversing elements in tree and stop listening the event type for the found in the tree elements. The parameter can be used if the interface is implemented with tree-like structure (for instance zebkit UI components).

  • [cb] <Object>

    remove the given event handler.

public void on ([eventName], [path], cb)

Register listener for the given events types or/and the given nodes in tree-like structure or listen all events types.


Parameters:
  • [eventName] <String>

    an event type name to listen. If the event name is not passed then listen all events types.

  • [path] <String>

    a xpath-like path to traversing elements in tree and register event handlers for the found elements. The parameter can be used if the interface is implemented with tree-like structure (for instance zebkit UI components).

  • cb <Function | Object>

    a listener method or an object that contains number of methods to listen the specified events types.


Example:
var comp = new zebkit.ui.Panel();
comp.add(new zebkit.ui.Button("Test 1").setId("c1"));
comp.add(new zebkit.ui.Button("Test 2").setId("c2"));
...
// register event handler for children components of "comp"
comp.on("/*", function() {
    // handle button fired event
    ...
});

// register event handler for button component with id equals "c1"
comp.on("#c1", function() {
    // handle button fired event
    ...
});