Hi.

I'm working on a lgpl-ed button animation plugin that needs a reference in
the global scope, so that it can call its own functions through a
setTimeout() (animations).
See http://mediabeez.ws/mediaBeez/permalink.php?tag=buttonAnimated

I've started by working from the datePicker plugin code, but i'm uncertain
that this is the right approach afterall.
DatePicker extends $.fn with quite a few functions (names preceded by "dp"),
and then uses a second object (defined outside the jQuery scope) to
implement those functions.

My animations run by setTimeout(), and i use
jQuery("#selfID.selfClassName").baSomeFunction to call the animation steps.
Although it runs, i find the code kinda UGLY. ;)
All calls have to go through a semi-complex forwarding mechanism before they
end up in the implementation object.
btw; the source has been released, on the url above..

Adding new functions this way is cumbersome, they have to be listed in two
places, and $.fn.prototype is over-extended this way.
IIRC, $.fn.prototype works on every valid jquery selector. Wouldn't it be
better to only be able to call functions on selectors that have been
initialized with the plugin that provides those extra methods?

I suppose i could do away with the extensions to $.fn and create a custom
variable in the global scope that holds a reference to the implementation
object;
  var baAnimations = Array();
  selfJQueryID = '#btnName.buttonAnimated';
  baAnimations[selfJQueryID] = new buttonAnimated();


At this point, i'd just like some advice from people who have more
experience / authority in jquery plugin programming.
Would you recommend the 'custom variable in global scope' approach, or do
you have another way to provide direct access to the implementation object
from global scope? If there's some coding standard that i've missed, i'd
love to hear about it now..

Reply via email to