event-custom-debug.js revision bd6676c46a56d23b5e6f4702054bbd52e3d6f05f
* Cache of objects touched by the utility * Execute the supplied method before the specified function * @param fn {Function} the function to execute * @param obj the object hosting the method to displace * @param sFn {string} the name of the method to displace * @param c The execution context for fn * @return {string} handle for the subscription // Y.log('Do before: ' + sFn, 'info', 'event'); * Execute the supplied method after the specified function * @param fn {Function} the function to execute * @param obj the object hosting the method to displace * @param sFn {string} the name of the method to displace * @param c The execution context for fn * @return {string} handle for the subscription * Execute the supplied method after the specified function * @param when {string} before or after * @param fn {Function} the function to execute * @param obj the object hosting the method to displace * @param sFn {string} the name of the method to displace * @param c The execution context for fn * @return {string} handle for the subscription // create a map entry for the obj if it doesn't exist // create a map entry for the method if it doesn't exist // re-route the method to our wrapper * Detach a before or after subscription * @param handle {string} the subscription handle ////////////////////////////////////////////////////////////////////////// * Wrapper for a displaced method with aop enabled * @param obj The object to operate on * @param sFn The name of the method to displace * Register a aop subscriber * @param sid {string} the subscriber id * @param fn {Function} the function to execute * @param when {string} when to execute the function * Unregister a aop subscriber * @param sid {string} the subscriber id * @param fn {Function} the function to execute * @param when {string} when to execute the function // Y.log('Y.Do._delete: ' + sid, 'info', 'Event'); * Execute the wrapped method // execute after methods. // Stop processing if a Halt object is returned // Check for a new return value ////////////////////////////////////////////////////////////////////////// * Return an AlterArgs object when you want to change the arguments that * were passed into the function. An example would be a service that scrubs * out illegal characters prior to executing the core business logic. * Return an AlterReturn object when you want to change the result returned * from the core method to the caller * Return a Halt object when you want to terminate the execution * of all subsequent subscribers as well as the wrapped method * if it has not exectued yet. * Return a Prevent object when you want to prevent the wrapped function * from executing, but want the remaining listeners to execute * Return an Error object when you want to terminate the execution * of all subsequent method calls. ////////////////////////////////////////////////////////////////////////// // Y["Event"] && Y.Event.addListener(window, "unload", Y.Do._unload, Y.Do); * Custom event engine, DOM event listener abstraction layer, synthetic DOM * Return value from all subscribe operations * @param evt {Event.Custom} the custom event * @param sub {Subscriber} the subscriber * 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);
// setTimeout(Y.rbind(this._notify, this, s), 0); * @param {Function} fn The function to execute * @param {Object} context Specifies the value of the * 'this' keyword in the listener. * @param args* 0..n params to provide to the listener * @return {EventHandle} unsubscribe handle * @param {Function} fn The function to execute * @param {Object} context Specifies the value of the * 'this' keyword in the listener. * @param args* 0..n params to provide to the listener * @return {EventHandle} unsubscribe handle * 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 * @param {Object} context Specifies the value of the * 'this' keyword in the listener. * @param args* 0..n params to provide to the listener * @return {EventHandle} unsubscribe handle * @param {Function} fn The subscribed function to remove, if not supplied * @param {Object} context The context object passed to subscribe. * @return {boolean} True if the subscriber was found and detached. // 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} True if the subscriber was found and detached. // if the first argument is an object literal, apply the // properties to the event facade // 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 // if (this.emitFacade && (!args[0] || !args[0]._yuifacade)) { // @TODO object literal support to fire makes it possible for // config info to be passed if we wish. // the listener was bound to. 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 ///////////////////////////////////////////////////////////////////// * 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 var a = (args) ? Y.Array(args) : []; * 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;
* Custom event engine, DOM event listener abstraction layer, synthetic DOM * Event.Target is designed to be used with Y.augment to wrap * Event.Custom in an interface that allows events to be subscribed to * and fired by name. This makes it possible for implementing code to * subscribe to an event that either has not been created yet, or will * If the instance has a prefix attribute and the * event type is not prefixed, the instance prefix is * applied to the supplied type. // Y.log("pre: " + pre, 'info', 'event'); // Y.log("type: " + t, 'info', 'event'); * Returns an array with the detach key (if provided), * and the prefixed event name from _getType * Y.on('detachkey, menu:click', fn) // 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 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 * 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 // 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. // 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 * @param context The execution context * @param args* 0..n params to supply to the callback * 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 * Attach an event listener, either to a DOM object * @param type {string} the event type * @param f {Function} the function to execute * @param o the Event.Target or element to attach to * @param context Optional execution context * @param args* 0..n additional arguments to append * to the signature provided when the event fires. * @return {Event.Handle} a handle object for * unsubscribing to this event. // Y.on = function(type, f, o) { // if (L.isFunction(type)) { // return Y.Do.before.apply(Y.Do, arguments); // var adapt = Y.Env.eventAdaptors[type]; // // check for the existance of an event adaptor // if (adapt && adapt.on) { // Y.log('Using adaptor for ' + type, 'info', 'event'); // return adapt.on.apply(Y, arguments); // // 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); // // the pattern for custom events is 'prefix:event', // // however it is possible to have an event adaptor that // // doesn't do anything special for subscribe. // if (adapt || type.indexOf(':') > -1) { // return Y._on.apply(Y, arguments); // return Y.Event.attach.apply(Y.Event, arguments); * Detach an event listener (either a custom event or a * @param type the type of event, or a Event.Handle to * for the subscription. If the Event.Handle is passed * in, the other parameters are not used. * @param f {Function} the subscribed function * @param o the object or element the listener is subscribed * @return {YUI} the YUI instance // Y.detach = function(type, f, o) { // var adapt = Y.Env.eventAdaptors[type], a; // if (o && o._yuievt && o.detach) { // a = Y.Array(arguments, 0, true); // return o.detach.apply(o, a); // } else if (L.isObject(type) && type.detach) { // if (adapt && adapt.detach) { // return adapt.detach.apply(Y, arguments); // } else if (adapt || type.indexOf(':') > -1) { // return Y._detach.apply(Y, arguments); // return Y.Event.detach.apply(Y.Event, arguments); * Executes the callback after 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: * type, callback, context, 1-n arguments * callback, object (method host), methodName, context, 1-n arguments * @return {Event.Handle} unsubscribe handle // Y.after = function(type, f, o) { // if (L.isFunction(type)) { // return Y.Do.after.apply(Y.Do, arguments); // return Y.on.apply(Y, arguments); * Custom event engine, DOM event listener abstraction layer, synthetic DOM * Wraps a DOM event, properties requiring browser abstraction are * fixed here. Provids a security layer when required. * @param ev {Event} the DOM event * @param currentTarget {HTMLElement} the element the listener was attached to * @param wrapper {Event.Custom} the custom event wrapper for this DOM event * @TODO constants? LEFTBUTTON, MIDDLEBUTTON, RIGHTBUTTON, keys // "button" : 1, // we supply // "bubbles" : 1, // needed? // "cancelable" : 1, // needed? // "charCode" : 1, // we supply // "currentTarget" : 1, // we supply "clientX" :
1,
// needed? "clientY" :
1,
// needed? "detail" :
1,
// not fully implemented // "height" : 1, // needed? // "initEvent" : 1, // need the init events? // "layerX" : 1, // needed? // "layerY" : 1, // needed? // "modifiers" : 1, // needed? // "offsetX" : 1, // needed? // "offsetY" : 1, // needed? // "preventDefault" : 1, // we supply // "reason" : 1, // IE proprietary // "returnValue" : 1, // needed? // "srcUrn" : 1, // IE proprietary // "srcFilter" : 1, IE proprietary // "stopPropagation" : 1, // we supply // "timeStamp" : 1, // needed? // "which" : 1, // we supply // "width" : 1, // needed? * webkit key remapping required for Safari < 3.1 25:
9 // SHIFT-TAB (Safari provides a different key code in // this case, even though the shiftKey modifier is set) * Returns a wrapped node. Intended to be used on event targets, * so it will return the node's parent if the target is a text // provide a single event with browser abstractions resolved // include all properties for both browers? // include only DOM2 spec properties? // provide browser-specific facade? // @TODO the document should be the target's owner document // copy all primitives ... this is slow in FF // if (!Y.Lang.isObject(e[i])) { ////////////////////////////////////////////////////// * The X location of the event on the page (including scroll) * The Y location of the event on the page (including scroll) ////////////////////////////////////////////////////// * The keyCode for key events. Uses charCode if keyCode is not available * The keyCode for key events. Uses charCode if keyCode is not available * The charCode for key events. Same as keyCode ////////////////////////////////////////////////////// * The button that was pushed. * The button that was pushed. Same as button. * The event details. Currently supported for Custom * Events only, where it contains the arguments that ////////////////////////////////////////////////////// * Timestamp for the event ////////////////////////////////////////////////////// * Node reference for the targeted element * Node reference for the element that the listener was attached to. if (e.
type ==
"mouseout") {
}
else if (e.
type ==
"mouseover") {
* Node reference to the relatedTarget ////////////////////////////////////////////////////// * Stops the propagation to the next bubble target * @method stopPropagation * Stops the propagation to the next bubble target and * prevents any additional listeners from being exectued * @method stopImmediatePropagation * Prevents the event's default behavior * Stops the event propagation and prevents the default * @param immediate {boolean} if true additional listeners * on the current target will not be executed