Interesting, Byrne.

The first thing I always look-to is "A Plugin Development Pattern" by
Mike Alsup
  http://www.learningjquery.com/2007/10/a-plugin-development-pattern

Therein Mike has a few good ideas about handling options.  I really
like how Mike keeps the options accessible, as opposed to settable
only upon call.  That's one factor to consider here.

For a variety of reasons, I would recommend against designing this as
one monolithic plugin.  The jqGrid plugin is a good example of how a
loader can be used to include or exclude facets.

Speaking of facets, I wouldn't get too deep into this without first
examining the jQuery Aspect Oriented Plugin -- 
http://code.google.com/p/jquery-aop/
-- because, by the sounds of it, this might be right-up your alley as
an approach.

**--**  Steve

On Apr 15, 12:37 am, Byrne Reese <byrnere...@gmail.com> wrote:
> First, some background:
>
> I am one of the lead contributors to the Movable Type Open Source
> project and am currently engaged in writing a jquery plugin that would
> be used on all of the blogs the platform publishes. So far I have
> successfully written a surprisingly complex plugin that works like
> this:
>
>     $('#greeting').greet( options );
>
> Which would convert:
>
>    <div id="greeting"></div>
>
> Into a message that would look like this:
>
>    Welcome Byrne! (edit profile | logout)
>
> You get the idea.
>
> The options I need to pass into the plugin is pretty substantial so I
> won't bother you with the specifics.
>
> Here is my question:
>
> I want my plugin to surface multiple event handlers like the
> following:
>
> a) $('#id').greet( { loggedOutMessage: 'Welcome back %user!
> %logout' });
>
> This is from the example above.
>
> b) $('#id').loggedIn( function(user) { $(this).show(); alert(u.name +
> ' logged in'); } );
>
> This would be invoked when a user successfully logged in and would be
> invoked whenever a login event occurred (which happens mainly via
> Ajax). One use case for this function is to selective show an element
> that would otherwise be hidden if the user was logged out.
>
> c) $('#id').loggedOut( function() { $(this).hide(); } );
>
> Similar to (b) above, but this of course would respond to a logout
> event.
>
> Ok, finally the question: I would like for all of the above use cases
> to be served by the same plugin. There is a lot of shared code between
> all three and a lot of shared config options between them.
>
> I would like to somehow initialize the system once with the same
> config options, but then subsequently invoke the loggedIn, loggedOut
> and greet functions on various elements.
>
> I guess I am just a little lost on the best way to do this and was
> wondering if there was any kind of best practice I should follow
> here.
>
> Not knowing a lot about how I *should* do it, here are some ideas I
> have for what the client code could look like:
>
> Idea 1:
>
> $.mtInit( global_options );
> $(document).ready( function(){
>   $('#greet').greet( greet_specific_options );});
>
> $('.hide_when_logged_out').loggedIn( function() { $(this).show(); } );
> $('.hide_when_logged_out').loggedOut( function() { $(this).hide
> (); } );
>
> Idea 2:
>
> $.mtInit({
>   cookiePath: 'foo',
>   cookieDomain: 'bar',
>   cookieName: 'baz',
>   onLoggedIn: function() { $('#greeting').greet(); },
>   onLoggedOut: function() { $('.hide_when_logged_out').hide(); }
>
> });
>
> Does anyone have any thoughts to share on the best or better way to do
> this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to