I don't think this approach will work quite the way you'd like. In your
example:
> // I access my plugin via:
> $("#myMap").Map({ <options hash> });
>
> // later I can access a public function on this object like:
> $("#myMap").Map.recenter(x, y, dxy);
Those two $("#myMap") calls are going to result in different jQuery objects.
How does the recenter() method know it applies to the Map object you created
earlier?
OTOH, you could easily get this to work:
// Create a map object for an element
var map = $("#myMap").Map({ <options hash> });
// later I can access a public function on this object like:
map.recenter(x, y, dxy);
But before I make any more specific suggestions, does your Map object always
relate to a single map as in your example, or could one Map object relate to
multiple maps, e.g.
// Get a Map object that controls every map with class anyMap
var maps = $('.anyMap').Map();
// Recenter all the maps
maps.recenter( x, y, dxy );
-Mike
> From: Stephen Woodbridge
>
> OK, How much of this is right?
>
> jQuery.Map = {
> // this is a public global attribute?
> // ie: global across all instances of jQuery.Map
> whatever : null,
>
> // a public function
> init : function(options)
> {
> // this is the jQuery search collection
> // self is a private pointer to the collection
> var self = this;
>
> // another private variable scoped to the function
> var _maph = 0;
>
> // an public attribute, accessed via $("#map").Map._maph
> this._maph = 0;
>
> // a method, accessed via $("#map").Map.recenter(x,y,dxy)
> this.recenter = function(x, y, dxy)
> {
> console.log("calling recenter()");
>
> };
>
> return this.each(
> function(options) {
>
> // this is each respective object in the collection
> // this is a DOM object not a jQuery object
>
> // here I can modify the DOM, bind events, etc
>
> };
> };
>
> // This extends jQuery with my plugin
> jQuery.fn.extend(
> {
> Map : jQuery.Map.init
> }
> );
>
> // I access my plugin via:
> $("#myMap").Map({ <options hash> });
>
> // later I can access a public function on this object like:
> $("#myMap").Map.recenter(x, y, dxy);
>
> Is this right? I probably have some terminology mixed up.
>
> -Steve
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/