Thanks for that Sam.

One further thing you might be able to help with. I have a function that
loops through some elements and then inside attaches a click even that
results in the HTML being reloaded... hence I need to call the function from
within itself.

My code looks like (I've put a note in where the call should be):

Thanks!
Tom

jQuery.fn.plotPins = function(gMap, gMarkerMan) {

 //Reference to this jquery function.
 var jElems = this;

 return this.each(function(){

   var listingID = jQuery(this).attr("id").replace(/pinned_/,"");
   var lat = jQuery("abbr.lat", this).attr("title");
   var lng = jQuery("abbr.lng", this).attr("title");

   //Create the marker
   var gPoint = new GLatLng(lat, lng);
   var gMarker = new GMarker(gPoint, {icon: this._gIcon, draggable: true,
bouncy: true});

   gMarkerMan.addMarker(gMarker, 1);
   //pinnedListings[listingID] = gMarker;

   //Attach the pull pin event.
   jQuery("ul.pinned_action li.pinned_remove a",this).click(function(){

       //Take the pin off the map.
       gMap.removeOverlay(gMarker);

       $("#pinned").load("ajax/GetPinned.ashx", {pull: listingID},
function(){

           //I want to call the current function from itself here... my
attempt that doesn't work is:
           //jQuery(jElems).plotPins(gMap, gMarkerMan);

       });

       //Do ajax here to pull the pin.
       return false;
   });

   //Add the marker to the marker manager
   //this._

 });

};

On 14/03/07, Sam Collett <[EMAIL PROTECTED]> wrote:

On 14/03/07, Tom Holder <[EMAIL PROTECTED]> wrote:
> Cheers Sam,
>
> That doesn't make a lot of sense to my I have to be honest.
>
> 1. Why are you starting with (function($)
This means that it would execute immediately and any variables
contained within the function won't be seen by other scripts.

> 2. Why $.fn inside this block? why not jQuery.fn
Results in a saving of code. It is whatever you used in 1.

> 3. What's (jQuery) on the end of the function?
jQuery is the jQuery object and is passed on as the parameter (the $
at the start).

A (hopefully) simpler example:

(function(parameter1, parameter2) {
        var space = " ";
        alert(parameter1 + space + parameter2); // alerts 'hello world'
})("hello", "world");
alert(space); // space is not defined

It is one of the suggestions for authoring plugins:
http://docs.jquery.com/Plugins/Authoring#Custom_Alias_in_plugin_code

>
> Sorry... OO Javascript is a whole new world of Pain for me! :)
>
> Thanks
> Tom
>
>
> On 14/03/07, Sam Collett < [EMAIL PROTECTED]> wrote:
> >
> > On 14/03/07, Tom Holder < [EMAIL PROTECTED]> wrote:
> > > Bit of a simple question this I'm sure but how do I scope a variable
to
> a
> > > plugin I'm creating and not expose it beyond my plugin? I do want
the
> > > variable to be accessible to all the methods in my plugin though.
> > >
> > >  Thanks
> > > Tom
> >
> > You could write your plugin like this:
> >
> > (function($) {
> >     var myvar = "Element number: ";
> >     $.fn.myplugin = function() {
> >         return this.each( function(i) {
> >             alert(myvar + i);
> >         });
> >     }
> > })(jQuery);
> > alert(myvar); // undefined
> >
> > _______________________________________________
> > jQuery mailing list
> > [email protected]
> > http://jquery.com/discuss/
> >
>
>
>
> --
> Tom Holder
>
> Technical Director
> SimpleWeb Limited
> Great websites. Low cost. No catch.
>
> http://www.simpleweb-online.co.uk/
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/




--
Tom Holder

Technical Director
SimpleWeb Limited
Great websites. Low cost. No catch.

http://www.simpleweb-online.co.uk/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to