Mike,
Many thanks for your reply, although I'm totally confused now ...
If I understand correctly;
- options is checked for being a string (method) or a function (set
of options)
- If it's a string (and using 'a', 'b' or 'c' from my previous
example) then execute the relevant code depending upon a,b or c.
- If it isn't then the plugin code continues as usual with either
user-supplied or default options, starting with the line 'options =
$.extend(defaults, options);'
If so, would doing this effect the 'options' or 'method' code by
preventing either being able to run functions within the plugin eg,
var someFunction = function(e) {
// do something
return false;
};
Thanks for your help.
djl
On 19 Feb 2009, at 13:16, Mike Alsup wrote:
Well, that sort of works, although I need to be able to pass (and
within the plugin provide default) options - I can do either but not
both so I'm a bit stumped:
Oh, I see what you mean now. Try something like this:
$.fn.myplugin = function(options) {
var defaults = { width: 300 };
if (typeof options == 'string')
options = { someDefaultOption: options };
else if ($.isFunction(option))
options = { callback: options };
options = $.extend(defaults, options);
...
};