[jQuery] Re: Plugin developement
Another "solution" i found on a Blog. Instead of adding a function to the Plugin, create a seperate object within the scope of the plugin. ;(function($) { $.fn.pluginname = function(options) { // private method function _doSomethingPrivate() { } // public method $.fn.pluginname_doSomethingPublic = function() { _doSomethingPrivate(); return this; } }; Like that you still could write something like $ ('#example').pluginname().pluginname_doSomethingPublic().otherJquery(); Of course there are still some limits to it. ie not declared before $ ().pluginname(). So from this point of view the way jmap is handling it is indeed somehow better. Its just, i like the way of having seperate methods instead of having one multipurpose method. But i guess i will go the way jmap does it, i still can seperate the "comands" into private methods. Its just u can't realy seperate anymore into private or plubic methods. On 3 Sep., 16:30, Balazs Endresz <[EMAIL PROTECTED]> wrote: > It depends on what the public method returns. If it returns the jQuery > object (the 'this' inside the plugin) then you have to call $ > ('#example').pluginname.doSomethingPublic().pluginname.doSomethingElse(). > > If you want to chain your methods directly you have to return 'this' > inside your public methods, which refers to $.fn.pluginname (not to > the jquery object!). > But doing this will prevent you from chaining jquery methods (most of > the plugins are chainable). If you don't like this and would like to > get the jquery object back, you can do that with another public > method: > $.fn.pluginname.returnJQuery = function(){ return _jquery; } > where _jquery is defined where your _options object: var _jquery=this; > so $().pluginname.doSomethingPublic().doSomethingElse().returnJQuery() > will return the original jQuery object. > > The only problem(?) with both is that it's a bit different from how > jQuery is generally used. That's why, I think, the jMaps approach is > somewhat better. >
[jQuery] Re: Plugin developement
Hi, Wow, thanks to both of you. Wouldn't have thought about such an construct. Maybe because i'm not that familiar with javascript at all. Somehow i thought you can't access an object while creating it. But also the way Balazs was mentioning about jmap looks interesting. I will have a closer look into it soon. For now i will try out the way mentioned above. The only thing i don't like in this solution is, that after calling the method u can't add another right after like : $('#example').pluginname.doSomethingPublic().doSomethingElse(); is there a solution to it, except the way jmap does.
[jQuery] Re: Plugin developement
Is there realy nobody out there, who can point me into the right direction? A link to a tutorial would be already great. If somebody doesn't understand the question, please tell me, i will try to explain it further.
[jQuery] Plugin developement
Hi @ all, i have a problem with the understanding of public methods of an plugin. Specialy how to create and link them to the plugin. For example: ;(function($) { $.fn.pluginname = function(options) { var _options = $.extend( { label: "data", debug : false }, options || {}); return this.each(function() { // this works, of course _doSomethingPrivate(); // this too var data = _options.label; }); // private method function _doSomethingPrivate() { } }; // public method $.fn.pluginname.doSomethingPublic = function() { // this won't work _doSomethingPrivate(); // this is not accessible either var data = _options.label; } })(jQuery); Obviously the above code won't work. I've tried several things to get this working, but had no success. So please, can somebody explain me this or point me into the right direction. If this question was aked before (and i'm somehow sure of this, but had not found something jet) please let me know the Url. Sorry for my english, i'm not a native speaker of this language. Regards Martin
[jQuery] Re: $.get and $.getJSON
Does really nobody got an Idea? Greets Martin
[jQuery] $.get and $.getJSON
Hi, i encounter problems with the getJSON method when i do that: $.getJSON("http://localhost/jas/www/rmt.php5?action=airport_state";, {country: $(this).val()}, function(json) { $.log(json); }); nothing happends. there is even no connection trace in firebug but $.get("http://localhost/jas/www/rmt.php5?action=airport_state";, {country: $(this).val()}, function(json) { eval("var a = "+json); $.log(a); }); works fine php sends header("Content-type: application/json"); so thats fine to. jquery version is 1.2.2 Any suggestions? Martin