event-do.js revision ac150e63555685e2b9730ff83eb45bdf8704eedb
(function() {
/**
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
* events.
* @module event
*/
/**
* Allows for the insertion of methods that are executed before or after
* a specified method
* @class Do
* @static
*/
var BEFORE = 0,
AFTER = 1;
Y.Do = {
/**
* Cache of objects touched by the utility
* @property objs
* @static
*/
objs: {},
/**
* Execute the supplied method before the specified function
* @method before
* @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
* @static
*/
// Y.log('Do before: ' + sFn, 'info', 'event');
var f = fn, a;
if (c) {
}
},
/**
* Execute the supplied method after the specified function
* @method 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
* @static
*/
var f = fn, a;
if (c) {
}
},
/**
* Execute the supplied method after the specified function
* @method _inject
* @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
* @private
* @static
*/
// object id
// create a map entry for the obj if it doesn't exist
}
if (! o[sFn]) {
// create a map entry for the method if it doesn't exist
// re-route the method to our wrapper
function() {
};
}
// subscriber id
// register the callback
},
/**
* Detach a before or after subscription
* @method detach
* @param handle {string} the subscription handle
*/
}
},
}
};
//////////////////////////////////////////////////////////////////////////
/**
* Wrapper for a displaced method with aop enabled
* @class Do.Method
* @constructor
* @param obj The object to operate on
* @param sFn The name of the method to displace
*/
this.methodName = sFn;
// this.before = [];
// this.after = [];
this.before = {};
this.after = {};
};
/**
* Register a aop subscriber
* @method register
* @param sid {string} the subscriber id
* @param fn {Function} the function to execute
* @param when {string} when to execute the function
*/
if (when) {
// this.after.push(fn);
} else {
// this.before.push(fn);
}
};
/**
* Unregister a aop subscriber
* @method delete
* @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
* @method exec
*/
prevented = false;
// execute before
for (i in bf) {
if (bf.hasOwnProperty(i)) {
if (ret) {
switch (ret.constructor) {
break;
prevented = true;
break;
default:
}
}
}
}
// execute method
if (!prevented) {
}
// execute after methods.
for (i in af) {
if (af.hasOwnProperty(i)) {
// Stop processing if a Halt object is returned
// Check for a new return value
}
}
}
return ret;
};
//////////////////////////////////////////////////////////////////////////
/**
* 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.
* @class Do.AlterArgs
*/
};
/**
* Return an AlterReturn object when you want to change the result returned
* from the core method to the caller
* @class Do.AlterReturn
*/
};
/**
* 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.
* @class Do.Halt
*/
};
/**
* Return a Prevent object when you want to prevent the wrapped function
* from executing, but want the remaining listeners to execute
* @class Do.Prevent
*/
};
/**
* Return an Error object when you want to terminate the execution
* of all subsequent method calls.
* @class Do.Error
* @deprecated
*/
//////////////////////////////////////////////////////////////////////////
// Y["Event"] && Y.Event.addListener(window, "unload", Y.Do._unload, Y.Do);
})();