Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created October 1, 2009 19:45
Show Gist options
  • Save jfsiii/199193 to your computer and use it in GitHub Desktop.
Save jfsiii/199193 to your computer and use it in GitHub Desktop.
jQuery.fn.getListeners = function(typ)
{
var $els = this,
cache = jQuery.cache,
aListeners = [];
function _handlersArray(typ, handlers)
{
var arr = [];
for (var guid in handlers) {
arr.push(handlers[guid]);
}
return arr;
}
$els.each(function(i, el)
{
var ndx = jQuery.data(el),
oListeners = {};
if (ndx){
var events = cache[ndx].events;
if (typ) {
aListeners.push(_handlersArray(typ, events[typ]));
}
else {
for (var e in events) {
oListeners[e] = _handlersArray(e, events[e]);
}
aListeners.push(oListeners);
}
}
else {
aListeners.push([]);
}
});
return aListeners;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment