What I meant by the last question can probably be better explained by looking at this plugin code:

http://www.gimiti.com/kltan/demo/jTree/jquery.jtree.1.0.js


Take line 55 for example;

$(container).find("li").bind("mouseover", getInitial);

and then lines 134-140;

var getInitial = function(e){
                        off = $(this).offset();
                        h = $(this).height();
                        w = $(this).width();
                        hover = this;
                        return false;
                };


Assuming the same getInitial code is included in my plugin and I do the type-checking on the options argument and fork the code accordingly, will the getInitial variable/function be available throughout the plugin?

Put another way, I have a requirement to run the same piece of code - it will need to run upon initially calling the plugin and also made available as a method so it can be called when required, therefore I don't want to have to duplicate code

I hope this makes sense?

I'm a lot clearer on this than I was this morning, so thanks for your responses so far.


djl


On 19 Feb 2009, at 17:31, Mike Alsup wrote:


Many thanks for your reply, although I'm totally confused now ...

I was just giving an example of using type-checking on the options
argument.  The following is a real snippet from the ajaxSubmit fn of
the form plugin:

   if (typeof options == 'function')
       options = { success: options };

The common usage of the ajaxSubmit fn is to pass an option *object*.
But that fn also permits you to pass a callback function by itself.
If you do pass a callback then a new options object is created and its
success property is assigned to the callback.  (footnote: I should be
using $.isFunction in that test).

But what happens after you do your type checking is up to you.  In the
case of the ajaxSubmit example, processing continues as normal.


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;

};

Not sure I understand that last question, but I don't see why
"someFunction" would effect anything.

Mike

Reply via email to