Created
April 17, 2014 20:58
-
-
Save mikedamage/11011183 to your computer and use it in GitHub Desktop.
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
/** | |
* Innovate Debug Functions | |
*/ | |
/** | |
* Descends through an element's children, their children's children, etc. and | |
* prints a list of their bound event handlers to console. | |
* | |
* ex. $('.sub-nav').parent().boundEventsTree(); | |
*/ | |
$.fn.boundEventsTree = function jqBoundEventsTree() { | |
var $kids = this.children(); | |
$kids.each(function() { | |
var $elem = $(this), evts = $._data($elem[0], 'events'); | |
if (evts) { console.log(this, evts); } | |
$elem.boundEventsTree(); // recurse | |
}); | |
return this; | |
}; | |
/** | |
* Watches literally everything that's a child of an element for the specified events | |
* and reports to console when they fire. | |
* | |
* ex. $('body').watchEverything('mouseenter mouseleave'); | |
*/ | |
$.fn.watchEverything = function watchEverything(evts) { | |
this.on(evts, '*', function(evt) { | |
console.log(evt.type, evt.target, evt); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment