[jQuery] Plugin development: Defaults & options: Questions?

2009-12-21 Thread Micky Hulse
I just wrote my first jQuery (test) plugin... This was my guide:



Questions:

==

1.

My plugin only takes one argument/option, and that is a target dom
element.

For example:

$('#div').myFunction({ target: '#targ' });

When it comes to the defaults, what is the best way to handle the
default value for an unknown target object?

This is what I am currently doing:

$.fn.myFunction.defaults = {
target: ''
};

But, I guess I am wondering what the best way to handle javascript
error checking for required options?

In other words, how you do you gracefully exit your plugin if the
"target" was not passed into the plugin as an option? Or, what if the
target div does not exist?

Tips? :)

2.

When calling my plugin:

$('#div').myFunction({ target: '#targ' });

If the only option is "target", can I do something like this instead:

$('#div').myFunction('#targ');

3.

Because "#targ" is a required argument, should I handle it differently
than your normal "options" object?

==

I hope those questions make sense.

A billion thanks in advance for the help!
Cheers,
Micky


[jQuery] Plugin development - how to access the current object from a "sub-method"?

2009-04-15 Thread Ricardo Tomasi

Supposing I have this:

jQuery.fn.myPlugin = function(){
//
};

jQuery.fn.myPlugin.myMethod = function(){
   // ?
};

$('#test').myPlugin.myMethod();

How can I access the current object or element collection from inside
jQuery.fn.myPlugin.myMethod? Is it possible at all?

thanks,
- ricardo


[jQuery] Plugin Development

2009-04-06 Thread Spot


How would one develop a plugin which can exist multiple times on the 
same page, without conflicting with each others namespaces?


[jQuery] plugin development

2007-04-17 Thread phpLord


Hi;

do you know any guide about plugin development except the documentation 
wiki page ?


like a tutorial on a simple plugin?

tHanks