event-target.js revision 2a165bf36ff23d834e73c333ea237fabace7a74d
225N/A * Event.Target is designed to be used with Y.augment to wrap 225N/A * Event.Custom in an interface that allows events to be subscribed to 225N/A * and fired by name. This makes it possible for implementing code to 225N/A * subscribe to an event that either has not been created yet, or will 225N/A * not be created at all. 225N/A // console.log('Event.Target constructor executed: ' + this._yuid); 225N/A * Subscribe to a custom event hosted by this object 225N/A * @param type {string} The type of the event 225N/A * @param fn {Function} The callback 225N/A * @param context The execution context 225N/A * @param args* 1..n params to supply to the callback 225N/A * Unsubscribes one or more listeners the from the specified event 225N/A * @param type {string|Object} Either the handle to the subscriber or the 225N/A * type of event. If the type 225N/A * is not specified, it will attempt to remove 225N/A * the listener from all hosted events. 225N/A * @param fn {Function} The subscribed function to unsubscribe, if not 225N/A * supplied, all subscribers will be removed. 225N/A * @param context {Object} The custom object passed to subscribe. This is 225N/A * optional, but if supplied will be used to 225N/A * disambiguate multiple listeners that are the same 225N/A * (e.g., you subscribe many object using a function 225N/A * that lives on the prototype) 225N/A * @return {boolean} true if the subscriber was found and detached. 313N/A // 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: * context: defines the default execution context. If not defined * the default context will be this instance. * silent: if true, the custom event will not generate log messages. * This is false by default. * onSubscribeCallback: specifies a callback to execute when the * event has a new subscriber. This will fire immediately for * each queued subscriber if any exist prior to the creation of * @return {Event.Custom} the custom event Y.
log(
"publish() skipped: '"+
type+
"' exists",
'info',
'Event');
// update config for the event * 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 // if (!(type in SILENT)) { // Y.log(type + ' fire did nothing (not published, no subscribers)', 'info', 'Event'); // 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.Target} the custom event or a falsy value * @param evt {Event.Custom} the custom event to propagate * @return {boolean} the aggregated return value from Event.Custom.fire // 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* 1..n params to supply to the callback // make Y an event target