Question about a possible plugin design pattern?

Question about a possible plugin design pattern?


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?