speed up superfish for menus that doe not have an superfish arrow

since we have nr_of_todos context menus and one main menu, this saves time (about 50%)
This commit is contained in:
Reinier Balt 2009-03-31 13:23:29 +02:00
parent 480af3a2ab
commit bb54f67938

View file

@ -11,111 +11,124 @@
*/ */
;(function($){ ;(function($){
$.fn.superfish = function(op){ $.fn.superfish = function(op){
var sf = $.fn.superfish, var sf = $.fn.superfish,
c = sf.c, c = sf.c,
$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')), $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
over = function(){ over = function(){
var $$ = $(this), menu = getMenu($$); var $$ = $(this), menu = getMenu($$);
clearTimeout(menu.sfTimer); clearTimeout(menu.sfTimer);
$$.showSuperfishUl().siblings().hideSuperfishUl(); $$.showSuperfishUl().siblings().hideSuperfishUl();
}, },
out = function(){ out = function(){
var $$ = $(this), menu = getMenu($$), o = sf.op; var $$ = $(this), menu = getMenu($$), o = sf.op;
clearTimeout(menu.sfTimer); clearTimeout(menu.sfTimer);
menu.sfTimer=setTimeout(function(){ menu.sfTimer=setTimeout(function(){
o.retainPath=($.inArray($$[0],o.$path)>-1); o.retainPath=($.inArray($$[0],o.$path)>-1);
$$.hideSuperfishUl(); $$.hideSuperfishUl();
if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);} if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){
},o.delay); over.call(o.$path);
}, }
getMenu = function($menu){ },o.delay);
var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0]; },
sf.op = sf.o[menu.serial]; getMenu = function($menu){
return menu; var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
}, sf.op = sf.o[menu.serial];
addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); }; return menu;
},
addArrow = function($a){
$a.addClass(c.anchorClass).append($arrow.clone());
};
return this.each(function() { return this.each(function() {
var s = this.serial = sf.o.length; var s = this.serial = sf.o.length;
var o = $.extend({},sf.defaults,op); var o = $.extend({},sf.defaults,op);
o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){ o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
$(this).addClass([o.hoverClass,c.bcClass].join(' ')) $(this).addClass([o.hoverClass,c.bcClass].join(' '))
.filter('li:has(ul)').removeClass(o.pathClass); .filter('li:has(ul)').removeClass(o.pathClass);
}); });
sf.o[s] = sf.op = o; sf.o[s] = sf.op = o;
$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() { if (o.autoArrows)
if (o.autoArrows) addArrow( $('>a:first-child',this) ); $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
}) addArrow( $('>a:first-child',this) );
.not('.'+c.bcClass) })
.hideSuperfishUl(); .not('.'+c.bcClass)
.hideSuperfishUl();
var $a = $('a',this); var $a = $('a',this);
$a.each(function(i){ $a.each(function(i){
var $li = $a.eq(i).parents('li'); var $li = $a.eq(i).parents('li');
$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);}); $a.eq(i).focus(function(){
}); over.call($li);
o.onInit.call(this); }).blur(function(){
out.call($li);
});
});
o.onInit.call(this);
}).each(function() { }).each(function() {
var menuClasses = [c.menuClass]; var menuClasses = [c.menuClass];
if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass); if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
$(this).addClass(menuClasses.join(' ')); $(this).addClass(menuClasses.join(' '));
}); });
}; };
var sf = $.fn.superfish; var sf = $.fn.superfish;
sf.o = []; sf.o = [];
sf.op = {}; sf.op = {};
sf.IE7fix = function(){ sf.IE7fix = function(){
var o = sf.op; var o = sf.op;
if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined) if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
this.toggleClass(sf.c.shadowClass+'-off'); this.toggleClass(sf.c.shadowClass+'-off');
}; };
sf.c = { sf.c = {
bcClass : 'sf-breadcrumb', bcClass : 'sf-breadcrumb',
menuClass : 'sf-js-enabled', menuClass : 'sf-js-enabled',
anchorClass : 'sf-with-ul', anchorClass : 'sf-with-ul',
arrowClass : 'sf-sub-indicator', arrowClass : 'sf-sub-indicator',
shadowClass : 'sf-shadow' shadowClass : 'sf-shadow'
}; };
sf.defaults = { sf.defaults = {
hoverClass : 'sfHover', hoverClass : 'sfHover',
pathClass : 'overideThisToUse', pathClass : 'overideThisToUse',
pathLevels : 1, pathLevels : 1,
delay : 800, delay : 800,
animation : {opacity:'show'}, animation : {
speed : 'normal', opacity:'show'
autoArrows : true, },
dropShadows : true, speed : 'normal',
disableHI : false, // true disables hoverIntent detection autoArrows : true,
onInit : function(){}, // callback functions dropShadows : true,
onBeforeShow: function(){}, disableHI : false, // true disables hoverIntent detection
onShow : function(){}, onInit : function(){}, // callback functions
onHide : function(){} onBeforeShow: function(){},
}; onShow : function(){},
$.fn.extend({ onHide : function(){}
hideSuperfishUl : function(){ };
var o = sf.op, $.fn.extend({
not = (o.retainPath===true) ? o.$path : ''; hideSuperfishUl : function(){
o.retainPath = false; var o = sf.op,
var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass) not = (o.retainPath===true) ? o.$path : '';
.find('>ul').hide().css('visibility','hidden'); o.retainPath = false;
o.onHide.call($ul); var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
return this; .find('>ul').hide().css('visibility','hidden');
}, o.onHide.call($ul);
showSuperfishUl : function(){ return this;
var o = sf.op, },
sh = sf.c.shadowClass+'-off', showSuperfishUl : function(){
$ul = this.addClass(o.hoverClass) var o = sf.op,
.find('>ul:hidden').css('visibility','visible'); sh = sf.c.shadowClass+'-off',
sf.IE7fix.call($ul); $ul = this.addClass(o.hoverClass)
o.onBeforeShow.call($ul); .find('>ul:hidden').css('visibility','visible');
$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); }); sf.IE7fix.call($ul);
return this; o.onBeforeShow.call($ul);
} $ul.animate(o.animation,o.speed,function(){
}); sf.IE7fix.call($ul); o.onShow.call($ul);
});
return this;
}
});
})(jQuery); })(jQuery);