/* * supposition v0.2 - an optional enhancer for superfish jquery menu widget. * * copyright (c) 2008 joel birch - based mostly on work by jesse klaasse and credit goes largely to him. * special thanks to karl swedberg for valuable input. * * dual licensed under the mit and gpl licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ /* * this is not the original jquery supposition plugin. * please refer to the readme for more information. */ (function($){ $.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']; }, onhide = function(){ this.css({bottom:''}); }, onbeforeshow = function(){ this.each(function(){ var $u = $(this); $u.css('display','block'); var $mul = $u.closest('.sf-menu'), level = $u.parents('ul').length, menuwidth = $u.width(), menuparentwidth = $u.closest('li').outerwidth(true), menuparentleft = $u.closest('li').offset().left, totalright = $w.width() + _offset('x'), menuright = $u.offset().left + menuwidth, exactmenuwidth = (menuright > (menuparentwidth + menuparentleft)) ? menuwidth - (menuright - (menuparentwidth + menuparentleft)) : menuwidth; if ($u.parents('.sf-js-enabled').hasclass('rtl')) { if (menuparentleft < exactmenuwidth) { if (($mul.hasclass('sf-horizontal') && level == 1) || ($mul.hasclass('sf-navbar') && level == 2)){ $u.css({left:0,right:'auto'}); } else { $u.css({left:menuparentwidth + 'px',right:'auto'}); } } } else { if (menuright > totalright && menuparentleft > menuwidth) { if (($mul.hasclass('sf-horizontal') && level == 1) || ($mul.hasclass('sf-navbar') && level == 2)){ $u.css({right:0,left:'auto'}); } else { $u.css({right:menuparentwidth + 'px',left:'auto'}); } } } var windowheight = $w.height(), offsettop = $u.offset().top, menuparentshadow = ($mul.hasclass('sf-shadow') && $u.css('padding-bottom').length > 0) ? parseint($u.css('padding-bottom').slice(0,-2)) : 0, menuparentheight = ($mul.hasclass('sf-vertical')) ? '-' + menuparentshadow : $u.parent().outerheight(true) - menuparentshadow, menuheight = $u.height(), baseline = windowheight + _offset('y'); var expandup = ((offsettop + menuheight > baseline) && (offsettop > menuheight)); if (expandup) { $u.css({bottom:menuparentheight + 'px',top:'auto'}); } $u.css('display','none'); }); }; return this.each(function() { var o = $.fn.superfish.o[this.serial]; /* get this menu's options */ /* if callbacks already set, store them */ var _onbeforeshow = o.onbeforeshow, _onhide = o.onhide; $.extend($.fn.superfish.o[this.serial],{ 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);