Jörn Zaefferer wrote:
> As far as I know, that is yet an unresearched topic.
> 
> So far there is a nice guide and tons of example code for writing plugins, 
> but not for
> extending them.
> 
> So far someone extends his local copy for his own needs and trie to 
> contribute them back to
> the original. Or they start their own version. Thickbox is a good example for 
> this: There has
> been contributions in both forms.
> 
> If I'd write a plugin that is flexible enough to be extended in every aspect, 
> it would
> contain lots of code only to allow that flexibility, I wouldn't want that in 
> most cases.

As a plugin author (http://jquery.lukelutman.com/plugins/flash/index.html), I 
think there are a
few ways you may be able to make it easy for other developers to build on top 
of your code.

## Store functions that depend on or generate markup where they can be 
overwritten.

For example, instead of:
$.fn.plugin = function(options){
     this.each(function(){
         // munge html here
     });
};

Use:
$.fn.plugin = function(options){
     this.each($.fn.plugin.munge,[options]);
};
$.fn.plugin.munge = function(options){
     // munge html here
};

## Allow blocks to be passed (temporarily replacing the default) when the 
method is called.

For example:
$.fn.plugin = function(options, munge) {
    this.each(munge || $.fn.plugin.munge, [options]);
};
$.fn.plugin.munge = function(options){
    // do stuff
};

Could be called like this:
$('.normal').plugin({ foo: 'bar'});

Or:
$('.custom').plugin({ foo: 'bar' }, function(options){
    // do custom stuff
});

That way, another author can change how the html gets munged (by passing a 
block function or 
overwriting $.fn.plugin.munge), without having to change the source of the 
original plugin. It 
doesn't really add much extra code, and makes your plugin less dependent on a 
specific markup 
structure :-)

Luke

-- 
zinc Roe Design
www.zincroe.com
(647) 477-6016

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to