event-target-lazy.js revision 4fd59bfb8fcc741f2159cbd73f554dc64744d224
486N/A * Custom event engine, DOM event listener abstraction layer, synthetic DOM 486N/A * EventTarget is designed to be used with Y.augment to wrap 486N/A * EventCustom in an interface that allows events to be listened to 486N/A * and fired by name. This makes it possible for implementing code to 486N/A * subscribe to an event that either has not been created yet, or will 486N/A * not be created at all. 486N/A * If the instance has a prefix attribute and the 486N/A * event type is not prefixed, the instance prefix is 486N/A * applied to the supplied type. 619N/A // console.log('__getType: ' + pre + ', ' + type, 'info', 'event'); 486N/A // Y.log("type: " + t, 'info', 'event'); 619N/A * Returns an array with the detach key (if provided), 486N/A * and the prefixed event name from _getType 486N/A * Y.on('detachcategory, menu:click', fn) 486N/A * An event target can fire events and be targeted by events. 486N/A * @param opts a configuration object 486N/A * @config emitFacade {boolean} if true, all events will emit event 486N/A * facade payloads by default (default false) 486N/A * @config prefix {string} the prefix to apply to non-prefixed event names 486N/A * chaining, otherwise they return an EventHandle (default false) 486N/A // console.log('Event.Target constructor executed: ' + this._yuid); 486N/A * Subscribe to a custom event hosted by this object 486N/A * @param type {string} The type of the event 486N/A * @param fn {Function} The callback 486N/A * @return the event target or a detach handle per 'chain' config if (
this instanceof YUI) {
// check for the existance of an event adaptor Y.
log(
'Using adaptor for ' +
type,
'info',
'event');
// check to see if the target is an Event.Target. If so, // delegate to it (the Event.Target should handle whether // or not the prefix was included); // } else if (o && !(o instanceof YUI) && o.getEvent) { // a = Y.Array(arguments, 0, true); // return o.on.apply(o, a); // Y.log('parts: ' + parts); // Y.log('storing: ' + key); * Detach 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 {EventTarget} the host // If this is an event handle, use it to detach // The YUI instance handles DOM events and adaptors if (
this instanceof YUI) {
// use the adaptor specific detach code if * 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 * 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 * @deprecated use detachAll // ce.log("publish applying config to published event: '"+type+"' exists", 'info', 'event'); // This event could have been published // make sure we turn the broadcast flag off if this // event was published as a result of bubbling * 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) * 'prefix': the prefix for this targets events, e.g., 'menu' in 'menu:click' * '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 * 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. // switched to a lazy publishing scheme for performance reasons, // if the event is fired w // otherwise there is nothing to be done // 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 * @return the event target or a detach handle per 'chain' config * Executes the callback before a DOM event, custom event * or method. If the first argument is a function, it * is assumed the target is a method. For DOM and custom * events, this is an alias for Y.on. * For DOM and custom events: * type, callback, context, 1-n arguments * callback, object (method host), methodName, context, 1-n arguments * @deprecated use the on method // make Y an event target * Hosts YUI page level events. This is where events bubble to * when the broadcast config is set to 2. // @TODO implement a global namespace function on Y.Global?