Why not take advantage of jquery's event mechanism and do an event
based api, like:
$("#sel").testStatus(opt).bind("statusupdated.testStatus",function()
{
  //dostuff
});

then in your plugin:

if (question) {
          $.ajax({
            type: 'POST',
            url: itemHref + defaults.status
          });
          $(this).trigger("statusupdated.testStatus");
        }


On Nov 6, 9:37 pm, "Hector Virgen" <[EMAIL PROTECTED]> wrote:
> I would add it as an option and set its default value to an empty function:
> var defaults = {
>     status: '?action=live',
>     onComplete: function() {}
>
> }
>
> That way you could safely call onComplete when ready and it will either do
> nothing or call the user-supplied function.
>
> -Hector
>
> On Thu, Nov 6, 2008 at 8:33 PM, Nic Hubbard <[EMAIL PROTECTED]> wrote:
>
> > What is the best way to add a callback to a plugin that I wrote?  Do I
> > just add it as an additional option?
>
> > So, after the ajax function is run, how would I allow a custom
> > callback or function to be added by the user?
>
> >  $.fn.testStatus = function(options) {
> >    var defaults = {
> >      status: '?action=live'
> >    };
>
> >    var options = $.extend(defaults, options);
>
> >    return this.each(function() {
>
> >      var obj = $(this);
> >      var itemId = obj.attr('id');
> >      var itemHref = obj.attr('href');
> >      obj.click(function() {
> >        var question = confirm('Are you sure you want change the
> > status?');
> >        if (question) {
> >          $.ajax({
> >            type: 'POST',
> >            url: itemHref + defaults.status
> >          });
> >        }
> >        return false;
> >      });
> >    });
> >  };

Reply via email to