Last active
August 29, 2015 13:57
-
-
Save mieky/9482792 to your computer and use it in GitHub Desktop.
Calculate events bound via jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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