Re: [jQuery] Plugin Authoring : How to keep plugin state?

2007-02-18 Thread Blair Mitchelmore
If you only want the last time the function was called:

jQuery.debug; // Stores last called date for jQuery.fn.debug
jQuery.fn.debug = function() {
jQuery.debug = new Date();
return this.each(function() {
   alert(this);
});
};

Other things like recording all previous calls and possibly including 
the number of elements or other useful information would be similarly 
accomplished but would use an array rather than a simple Date Object. 
And obviously the variable name I chose simply for style, it can be any 
variable you want it to be.

-blair

howard chen wrote:
 e.g.

 jQuery.fn.debug = function() {
 // i want to save the current time into a global variable?
   return this.each(function(){
 alert(this);
   });
 };

 I want save the time of the last plugin being executed for later use,
 any recommened method?

 thanks.

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring: Custom Alias

2006-12-26 Thread Aaron Heimlich

I made a few minor spelling and grammar changes, but otherwise it's good.

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com

On 12/26/06, Jörn Zaefferer [EMAIL PROTECTED] wrote:


Hi folks,

just added the Custom Alias section to the plugin authoring guide. If
you don't know about this yet, check it out. Anyway, please correct or
improve it!

Link:
http://jquery.com/docs/Plugins/Authoring/#CustomAlias

--
Jörn Zaefferer

http://bassistance.de


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring: Custom Alias

2006-12-26 Thread Mike Alsup
 just added the Custom Alias section to the plugin authoring guide. If
 you don't know about this yet, check it out. Anyway, please correct or
 improve it!

Nice job, Jörn.  That's a handy page.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread John Resig
 Authoring guidelines say Always use jQuery instead of $ inside your
 plugin code - that allows users to change the alias for jQuery in a
 single place. Does this mean only the first line jQuery.fn... or
 should also extend be jQuery.extend()?

That means everywhere inside. So if you did $.extend() you should do
jQuery.extend() instead.

--John

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread John Resig
 jQuery.fn.pluginMethod = function(options) {
   var settings = $.extend({
 stuff: [5, 3, 6, 1],
 name: pete,
 speed: 5
   }, options || {});
   // other plugin code
 };

 So far this is the shortest way to write that particular snippet, and
 I'd like to see it in your plugins :-)

And this is even shorter, plus there's one less variable being defined:

jQuery.fn.pluginMethod = function(settings) {
settings = jQuery.extend({
// stuff
}, settings);
};

As noted previously - make sure that you use jQuery.extend() instead
of $.extend().

 Credits for the options || {} idea go to Franck Marcia.

Having to do that is no longer needed in SVN - I added a catch to see
if a null or undefined value was being passed in and handled it
gracefully.

--John

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread Klaus Hartl


John Resig schrieb:
 jQuery.fn.pluginMethod = function(options) {
   var settings = $.extend({
 stuff: [5, 3, 6, 1],
 name: pete,
 speed: 5
   }, options || {});
   // other plugin code
 };

 So far this is the shortest way to write that particular snippet, and
 I'd like to see it in your plugins :-)
 
 And this is even shorter, plus there's one less variable being defined:
 
 jQuery.fn.pluginMethod = function(settings) {
 settings = jQuery.extend({
 // stuff
 }, settings);
 };
 
 As noted previously - make sure that you use jQuery.extend() instead
 of $.extend().
 
 Credits for the options || {} idea go to Franck Marcia.
 
 Having to do that is no longer needed in SVN - I added a catch to see
 if a null or undefined value was being passed in and handled it
 gracefully.
 
 --John

This is cool, but as plugin developer I cannot assume the latest jQuery 
SVN version, right?

-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread John Resig
 This is cool, but as plugin developer I cannot assume the latest jQuery
 SVN version, right?

Right - once this feature comes out (say, 1.0.3) then it would be more
acceptable to require it. I guess you could always just be on the safe
side and do || {}, at least until the release of 1.1 (to which
everyone should upgrade).

--John

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread Jörn Zaefferer
Hi John!
 And this is even shorter, plus there's one less variable being defined:

 jQuery.fn.pluginMethod = function(settings) {
 settings = jQuery.extend({
 // stuff
 }, settings);
 };

 As noted previously - make sure that you use jQuery.extend() instead
 of $.extend().
   
Thanks for correcting the $/jQuery issue, didn't see that.
   
 Credits for the options || {} idea go to Franck Marcia.
 

 Having to do that is no longer needed in SVN - I added a catch to see
 if a null or undefined value was being passed in and handled it
 gracefully.
   
Cool, checking for arguments.length should make it pretty safe.
 This is cool, but as plugin developer I cannot assume the latest jQuery
 SVN version, right?
 

 Right - once this feature comes out (say, 1.0.3) then it would be more
 acceptable to require it. I guess you could always just be on the safe
 side and do || {}, at least until the release of 1.1 (to which
 everyone should upgrade).
   
Well, actually not everyone should update. I think we need to start to 
roll on two tracks at some point. On one hand, we have to keep the API 
stable while fixing bugs. On the other hand, we have to evolve the API, 
to make it better in the long term.

Consider someone using 1.0.2 in a big project. He wants bugfixes and a 
stable API, he won't care much about new features. Consider someone else 
who wants to start a new project or add jQuery to an existing one, he 
wants an API at it's best.

I think it's very hard to provide both at the same time with only one 
branch. But I wouldn't mind if you have a nice solution at hand :-)

-- Jörn



___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread Jörn Zaefferer
Dave Methvin schrieb:
 Still, if you're writing a plugin only for your personal (well, non-public)
 use and you're not using prototype.js, then you can freely use $() in
 plugins because there will be no conflict.
   
I like the idea of using $ for prototyping. When you go back and 
refactor and most likely manage code via plugins, switch to jQuery 
instead of $. Search and replace should work in most cases.

-- Jörn

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Plugin Authoring

2006-10-15 Thread Michael Geary
  Authoring guidelines say Always use jQuery instead of $ 
  inside your plugin code - that allows users to change the
  alias for jQuery in a single place. Does this mean only
  the first line jQuery.fn... or should also extend be
  jQuery.extend()?

 That means everywhere inside. So if you did $.extend() you should do
 jQuery.extend() instead.

I like coding with $ too much to give it up, so I do this:

   (function( $ ) {
  // Plugin code goes here. You can use $ instead
  // of jQuery, and you can use var to declare
  // private variables.
   })( jQuery );

As often as not I need some private data for the plugin anyway, so the
closure gives me that and lets me rename jQuery to $ at the same time. Very
convenient.

-Mike


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/