Skip to content

Instantly share code, notes, and snippets.

@boban100janovski
Created March 16, 2014 22:57
Show Gist options
  • Save boban100janovski/9591087 to your computer and use it in GitHub Desktop.
Save boban100janovski/9591087 to your computer and use it in GitHub Desktop.
jQuery get Events
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, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment