Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I've started writing jquery plugin and I want:

To initialize it when I call it like this $('selector').sitemap(options);
To be able using some members(like 'loader', 'viewPort') in functions in plugin

Regard 1st: have I done it correctly in the way I wrote initialization(init function) or there is more correct\elegant way to do it?

Regard 2nd: in order to use members like 'loader', 'viewPort' I wrote all functions in sitemap object. have I done it right or there is more correct\elegant way to do it?

I'll be glad if you could suggest me Thank you very much

(function ($) {
    $.extend($.fn, {
        sitemap: function (options) {
            //check if applied on valid DIV element
            var canvas = this;
            if (!canvas.is('div')) return;
            var viewPort = null;
            var loader = $('<p id="initLoader">Loading...</p>');
            init();
            loadMap();
            function init() {
                //create viewPort div
                setCanvas();
            }
            function setCanvas() {
                         //set height and width
            }
            function loadMap() {
                viewPort.prepend(loader);
                buildMap($.parseJSON('{"pages":[]}'));
            }
            function buildMap(map){
              //...
           }
})(jQuery);


Thank you
Posted

Your plugin should always return "this" to stack call,

Have a look on this official documentation

Manfred is right, you should better post on jquery forums :)
 
Share this answer
 
Eventhough your chances are not all that bad for receiving good advice here on CP, I strongly advice to post your question on the jQuery forums: http://forum.jquery.com/[^]
That's were the developers and creators of this great javascript framework mix and mingle. Chance will be even greater to garner good advice there. The very same page I posted above also sports some great links to tutorials and I'm quite sure you shouldn't miss this one: Developing jQuery Plugins[^]

Regards,
Manfred
 
Share this answer
 
v2
Comments
Espen Harlinn 7-Feb-11 15:13pm    
Good answer :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900