Created
November 4, 2013 13:12
-
-
Save pentaphobe/7302216 to your computer and use it in GitHub Desktop.
DOM Event Usage Dumper (and friends)
This file contains 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
/** | |
* Handy for checking for event spamming | |
* @returns {Object} A map of event name to number of occurances. | |
*/ | |
function getEventCounts() { | |
var eventCounts = {}; | |
function incrementEventCounter( eventName ) { | |
eventCounts[eventName] || ( eventCounts[eventName] = 0 ); | |
eventCounts[eventName] += 1; | |
} | |
$('*').each( function(idx, item) { | |
var events = $._data(item, 'events'); | |
if (!events) return; | |
for (var i in events) { | |
if ( events.hasOwnProperty(i) ) { | |
incrementEventCounter( i ); | |
} | |
} | |
}); | |
return eventCounts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment