1/* 2 * Supposition v0.2 - an optional enhancer for Superfish jQuery menu widget. 3 * 4 * Copyright (c) 2008 Joel Birch - based mostly on work by Jesse Klaasse and credit goes largely to him. 5 * Special thanks to Karl Swedberg for valuable input. 6 * 7 * Dual licensed under the MIT and GPL licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl.html 10 */ 11/* 12 * This is not the original jQuery Supposition plugin. 13 * Please refer to the README for more information. 14 */ 15 16(function($){ 17 $.fn.supposition = function(){ 18 var $w = $(window), /*do this once instead of every onBeforeShow call*/ 19 _offset = function(dir) { 20 return window[dir == 'y' ? 'pageYOffset' : 'pageXOffset'] 21 || document.documentElement && document.documentElement[dir=='y' ? 'scrollTop' : 'scrollLeft'] 22 || document.body[dir=='y' ? 'scrollTop' : 'scrollLeft']; 23 }, 24 onHide = function(){ 25 this.css({bottom:''}); 26 }, 27 onBeforeShow = function(){ 28 this.each(function(){ 29 var $u = $(this); 30 $u.css('display','block'); 31 var $mul = $u.closest('.sf-menu'), 32 level = $u.parents('ul').length, 33 menuWidth = $u.width(), 34 menuParentWidth = $u.closest('li').outerWidth(true), 35 menuParentLeft = $u.closest('li').offset().left, 36 totalRight = $w.width() + _offset('x'), 37 menuRight = $u.offset().left + menuWidth, 38 exactMenuWidth = (menuRight > (menuParentWidth + menuParentLeft)) ? menuWidth - (menuRight - (menuParentWidth + menuParentLeft)) : menuWidth; 39 if ($u.parents('.sf-js-enabled').hasClass('rtl')) { 40 if (menuParentLeft < exactMenuWidth) { 41 if (($mul.hasClass('sf-horizontal') && level == 1) || ($mul.hasClass('sf-navbar') && level == 2)){ 42 $u.css({left:0,right:'auto'}); 43 } 44 else { 45 $u.css({left:menuParentWidth + 'px',right:'auto'}); 46 } 47 } 48 } 49 else { 50 if (menuRight > totalRight && menuParentLeft > menuWidth) { 51 if (($mul.hasClass('sf-horizontal') && level == 1) || ($mul.hasClass('sf-navbar') && level == 2)){ 52 $u.css({right:0,left:'auto'}); 53 } 54 else { 55 $u.css({right:menuParentWidth + 'px',left:'auto'}); 56 } 57 } 58 } 59 var windowHeight = $w.height(), 60 offsetTop = $u.offset().top, 61 menuParentShadow = ($mul.hasClass('sf-shadow') && $u.css('padding-bottom').length > 0) ? parseInt($u.css('padding-bottom').slice(0,-2)) : 0, 62 menuParentHeight = ($mul.hasClass('sf-vertical')) ? '-' + menuParentShadow : $u.parent().outerHeight(true) - menuParentShadow, 63 menuHeight = $u.height(), 64 baseline = windowHeight + _offset('y'); 65 var expandUp = ((offsetTop + menuHeight > baseline) && (offsetTop > menuHeight)); 66 if (expandUp) { 67 $u.css({bottom:menuParentHeight + 'px',top:'auto'}); 68 } 69 $u.css('display','none'); 70 }); 71 }; 72 73 return this.each(function() { 74 var o = $.fn.superfish.o[this.serial]; /* get this menu's options */ 75 76 /* if callbacks already set, store them */ 77 var _onBeforeShow = o.onBeforeShow, 78 _onHide = o.onHide; 79 80 $.extend($.fn.superfish.o[this.serial],{ 81 onBeforeShow: function() { 82 onBeforeShow.call(this); /* fire our Supposition callback */ 83 _onBeforeShow.call(this); /* fire stored callbacks */ 84 }, 85 onHide: function() { 86 onHide.call(this); /* fire our Supposition callback */ 87 _onHide.call(this); /* fire stored callbacks */ 88 } 89 }); 90 }); 91 }; 92})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.