First, I don't see how just splitting things up into optional plug- 
ins really helps the problem. At most, it means that in some rare  
cases, collision will be less frequent. But the majority of people  
will not want to use jQuery without dom attributes or events. It can  
also result in the ugly situation where, if you decide you need a new  
plug-in halfway, you might break existing code because suddenly the  
meaning of a method changes.

That is, unless you also namespace all the methods (e.g. $ 
(...).events.click(...)), but that means the general chainability  
principle is hard to achieve. Perhaps it would work like this:

$(...).events.click(...).mouseover(...).dom.title(...).href 
(...).css.display(...);

You'd essentially have to build a namespace list object such as  
{ dom: { ... }, events: { ... }, css: { ... } }, but somehow also  
extend each of its members with the namespace list object itself. You  
would need a formal method of adding new namespaces to make it work.  
Something like:

jQuery.plugin = function (name, object) {
   // Maintain namespace list
   jQuery._namespaces = jQuery._namespaces || {};
   jQuery._namespaces[name] = object;
   // Insert namespace into jQuery prototype
   jQuery.fn[name] = object;
   // Insert existing namespaces into new namespace
   jQuery.extend(object, jQuery._namespaces);
   // Update existing namespaces with new namespace
   for (i in jQuery._namespaces) jQuery._namespaces[i][name] = object;
}

A multi-method plug-in (such as dom) would do:
jQuery.plugin('dom', { attr: function() { ... }, /* other methods */ }
while a single-method plug-in (e.g. farbtastic) would do:
jQuery.plugin('farbtastic', function () { ... });


However, I think we do need to look at actual jQuery use here, as  
this is all about convenience. In my own jQuery code (which I'll  
admit is not that fancy), I mostly use jQuery objects to bind event  
handlers. When I change CSS or DOM properties, it is almost always  
within the context of each(), so that I can just use 'this'. Most of  
my event handlers are anonymous functions which are really hard to  
unbind anyway. For CSS, I've never really found .css() to be  
cumbersome (I usually change CSS styles in groups anyway).

It might be useful to look at a bunch of plug-ins and other jQuery- 
using code and look at which methods are actually used the most.

Steven Wittens


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

Reply via email to