Code:
/*
* Superfish v1.4.1 - jQuery menu widget
* Copyright (c) 2007 Joel Birch
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
*/
(function($){
$.superfish = {};
$.superfish.o = [];
$.superfish.op = {};
$.superfish.defaults = {
hoverClass : 'sfHover',
pathClass : 'overideThisToUse',
delay : 100,
animation : {opacity:'show'},
speed : 1500,
oldJquery : false, /* set to true if using jQuery version below 1.2 */
disableHI : false, /* set to true to disable hoverIntent usage */
// callback functions:
onInit : function(){},
onBeforeShow: function(){},
onShow : function(){}, /* note this name changed ('onshow' to 'onShow') from version 1.4 onward */
onHide : function(){}
};
$.fn.superfish = function(op){
var bcClass = 'sfbreadcrumb',
over = function(){
var $$ = $(this), menu = getMenu($$);
getOpts(menu,true);
clearTimeout(menu.sfTimer);
$$.showSuperfishUl().siblings().hideSuperfishUl();
},
out = function(){
var $$ = $(this), menu = getMenu($$);
var o = getOpts(menu,true);
clearTimeout(menu.sfTimer);
if ( !$$.is('.'+bcClass) ) {
menu.sfTimer=setTimeout(function(){
$$.hideSuperfishUl();
if (o.$path.length){over.call(o.$path);}
},o.delay);
}
},
getMenu = function($el){ return $el.parents('ul.superfish:first')[0]; },
getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return $.superfish.op = $.superfish.o[el.serial]; },
hasUl = function(){ return $.superfish.op.oldJquery ? 'li[ul]' : 'li:has(ul)'; };
return this.each(function() {
var s = this.serial = $.superfish.o.length;
var o = $.extend({},$.superfish.defaults,op);
o.$path = $('li.'+o.pathClass,this).each(function(){
$(this).addClass(o.hoverClass+' '+bcClass)
.filter(hasUl()).removeClass(o.pathClass);
});
$.superfish.o[s] = $.superfish.op = o;
$(hasUl(),this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out)
.not('.'+bcClass)
.hideSuperfishUl();
var $a = $('a',this);
$a.each(function(i){
var $li = $a.eq(i).parents('li');
$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
});
o.onInit.call(this);
}).addClass('superfish');
};
$.fn.extend({
hideSuperfishUl : function(){
var o = $.superfish.op,
$ul = $('li.'+o.hoverClass,this).add(this).removeClass(o.hoverClass)
.find('>ul').hide().css('visibility','hidden');
o.onHide.call($ul);
return this;
},
showSuperfishUl : function(){
var o = $.superfish.op,
$ul = this.addClass(o.hoverClass)
.find('>ul:hidden').css('visibility','visible');
o.onBeforeShow.call($ul);
$ul.animate(o.animation,o.speed,function(){ o.onShow.call(this); });
return this;
}
});
$(window).unload(function(){
$('ul.superfish').each(function(){
$('li',this).unbind('mouseover','mouseout','mouseenter','mouseleave');
});
});
$.fn.supposition = function(){
var $w = $(window), /* do this once instead of every onBeforeShow call*/
_offset = function(dir) {
return window[dir == 'y' ? 'pageYOffset' : 'pageXOffset']
|| document.documentElement && document.documentElement[dir=='y' ? 'scrollTop' : 'scrollLeft']
|| document.body[dir=='y' ? 'scrollTop' : 'scrollLeft'];
},
onInit = function(){
/* I haven't touched this bit - needs work as there are still z-index issues */
$topNav = $('li',this);
var cZ=parseInt($topNav.css('z-index')) + $topNav.length;
$topNav.each(function() {
$(this).css({zIndex:--cZ});
});
},
onHide = function(){
this.css({marginTop:'',marginLeft:''});
},
onBeforeShow = function(){
this.each(function(){
var $u = $(this);
$u.css('display','block');
var menuWidth = $u.width(),
parentWidth = $u.parents('ul').width(),
totalRight = $w.width() + _offset('x'),
menuRight = $u.offset().left + menuWidth;
if (menuRight > totalRight) {
$u.css('margin-left', '-152px');
}
var windowHeight = $w.height(),
offsetTop = $u.offset().top,
menuHeight = $u.height(),
baseline = windowHeight + _offset('y');
var expandUp = (offsetTop + menuHeight > baseline);
if (expandUp) {
$u.css('margin-top',baseline - (menuHeight + offsetTop));
}
$u.css('display','none');
});
};
return this.each(function() {
var o = $.superfish.o[this.serial]; /* get this menu's options */
/* if callbacks already set, store them */
var _onInit = o.onInit,
_onBeforeShow = o.onBeforeShow,
_onHide = o.onHide;
$.extend($.superfish.o[this.serial],{
onInit : function() {
onInit.call(this); /* fire our Supposition callback */
_onInit.call(this); /* fire stored callbacks */
},
onBeforeShow: function() {
onBeforeShow.call(this); /* fire our Supposition callback */
_onBeforeShow.call(this); /* fire stored callbacks */
},
onHide : function() {
onHide.call(this); /* fire our Supposition callback */
_onHide.call(this); /* fire stored callbacks */
}
});
});
};
})(jQuery);
Bookmarks