Created
March 15, 2013 16:00
-
-
Save jcinis/5170945 to your computer and use it in GitHub Desktop.
jQuery plugin to add event triggering to dom elements anytime they append or are appended. The reason for creating this is was to allow backbone.js views to be aware of their being added to the dom and to trigger post-render functionality.
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
/** | |
* Adds event triggering whenever an append takes place. | |
* | |
* - Parent is given an "append" trigger with the child as an arguement | |
* - Child is given an "appended" trigger with the parent as an argument | |
* | |
* @author Jessey White-Cinis <[email protected]> | |
*/ | |
(function($) { | |
var jqueryAppend = $.fn.append; | |
$.fn.append = function () { | |
// trigger append event | |
var rtn = jqueryAppend.apply(this, arguments).trigger("append", arguments); | |
// trigger appended event | |
$(arguments).trigger("appended", this); | |
return rtn; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great for adding focus events to form elements since it focus can not be triggered until an input is rendered into the dom. Essentially this allows for postRender functionality to be added.