1/* 2 * SooperFish 0.1 3 * (c) 2010 Jurriaan Roelofs - SooperThemes.com 4 * Inspired by Suckerfish, Superfish and Droppy 5 * Licensed GPL: http://www.gnu.org/licenses/gpl.html 6 */ 7(function($){ 8$.fn.sooperfish = function(op) { 9 10 var sf = $.fn.sooperfish; 11 sf.o = []; 12 sf.op = {}; 13 sf.c = { 14 menuClass : 'sf-js-enabled', 15 isParent : 'sf-parent', 16 arrowClass : 'sf-arrow' 17 }; 18 if ($.easing.easeOutOvershoot) { //set default easing 19 sooperEasingShow = 'easeOutOvershoot'; 20 } else { 21 sooperEasingShow = 'linear'; 22 }; 23 if ($.easing.easeInTurbo) { 24 sooperEasingHide = 'easeInTurbo'; 25 } else { 26 sooperEasingHide = 'linear'; 27 }; 28 sf.defaults = { 29 multiColumn : true, 30 dualColumn : 6, //if a submenu has at least this many items it will be divided in 2 columns 31 tripleColumn : 12, //if a submenu has at least this many items it will be divided in 3 columns 32 hoverClass : 'sfHover', 33 delay : 500, //make sure menus only disappear when intended, 500ms is advised by Jacob Nielsen 34 animationShow : {height:'show'}, 35 speedShow : 600, 36 easingShow : sooperEasingShow, 37 animationHide : {height:'hide',opacity:'hide'}, 38 speedHide : 200, 39 easingHide : sooperEasingHide, 40 autoArrows : true, //Adds span elements to parent li elements, projecting arrow images on these items to indicate submenus. I added an alternative image file with white arrows. 41 onShow : function(){}, //callback after showing menu 42 onHide : function(){} //callback after hiding menu 43 }; 44 45 46 //Merge default settings with o function parameter 47 var o = $.extend({},sf.defaults,op); 48 if (!o.sooperfishWidth) { 49 o.sooperfishWidth = $('ul:first li:first', this).width(); //if no width is set in options try to read it from DOM 50 } else { 51 $('ul li', this).width(o.sooperfishWidth) //if width is set in invocation make sure this width is true for all submenus 52 } 53 54 this.each(function() { 55 56 //Check dom for submenus 57 var parentLi = $('li:has(ul)', this); 58 parentLi.each(function(){ 59 if (o.autoArrows) { //Add autoArrows if requested 60 $('>a',this).append('<span class="'+sf.c.arrowClass+'"></span>'); 61 } 62 $(this).addClass(sf.c.isParent); 63 }); 64 65 $('ul',this).css({left: 'auto',display: 'none'}); //The script needs to use display:none to make the hiding animation possible 66 67 //Divide menu in columns 68 //Set width override 69 if (o.multiColumn) { 70 var uls = $('ul',this); 71 uls.each(function(){ 72 var ulsize = $('>li:not(.backLava)',this).length; //Skip list items added by Lavalamp plugin 73 if (ulsize >= o.dualColumn) { 74 if (ulsize >= o.tripleColumn) { 75 $(this).width(3*o.sooperfishWidth).addClass('multicolumn triplecolumn'); 76 } else { 77 $(this).width(2*o.sooperfishWidth).addClass('multicolumn dualcolumn'); 78 } 79 } 80 }); 81 } 82 83 var root = this, zIndex = 1000; 84 85 function getSubmenu(ele) { 86 if (ele.nodeName.toLowerCase() == 'li') { 87 var submenu = $('> ul', ele); 88 return submenu.length ? submenu[0] : null; 89 } else { 90 return ele; 91 } 92 } 93 94 function getActuator(ele) { 95 if (ele.nodeName.toLowerCase() == 'ul') { 96 return $(ele).parents('li')[0]; 97 } else { 98 return ele; 99 } 100 } 101 102 function hideSooperfishUl() { 103 var submenu = getSubmenu(this); 104 if (!submenu) return; 105 $.data(submenu, 'cancelHide', false); 106 setTimeout(function() { 107 if (!$.data(submenu, 'cancelHide')) { 108 $(submenu).animate(o.animationHide,o.speedHide,o.easingHide,function(){ o.onHide.call(submenu); }); 109 } 110 }, o.delay); 111 } 112 113 function showSooperfishUl() { 114 var submenu = getSubmenu(this); 115 if (!submenu) return; 116 $.data(submenu, 'cancelHide', true); 117 $(submenu).css({zIndex: zIndex++}).animate(o.animationShow,o.speedShow,o.easingShow,function(){ o.onShow.call(submenu); }); 118 if (this.nodeName.toLowerCase() == 'ul') { 119 var li = getActuator(this); 120 $(li).addClass('hover'); 121 $('> a', li).addClass('hover'); 122 } 123 } 124 125 // Bind Events. Yes it's that simple! 126 $('li', this).unbind().hover(showSooperfishUl, hideSooperfishUl); 127 128 }); 129 130}; 131})(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.