I recently found myself in the situation that I needed to remove a function bound to the resize event of the window by WordPress’ media manager (media-upload.js), because it was interfering with the proper use of Thickbox. The event is attached like this:
a(window).resize(function(){tb_position()})
It took me a while, but I finally found out I could do it in this way:
jQuery.each( jQuery(window).data('events')['resize'], function(i, event) {
var thisEvent = event.toString().replace(/n/g, '').replace(/t/g, '').split(' ').join('');
var expectedEvent = 'function(){tb_position()}';
if (thisEvent == expectedEvent)
delete jQuery(window).data(âeventsâ)[âresizeâ][i];
})
Here I cycle through the events, removing spaces, tabs and new lines from them and compare them to what I’m looking for, and when I find it I throw it out of the goddamn airlock. It happens in this case that the attached function perhaps doesn’t have spaces, tabs or new lines, but this way also works with more complicated functions as far as I can tell.
Is there an easier and/or more elegant way of doing this? Is this a recipe for disaster down the road?
When you register a handler for an event, you can use a qualifier:
Then when you need to remove it you can do so without bothering other handlers for “click”.
Now, it occurs to me that you may not be able to affect the way that WordPress binds its event handler.
Another way around might be to use WordPress’ system for queueing/unqueueing or registering/deregistering scripts. Unregister media-upload.js, and then queue your own version of it.
Prem