Skip to content

Instantly share code, notes, and snippets.

@mieky
Last active August 29, 2015 13:57
Show Gist options
  • Save mieky/9482792 to your computer and use it in GitHub Desktop.
Save mieky/9482792 to your computer and use it in GitHub Desktop.
Calculate events bound via jQuery
function getEvents(sel) {
return $(sel).toArray().reduce(function(acc, el) {
var events = $._data(el, 'events');
if (events) acc.push(events);
return acc;
}, []);
}
function calculateEvents(acc, obj) {
for (key in obj) {
if (!acc[key]) acc[key] = 0;
acc[key] += obj[key].length;
}
return acc;
}
getEvents("*").reduce(calculateEvents, {})
/*
Object {dragover: 1, click: 43, mousedown: 5, _touchstart: 6, _touchmove: 6…}
_touchend: 5
_touchmove: 6
_touchstart: 6
click: 43
dragover: 1
mousedown: 5
mousemove: 2
mouseout: 1
__proto__: Object
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment