Hmmm, ok.

So with that setup, I (as a user) could do
$.myAwesomePlugin.startRockin?  I notice you have the options stuff
under simply $.fn.myAwesomePlugin.  So what if I wanted to call
startRockin and set defaults, too?  Does
$.myAwesomePlugin.startRockin(options_go_here) do it? Or do I have to
do $.myAwesomePlugin(options_here), then
$.myAwesomePlugin.startRockin?

I've been reading these two articles over and over, and I've kind of
got it (I think) but one or two things I still don't quite grasp.  The
articles are:

http://docs.jquery.com/Plugins/Authoring
http://www.learningjquery.com/2007/10/a-plugin-development-pattern

I rather like the second article, it seems failry straightforward.  My
only complaint is that it doesn't show any example calls at the end
when all the code is put together.  And that is where I keep getting
hung up.

For my example:

I have my plugin that looks more or less like what I have in my intial
post.  When I try to call $.myAwesomePlugin.startRockin, firebug tells
me that $.myAwesomePlugin.startRockin has no properties.  From reading
the second article, it looks like maybe I want to do
$.fn.myAwesomePlugin.startRockin.  Which is great, but I have a few
different functions that use the same defaults/options, and I really
don't want to reproduce the options = $.extend code.

If someone could kindly tell me what I'm missing or getting mixed up
I'd greatly appreciate it.  I know I'm close.

On Mar 1, 8:59 am, "Scott González" <[EMAIL PROTECTED]> wrote:
> The most common approach is something like this:
>
> (function($) {
>         $.fn.myAwesomePlugin = function(options) {
>                 options = $.extend({}, $.myAwesomePlugin.defaults, options);
>                 $.myAwesomePlugin.rockOn();
>         };
>
>         // Make helper/utility functions accessible to users, so they can
> access
>         // them directly if they need to.
>         // Make defaults available for users to override.
>         $.myAwesomePlugin = {
>                 defaults: {
>                         [some defaultish stuff here]
>                 },
>
>                 rockOn: function() {
>                         $.myAwesomePlugin.startRockin();
>                         $.myAwesomePlugin.keepRockin();
>                 },
>
>                 startRockin: function() {
>                         // rockin' code
>                 },
>
>                 keepRockin: function() {
>                         // more rockin' code
>                 }
>         };
>
> })(jQuery);
>
> On Feb 29, 2:45 pm, Leanan <[EMAIL PROTECTED]> wrote:
>
> > I apologize if this seems noobish.
>
> > So let's say I want to write my own plugin (who woudln't?)
>
> > So I spec it out like this:
>
> > (function($) {
> >   $.fn.myAwesomePlugin = function(options) {
> >     var defaults = {
> >        [some defaultish stuff here]
> >     };
>
> >     var options = $.extend(defaults,options);
>
> >     function rockOn() {
> >       // I want to call another function in myAwesomePlugin here
> >     };
>
> > })(jQuery);
>
> > How do I call the other function in rockOn?  Say it's called
> > startRockin.
>
> > Do I do $.myAwesomePlugin.startRockin?
> > Do I simply do startRockin?
> > Would it be $this.startRockin?
>
> > I've been searching for this and so far I haven't seen much in any of
> > the tutorials I've found... and the plugins I have to dig through
> > don't seem to either: 1) have multiple functions 2) have those
> > functions call each other.
>
> > Thanks!

Reply via email to