event-custom.js revision 130f363d445df351b93f7f72a465e9c33092193d
* Detaches this subscriber // Y.log('EventHandle.detach: ' + this.sub, 'info', 'Event'); * The Event.Custom 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. // this.queuable = !(this.logSystem); * The subscribers to this event * The publisher has configured 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 * 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 * The function to execute if a subscriber calls * stopPropagation or stopImmediatePropagation * The function to execute if a subscriber calls * 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 * If set to true, the custom event will deliver an EventFacade object * that is similar to a DOM event object. // Only add subscribe events for events that are not generated by * Custom events provide a custom event that fires whenever there is * a new subscriber to the event. This provides an opportunity to * handle the case where there is a non-repeating event that has * already fired has a new subscriber. * @param {Function} fn The function to execute * @param {Object} obj An object to be passed along when the event * @param {boolean|Object} override If true, the obj passed in becomes * the execution context of the listener. * if an object, that object becomes the * 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. // the listener was bound to. // @TODO this breaks some expectations documented here: // confirm that their isn't a case that the bubbled // context should be used. // ct = (args && Y.Lang.isObject(args[0]) && args[0].currentTarget); 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, // var b = this.bubbles, h = this.host; // b = (h._yuievt.targets.length); // es.silent = (es.silent || this.silent); // queue this event if the current item in the queue bubbles // if (b && this.queuable && this.type != es.next.type) { // id of the first event in the stack this.
log(
'fireOnce event: ' +
this.
type +
' already fired');
// var subs = this.subscribers.slice(), len=subs.length, // 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 // @TODO check if we need to worry about defaultFn order // execute the default behavior if not prevented // 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 {int} The number of listeners unsubscribed * @param subscriber object // return "{ CE '" + this.type + "' " + "id: " + this.id + // ", host: " + (this.host && Y.stamp(this.host) + " }"); * 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 * Optional additional arguments supplied to subscribe(). If present, * these will be appended to the arguments supplied to fire() * fn bound to obj with additional arguments applied via Y.rbind * Custom events for a given fire transaction. * Executes the subscriber. * @param defaultContext The execution context if not overridden * @param args {Array} Arguments array for the subscriber * @param ce {Event.Custom} 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'));