=head1 NAME GvaScript.fireEvent - application-specific events =head1 SYNOPSIS MyConstructor = function (...) {...}; MyContructor.prototype = { fireEvent = GvaScript.fireEvent, // copy into the target object someMethod: function(...) { ... this.fireEvent(eventName, target1, target2, ...); // OR ... this.fireEvent({type: eventName, prop1: value1, ... }, target1, target2, ...); } }; =head1 DESCRIPTION Extension of the HTML event model with specific events. Various C controllers use this to manage interactions between the DOM elements and the controller. Client code can register a an event handler either within the HTML code, or through Javascript. Events have names specific to the controller (for example C uses events C and C; C uses events C, C, C, etc.). =head1 METHODS =head2 fireEvent (first syntax) If a class needs to fire specific events, it must I the C method into its own methods (so that "this" is properly bound to an instance of that class). The first argument to C is usually an event name. This can be any string, without the C prefix : this.fireEvent("Ping", this.htmlElement, otherElement1, ...); The method will inspect all HTML elements supplied in the argument list, trying to find an C handler. If none is found, the method also tries to find an C property within the calling object (C). If an event handler is found, that handler is called with an C argument as described below; the return value of the handler becomes the return value of C. If not handler is found, C returns C. =head2 fireEvent (second syntax) For more sophisticated needs, the first argument to C can be an object with several properties. In that case, all properties will be copied into the generated event structure. The C property should contain the event name, in order to be compatible with the first syntax. So for example this.fireEvent({type : "Ping", prop1 : "value1", prop2 : "value2"}, this.htmlElement, otherElement1, ...); will generate "Ping" events with all default properties described below, plus the properties C and C. =head1 REGISTERING AN EVENT HANDLER
myController.onEventName = function(event){...}; There are three ways to register a handler: =over =item javascript statement in an HTML attribute This works as for ordinary HTML DOM events. The javascript statement will be evaluated in a context where the following variables are defined: =over =item this The object that registered the event handler. =item target The HTML element that first received the event. =item currentTarget The object that registered the event handler (equivalent to C). =item controller The GvaScript controller object that generated the event. =item event A structure containing various information about the generated event, described below. =back =item name of a javascript function inside an HTML attribute The given function will be called with a single C argument. =item property assigned from Javascript This works exactly like the previous case : the event handling function receives a single C argument. =back =head2 Event structure The C object passed to event handlers contains the following properties : =over =item type name of the triggered event (i.e. "Ping", "Highlight", etc.) =item target The HTML element that first received the event. =item srcElement Synonym for C. =item currentTarget The object that registered the event handler. =item controller The GvaScript controller object that generated the event. =back