$.fn.myPlugin = function(options) { options $.extend({ callback: null },
options);
// Your plugin
if ( $.isFunction(options.callback) ) {
options.callback.call();
}
};
$('div').myPlugin({
callback: function() {
// Your callback code
}
});
A better approach might be to simply have your plugin do a
.trigger('pluginevent') which allows for multiple listeners to then use it:
$.fn.myPlugin = function() {
// Your plugin code
$(this).trigger('myplugindidsomething');
};
$('div')
.myPlugin()
.bind('myplugindidsomething', function() {
// Your callback code
});
Cheers,
- Jonathan
http://jqueryminute.com
On Mon, Oct 5, 2009 at 3:10 PM, bittermonkey <[email protected]> wrote:
>
> How do I add a callback function to a plugin so that i can execute
> another function after the plugin completes its own processes.
>
> Thanks in advance.