Skip to content

Instantly share code, notes, and snippets.

@visiongeist
Created August 20, 2012 08:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save visiongeist/3402141 to your computer and use it in GitHub Desktop.
Save visiongeist/3402141 to your computer and use it in GitHub Desktop.
This plugin hooks into an existing jQuery function and calls a user defined function after a jQuery function was called.
/*
* Function hook jQuery plugin
* version 1.0
* author: Damien Antipa
* http://github.com/dantipa/
*/
(function(window, $, undefined){
/**
* Hooks into a given method
*
* @param method
* @param fn
*/
$.fn.hook = function (method, fn) {
var def = $.fn[method];
if (def) {
$.fn[method] = function() {
var r = def.apply(this, arguments); //original method
fn(this, method, arguments); //injected method
return r;
}
}
}
})(window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment