[jQuery] Re: Custom Callback not using jQuery object

2009-04-16 Thread Nic Hubbard
Eric, I now have the need to take the callback out of the scope of the plugin, and put that into a function that is being called within the plugin, what would be the best way to do this? So, if I had: my_function(defaults.onComplete.apply(obj, [])); For some reason that does not seem like it w

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread pete higgins
I never miss an opportunity to mention my uberuseful tiny [and only] jQuery plugin. "hitch" http://higginsforpresident.net/js/jq.hitch.js http://higginsforpresident.net/js/jq.hitch.min.js Regards, Peter On Wed, Feb 25, 2009 at 4:58 PM, Nic Hubbard wrote: > > Thank you.  I appreciate the explan

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Nic Hubbard
Thank you. I appreciate the explanation, and for taking the time to thoroughly explain it! On Feb 25, 1:40 pm, Eric Garside wrote: > Sure. Basically apply allows you to declare the scope of the function > you're calling, instead of letting that scope resolve normally. With > any function, it wi

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Eric Garside
Sure. Basically apply allows you to declare the scope of the function you're calling, instead of letting that scope resolve normally. With any function, it will take on the scope of whatever encloses it. So if you declare a function without it being enclosed, "this" will resolve to "window" in alm

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Nic Hubbard
Ha! That worked perfectly! Thanks, I really appreciate that, I was lost. So, could you explain, just so I know, what this did: defaults.onComplete.apply(obj, []); ? On Feb 25, 1:07 pm, Eric Garside wrote: > The problem is you're losing scope when calling onComplete. Try using > the .apply met

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Eric Garside
If you want to pass it in as a parameter, yes. If you want it accessible as the "this" variable, you should be able to achieve that using .apply I threw a pretty straightforward test up on jsbin: http://jsbin.com/ecina/edit Apply lets you change the scoping of your object, which is how you can

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread brian
You need to specify what you'll be passing to the onComplete function. $('a.matrixStatus').matrixStatus({ urlSuffix: '?action=status_posting', onComplete: function(el) {alert('Callback worked'); alert(el.attr('class'));} }); obj.click(function() { var self = $(this); ... d

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Eric Garside
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.a

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread Nic Hubbard
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

[jQuery] Re: Custom Callback not using jQuery object

2009-02-25 Thread brian
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 wrote: > > I have built a custom callback into my plugin, here is an example: > >  $.fn.matrixStatus = function(options) { >