Joel Birch wrote: > Here is the code: > --------------------------------------------- > > (function($){ > $.fn.superfish = function(o){ > var defaults = { > hoverClass : "sfHover", > delay : 400, > animation : {"opacity":"show"}, > speed : "normal" > }; > var over = function(){ > var $$ = $(this); > clearTimeout(this.sfTimer); > if (!$$.is("."+o.hoverClass)) { > $$.addClass(o.hoverClass) > .find("ul").animate(o.animation,o.speed) > .end() > .siblings().removeClass(o.hoverClass); > } > }; > var out = function(){ > var $$ = $(this); > this.sfTimer=setTimeout(function(){$$.removeClass > (o.hoverClass);},o.delay); > }; > o = $.extend(defaults, o || {}); > $("li[ul]",this) > .hover(over,out) > .find("a") > .focus(function(){ > $(this).parents("li[ul]").each(over); }) > .blur(function(){ $(this).parents("li[ul]").each(out); > }); > > return this; > }; > })(jQuery); > > Joel,
I think your plugin is certainly worthwhile. It is clean, readable, and expandable. I also like the method of using settimeout/cleartimeout as a queuing system. Of course, I never find out what can be improved with plugins until I actually implement them ;) It may be a good idea to store a primitive reference to the out function in order to avoid memory leaks. I would also add the ability to assign the suckerfish menu to multiple menus @ once. e.g. $('.nav').superfish();, where '.nav' references multiple suckerfish menu containers. Here is my *untested* rendition; (function($){ $.superfish = []; // will hold setTimout reference funtions $.fn.superfish = function(o){ var defaults = { hoverClass : "sfHover", delay : 400, animation : {"opacity":"show"}, speed : "normal" }; var over = function(){ // serialize this menu item if(!this.sfSerial) { this.sfSerial = $.superfish.length; // expando is now a primitive (int) $.superfish.push(false); } var $$ = $(this); clearTimeout($.superfish[this.sfSerial]); if (!$$.is("."+o.hoverClass)) { $$.addClass(o.hoverClass) .find("ul").animate(o.animation,o.speed) .end() .siblings().removeClass(o.hoverClass); } }; var out = function(){ var $$ = $(this); $.superfish[this.sfSerial]=setTimeout(function(){$$.removeClass (o.hoverClass);},o.delay); }; o = $.extend(defaults, o || {}); return this.each(function() { // multi-menu support $("li[ul]",this) .hover(over,out) .find("a") .focus(function(){ $(this).parents("li[ul]").each(over); }) .blur(function(){ $(this).parents("li[ul]").each(out); }); }); }; })(jQuery); Perhaps I'm way off in protecting the expando ... and I too would like to hear some feedback ;) ~ Brice _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/