Can we add something akin to this...?
It would be nice to have something akin to this in the static portion of jQuery. I know I can do a plugin (and I may) but it would be really nice to have this functionality in the core. I use a variation of this code snippet to define custom events that any code can listen to. Its really handy, small and makes various interfaces quite clean.
Gabriel
pubSub: {},
publish: function(eventName) {
if(!jQuery.pubSub[eventName])
jQuery.pubSub[eventName] = [];
},
subscribe: function(eventName, fn) {
if(!jQuery.pubSub[eventName])
jQuery.publish(eventName);
jQuery.pubSub[eventName].push(fn);
},
fire: function(eventName, thisObj, data) {
if(jQuery.pubSub[eventName]) {
var events =
jQuery.pubSub[eventName];
var thisObject = arguments.length <= 2 ? window : arguments[1];
var eventData = arguments.length > 3
? Array.prototype.splice(arguments, 2, arguments.length
)
: arguments.length==3 ? arguments[2] : arguments[1];
for(var i = 0, len = events.length; i < len; i++) {
try {events[i].apply(thisObject,eventData);} catch(e) {console.log(e);}
}
}
}
<br clear="all">
--
Sincerely,
Gabriel Harrison
(if you encounter issues with my gmail account try me at <a href="mailto:nyteschayde@yahoo.com" target="_blank">nyteschayde@yahoo.com</a>)