Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created August 11, 2010 05:32
Show Gist options
  • Select an option

  • Save DylanFM/518525 to your computer and use it in GitHub Desktop.

Select an option

Save DylanFM/518525 to your computer and use it in GitHub Desktop.
window.boundEvents = { all: { count: 0, elements: [] } };
// Collect all the events
$('html').find('*').andSelf().each(function() {
var events = $(this).data('events');
if ($.isPlainObject(events) === true) {
$.each(events, function(n, e) {
if (window.boundEvents[n] === undefined) {
window.boundEvents[n] = { count: 0, elements: [] };
}
});
}
});
var bindTo = '';
$.each(window.boundEvents, function(n, c) { bindTo += n + ' '; });
// Bind to these events
$('html').bind(bindTo, function(e) {
if ($.isPlainObject(window.boundEvents[e['type']])) {
var el = e.target.nodeName;
// Increment counts
window.boundEvents[e.type].count++;
window.boundEvents['all'].count++;
// Track the element types
window.boundEvents[e.type].elements.push(el);
window.boundEvents['all'].elements.push(el);
}
});
@DylanFM

DylanFM commented Aug 11, 2010

Copy link
Copy Markdown
Author

The previous version is nicer to look at in the console, but this one tracks what elements are targetted by the events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment