Skip to content

Instantly share code, notes, and snippets.

@visiongeist
Created August 20, 2012 08:16
Show Gist options
  • 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