The problem is you're losing scope when calling onComplete. Try using
the .apply method. Instead of:

defaults.onComplete();

try:

defaults.onComplete.apply(obj.get(0), []);

That should get "this" back to what you're expecting it to be. You
could also skip a step and call:

defaults.onComplete.apply(obj, []);

---

onComplete: function(){ alert(this.attr('class')); }

I'm pretty sure that should work. IF not, let me know, and I'll play
around with it locally and actually test it out.







On Feb 25, 3:52 pm, Nic Hubbard <nnhubb...@gmail.com> wrote:
> I was meaning when trying to call $(this) in the following
> circumstance:
>
>         $('a.matrixStatus').matrixStatus({
>             urlSuffix: '?action=status_posting',
>             onComplete: function() {alert('Callback worked'); alert($
> (this).attr('class'));}
>         });
>
> When I am trying to pass things to the custom function, using $(this)
> does not work.
>
> On Feb 25, 12:28 pm, brian <bally.z...@gmail.com> wrote:
>
> > Something like this? (no pun intended)
>
> > obj.click(function() {
> >   var self = $(this);
>
> >   ...
>
> >    defaults.onComplete(self);
>
> > On Wed, Feb 25, 2009 at 3:11 PM, Nic Hubbard <nnhubb...@gmail.com> wrote:
>
> > > I have built a custom callback into my plugin, here is an example:
>
> > >  $.fn.matrixStatus = function(options) {
> > >    var defaults = {
> > >      urlSuffix: '?action=live',
> > >          onComplete: function() {}
> > >    };
>
> > >    var options = $.extend(defaults, options);
>
> > >    return this.each(function() {
> > >      var obj = $(this);
> > >          var itemDesc = obj.attr('rel');
> > >      var itemId = obj.attr('id');
> > >      var itemHref = obj.attr('href');
> > >      obj.click(function() {
> > >      if (!itemDesc == '') {
> > >                  var question = confirm('Are you sure you want to change 
> > > the status
> > > of "'+itemDesc+'"?');
> > >          } else {
> > >                  var question = confirm('Are you sure you want to change 
> > > the
> > > status?');
> > >          }
> > >        if (question) {
> > >          $.ajax({
> > >            type: 'POST',
> > >            url: itemHref + defaults.urlSuffix
> > >          });
>
> > >                  // Run our custom callback
> > >                  defaults.onComplete();
>
> > >        }
> > >        return false;
>
> > >      });
>
> > >    });
>
> > >  };
>
> > > For some reason when I try to use that function for a custom callback,
> > > it won't allow me to get the jQuery object that the plugin is
> > > targeting, so using $(this) within the onComplete function doesn't
> > > work and give me errors.  Any idea why this would be?

Reply via email to