Created
April 14, 2012 09:20
-
-
Save alexeypegov/2383088 to your computer and use it in GitHub Desktop.
jquery disposed event to execute some code before element removal
This file contains hidden or 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
(function ($) { | |
/** | |
* Disposer jQuery plugin. | |
* | |
* Adds 'disposed' event so you may execute some code _before_ element is somehow removed: | |
* | |
* $('.remove').bind('disposed', function() { | |
* // code to be executed | |
* }); | |
* | |
* WARNING! 'disposed' event will not be fired on jQuery.detach() due to a different implementation! | |
* | |
* @version 1.0 | |
*/ | |
var old = jQuery.cleanData; | |
$.cleanData = function (elements) { | |
for (var i = 0, elem; (elem = elements[i]) !== undefined; i++) { | |
$(elem).triggerHandler("disposed"); | |
} | |
old(elements); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment