occasionally useful ruby, ubuntu, etc


Debugging unobtrusive javascript in jQuery

So if you work for a large enterprise website like I do, where each page loads dozens or hundreds of kilobytes of javascript, it can be hard to figure out exactly what happens when you click that div and something magically happens, due to the wonders of unobtrusive javascript.

Or, to rephrase the question, "I know how to add event handlers to an object -- how do I enumerate what's already been attached?"

And it's pretty easy, but unfortunately it doesn't use a public API. Anyway, try this in Firebug:


If there are any events on that element, they'll be displayed. The only drawback is...you have to know exactly which element the events are attached to, or guess around a bit.



Sprockets — it's a good thing

Came across an interesting utility library: Sprockets. It's a Ruby-powered Javascript preprocessor. It's used for three things -- embedding other js files into the current js file, ensuring required assets get copied to the assets root, and for interpolating constants (like version numbers, author, etc) into the js file. I found it browsing Prototype.js's source -- really cool stuff. Also funny because I came across it by accident and I was just contemplating designing an identical tool. Good thing and bad thing at the same time :)