Last active
August 29, 2015 14:10
-
-
Save matthewmorrone/815f2739237b81795fbd to your computer and use it in GitHub Desktop.
This is an attempt to make jQuery's event helper functions use the "live" or "delegate" implementation of the on function, so that you don't have to run your event handler creators again if/when you add more elements.
This file contains 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
$.each(("blur focus focusin focusout load resize scroll unload click dblclick " + | |
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + | |
"change select submit keydown keypress keyup error contextmenu").split(" "), | |
function(i, name) | |
{ | |
$.fn[name] = function(fn) { | |
return arguments.length > 0 ? | |
$(document).on(name, this, fn) : | |
this.trigger(name); | |
}; | |
}); | |
// Unfortunately, it doesn't quite work yet, as I believe the second parameter | |
// requires a CSS selector string, which as far as I know is not trivial | |
// to retrieve from an arbitrary jquery object. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment