event-custom.js revision 1629abfab16a010ce64a057b1d3b3dfeaec3cc1f
* Custom event engine, DOM event listener abstraction layer, synthetic DOM * Return value from all subscribe operations * @param evt {CustomEvent} the custom event * @param sub {Subscriber} the subscriber // var onsubscribeType = "_event:onsub", * Detaches this subscriber // Y.log('EventHandle.detach: ' + this.sub, 'info', 'Event'); * The CustomEvent class lets you define events for your application * that can be subscribed to by one or more independent component. * @param {String} type The type of event, which is passed to the callback * @param o configuration object // if (arguments.length > 2) { // this.log('CustomEvent context and silent are now in the config', 'warn', 'Event'); * The type of event, returned to subscribers when the event fires * The context the the event will fire from by default. Defaults to the YUI * If 0, this event does not broadcast. If 1, the YUI instance is notified * every time this event fires. If 2, the YUI instance and the YUI global * (if event is enabled on the global) are notified every time this event * By default all custom events are logged in the debug build, set silent * to true to disable debug outpu for this event. * Specifies whether this event should be queued when the host is actively * processing an event. This will effect exectution order of the callbacks * for the various events. // this.queuable = false; * The subscribers to this event * This event has fired if true * This event should only fire one time if true, and if * it has fired, any new subscribers should be notified // this.fireOnce = false; * Flag for stopPropagation that is modified during fire() * 1 means to stop propagation to bubble targets. 2 means * to also stop additional subscribers on this target. * Flag for preventDefault that is modified during fire(). * if it is not 0, the default behavior for this event * Specifies the host for this custom event. This is used * to enable event bubbling * The default function to execute after event listeners * have fire, but only if the default action was not // this.defaultFn = null; * The function to execute if a subscriber calls * stopPropagation or stopImmediatePropagation // this.stoppedFn = null; * The function to execute if a subscriber calls // this.preventedFn = null; * Specifies whether or not this event's default function * can be cancelled by a subscriber by executing preventDefault() * Specifies whether or not a subscriber can stop the event propagation * via stopPropagation(), stopImmediatePropagation(), or halt() * Supports multiple options for listener signatures in order to // this.hasSubscribers = false; // this.hasAfters = false; * If set to true, the custom event will deliver an EventFacade object * that is similar to a DOM event object. // this.emitFacade = false; // this.log("Creating " + this.type); * Apply configuration properties. Only applies the CONFIG whitelist * @param o hash of properties to apply * @param force {boolean} if true, properties that exist on the event Y.
error(
"Invalid callback for CE: " +
this.
type);
* @param {Function} fn The function to execute * @return {EventHandle|EventTarget} unsubscribe handle or a * chainable event target depending on the 'chain' config. * @param {Function} fn The function to execute * @return {EventHandle|EventTarget} unsubscribe handle or a * chainable event target depending on the 'chain' config. * Listen for this event after the normal subscribers have been notified and * the default behavior has been applied. If a normal subscriber prevents the * default behavior, it also prevents after listeners from firing. * @param {Function} fn The function to execute * @return {EventHandle|EventTarget} unsubscribe handle or a * chainable event target depending on the 'chain' config. * @param {Function} fn The subscribed function to remove, if not supplied * @param {Object} context The context object passed to subscribe. * @return {boolean|EventTarget} returns a chainable event target * or a boolean for legacy detach support. // if arg[0] typeof unsubscribe handle * @param {Function} fn The subscribed function to remove, if not supplied * @param {Object} context The context object passed to subscribe. * @return {boolean|EventTarget} returns a chainable event target * or a boolean for legacy detach support. // if the first argument is an object literal, apply the // properties to the event facade // protect the event facade properties // update the details field with the arguments * Notify a single subscriber * @param s {Subscriber} the subscriber * @param args {Array} the arguments array to apply to the listener this.
log(
this.
type +
"->" +
": " + s);
// emit an EventFacade if this is that sort of event // @TODO object literal support to fire makes it possible for // config info to be passed if we wish. this.
log(
this.
type +
" cancelled by subscriber");
* Logger abstraction to centralize the application of the silent flag * @param msg {string} message to log * @param cat {string} log category * Notifies the subscribers. The callback functions will be executed * from the context specified when the event was created, and with the * <li>The type of event</li> * <li>All of the arguments fire() was executed with as an array</li> * <li>The custom object (if any) that was passed into the subscribe() * @param {Object*} arguments an arbitrary set of parameters to pass to * @return {boolean} false if one of the subscribers returned false, // @TODO find a better way to short circuit this. // if (!this.broadcast && !this.defaultFn && !this.hasSubscribers && !this.hasAfters) { // queue this event if the current item in the queue bubbles // id of the first event in the stack this.
log(
'fireOnce event: ' +
this.
type +
' already fired');
// this.log("Firing " + this + ", " + "args: " + args); // } // foo is still 1 unless we create a new facade // stopImmediatePropagation // bubble if this is hosted in an event target and propagation has not been stopped // execute the default behavior if not prevented // broadcast listeners are fired as discreet events on the // YUI instance and potentially the YUI global. // process after listeners. If the default behavior was // prevented, the after events don't fire. // stopImmediatePropagation // console.log('clearing stack: ' + es.id + ', ' + this); // reset propragation properties while processing the rest of the queue // q[0] = the event, q[1] = arguments to fire // Y.log('firing queued event ' + ce.type + ', from ' + this); // set up stack to allow the next item to be processed // return (ret !== false); return this.
stopped ?
false :
true;
* @return {int} The number of listeners unsubscribed * @deprecated use detachAll * @return {int} The number of listeners unsubscribed * @param subscriber object * Stop propagation to bubble targets * @method stopPropagation * Stops propagation to bubble targets, and prevents any remaining * subscribers on the current target from executing. * @method stopImmediatePropagation * Prevents the execution of this event's defaultFn * Stops the event propagation and prevents the default * @param immediate {boolean} if true additional listeners * on the current target will not be executed ///////////////////////////////////////////////////////////////////// * Stores the subscriber information to be used when the event fires. * @param {Function} fn The wrapped function to execute * @param {Object} context The value of the keyword 'this' in the listener * @param {Array} args* 0..n additional arguments to supply the listener * The callback that will be execute when the event fires * This is wrapped by Y.rbind if obj was supplied. * Optional 'this' keyword for the listener * fn bound to obj with additional arguments applied via Y.rbind * Additional arguments to propagate to the subscriber * Custom events for a given fire transaction. // this.wrappedFn = Y.rbind.apply(Y, args); * Executes the subscriber. * @param args {Array} Arguments array for the subscriber * @param ce {CustomEvent} The custom event that sent the notification // Ease debugging by only catching errors if we will not re-throw * Returns true if the fn and obj match this objects properties. * Used by the unsubscribe method to match the right subscriber. * @param {Function} fn the function to execute * @param {Object} context optional 'this' keyword for the listener * @return {boolean} true if the supplied arguments match this * subscriber's signature. return "Subscriber " +
this.
id;
// FACADE = new Y.EventFacade(new Y.CustomEvent('x'));