UI's widget factory is specifically for plugins that contain state and
can only be used once.  If your plugin is meant to do someone once and
be done, then you shouldn't use $.widget.  Without any detail about
what you want to do with your plugin, I can't really advise you on
whether or not you should be using $.widget.


On Feb 18, 9:07 am, Aleem B <[email protected]> wrote:
> [Originally post on jQuery-en]
>
> I created a widget and figured that it can only be called once per element:
>
> $.widget('ui.mywidget', {
>    _init: function() {
>        alert('hello');
>    }
>
> }
>
> $.widget("ui.mywidget", mywidget);
>
> $("#foo").mywidget(); // alerts hello
> $("#foo").mywidget(); // doesn't do anything
>
> now I understand this is by design because _init acts like a static
> constructor. however, I want to create a widget to add a panel to #foo
> each time it's called so:
>
> $("#foo").addpanel();
> $("#foo").addpanel();
>
> But that obvioulsy fails.What's the work around or what is a better
> design? I don't want to do:
> $("#foo").addpanel();
> $("#foo").addpanel("add");
> $("#foo").addpanel("add");
>
> because that requires an extra () call followed by ("add"), ("add").
>
> -- Aleem
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to