event-target.js revision 0386c9fb5b693cf9752dac24b09ba21992c4f103
0N/A * Custom event engine, DOM event listener abstraction layer, synthetic DOM 0N/A * Event.Target is designed to be used with Y.augment to wrap 0N/A * Event.Custom in an interface that allows events to be subscribed to 0N/A * and fired by name. This makes it possible for implementing code to 0N/A * subscribe to an event that either has not been created yet, or will 0N/A * not be created at all. 0N/A * @Class Event.Target 0N/A // console.log('Event.Target constructor executed: ' + this._yuid); * Subscribe to a custom event hosted by this object * @param type {string} The type of the event * @param fn {Function} The callback * @param context The execution context * @param args* 0..n params to supply to the callback * Unsubscribes one or more listeners the from the specified event * @param type {string|Object} Either the handle to the subscriber or the * type of event. If the type * is not specified, it will attempt to remove * the listener from all hosted events. * @param fn {Function} The subscribed function to unsubscribe, if not * supplied, all subscribers will be removed. * @param context {Object} The custom object passed to subscribe. This is * optional, but if supplied will be used to * disambiguate multiple listeners that are the same * (e.g., you subscribe many object using a function * that lives on the prototype) * @return {boolean} true if the subscriber was found and detached. // If this is an event handle, use it to detach * Removes all listeners from the specified event. If the event type * is not specified, all listeners from all hosted custom events will * @param type {string} The type, or name of the event * Creates a new custom event of the specified type. If a custom event * by that name already exists, it will not be re-created. In either * case the custom event is returned. * @param type {string} the type, or name of the event * @param opts {object} optional config params. Valid properties are: * 'broadcast': whether or not the YUI instance and YUI global are notified when the event is fired (false) * 'bubbles': whether or not this event bubbles (true) * 'context': the default execution context for the listeners (this) * 'defaultFn': the default function to execute when this event fires if preventDefault was not called * 'emitFacade': whether or not this event emits a facade (false) * 'fireOnce': if an event is configured to fire once, new subscribers after * the fire will be notified immediately. * 'preventable': whether or not preventDefault() has an effect (true) * 'preventedFn': a function that is executed when preventDefault is called * 'queuable': whether or not this event can be queued during bubbling (false) * 'silent': if silent is true, debug messages are not provided for this event. * 'stoppedFn': a function that is executed when stopPropagation is called * 'type': the event type (valid option if not provided as the first parameter to publish) * @return {Event.Custom} the custom event // ce.log("publish applying config to published event: '"+type+"' exists", 'info', 'event'); // This event could have been published * Registers another Event.Target as a bubble target. Bubble order * is determined by the order registered. Multiple targets can * @param o {Event.Target} the target to add * Removes a bubble target * @param o {Event.Target} the target to remove * Fire a custom event by name. The callback functions will be executed * from the context specified when the event was created, and with the * If the custom event object hasn't been created, then the event hasn't * been published and it has no subscribers. For performance sake, we * immediate exit in this case. This means the event won't bubble, so * if the intention is that a bubble target be notified, the event must * be published on this object first. * @param type {String|Object} The type of the event, or an object that contains * @param arguments {Object*} an arbitrary set of parameters to pass to * @return {boolean} the return value from Event.Custom.fire // this event has not been published or subscribed to // if this object has bubble targets, we need to publish the // event in order for it to bubble. // ce = this.publish(t, { // otherwise there is nothing to be done // Provide this object's subscribers the object they are listening to. // ce.currentTarget = this; // This this the target unless target is current not null // ce.target = ce.target || this; // clear target for next fire() * Returns the custom event of the provided type has been created, a * @param type {string} the type, or name of the event * @return {Event.Custom} the custom event or null return (e &&
type in e) ? e[
type] :
null;
* @param evt {Event.Custom} the custom event to propagate * @return {boolean} the aggregated return value from Event.Custom.fire // Y.log('Bubbling ' + evt.type); // if this event was not published on the bubble target, // publish it with sensible default properties // publish the event on the bubble target using this event // set the host and context appropriately // clear handlers if specified on this event // ce.target = evt.target; // stopPropagation() was called * Subscribe to a custom event hosted by this object. The * supplied callback will execute after any listeners add * via the subscribe method, and after the default function, * if configured for the event, has executed. * @param type {string} The type of the event * @param fn {Function} The callback * @param context The execution context * @param args* 0..n params to supply to the callback // make Y an event target