I recently found myself in a situation where I needed to remove a function related to a window resize event using the WordPress media editor (media-upload.js), because it prevented the proper use of Thickbox. The event is attached as follows:
a(window).resize(function(){tb_position()})
It took me a while, but I finally found out that I can do this as follows:
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 look at events, removing spaces, tabs and newlines from them, comparing them with what I'm looking for, and when I find this, I throw it out of the damned gateway. It happens that in the attached function there may not be spaces, tabs or new lines, but this method also works with more complex functions, as far as I can tell.
Is there an easier and / or more elegant way to do this? Is this a recipe for disaster along the way?
source share