1/* 2NAME: Jet Responsive Megamenu 3AUTHOR PAGE: http://codecanyon.net/user/marcoarib 4ITEM PAGE: http://codecanyon.net/item/jet-responsive-megamenu/5719593 5*/ 6 7(function($){ 8 9 jQuery.fn.jetmenu = function(options){ 10 var settings = { 11 indicator :true // indicator that indicates a submenu 12 ,speed :300 // submenu speed 13 ,delay :0 // submenu show delay 14 ,hideClickOut :true // hide submenus when click outside menu 15 ,align :"left" // menu alignment (left/right) 16 ,submenuTrigger :"hover" // defines if submenu appears after hover/click 17 } 18 $.extend( settings, options ); 19 20 var menu = $(".jetmenu"); 21 var lastScreenWidth = windowWidth(); 22 var bigScreen = false; 23 24 $(menu).prepend("<li class='showhide'><span class='title'>MENU</span><span class='icon'><em></em><em></em><em></em><em></em></span></li>"); 25 26 if(settings.indicator == true){ 27 $(menu).find("a").each(function(){ 28 if($(this).siblings(".dropdown, .megamenu").length > 0){ 29 $(this).append("<span class='indicator'></span>"); 30 } 31 }); 32 } 33 34 screenSize(); 35 36 $(window).resize(function() { 37 if(lastScreenWidth <= 768 && windowWidth() > 768){ 38 unbindEvents(); 39 hideCollapse(); 40 bindHover(); 41 if(settings.align == "right" && bigScreen == false){ 42 rightAlignMenu(); 43 bigScreen = true; 44 } 45 } 46 if(lastScreenWidth > 768 && windowWidth() <= 768){ 47 unbindEvents(); 48 showCollapse(); 49 bindClick(); 50 if(bigScreen == true){ 51 rightAlignMenu(); 52 bigScreen = false; 53 } 54 } 55 if(settings.align == "right"){ 56 if(lastScreenWidth > 768 && windowWidth() > 768) 57 fixSubmenuRight(); 58 } 59 else{ 60 if(lastScreenWidth > 768 && windowWidth() > 768) 61 fixSubmenuLeft(); 62 } 63 lastScreenWidth = windowWidth(); 64 }); 65 66 function screenSize(){ 67 if(windowWidth() <= 768){ 68 showCollapse(); 69 bindClick(); 70 if(bigScreen == true){ 71 rightAlignMenu(); 72 bigScreen = false; 73 } 74 } 75 else{ 76 hideCollapse(); 77 bindHover(); 78 if(settings.align == "right"){ 79 rightAlignMenu(); 80 bigScreen = true; 81 } 82 else{ 83 fixSubmenuLeft(); 84 } 85 } 86 } 87 88 function bindHover(){ 89 if (navigator.userAgent.match(/Mobi/i) || window.navigator.msMaxTouchPoints > 0 || settings.submenuTrigger == "click"){ 90 $(menu).find("a").on("click touchstart", function(e){ 91 e.stopPropagation(); 92 e.preventDefault(); 93 $(this).parent("li").siblings("li").find(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed); 94 if($(this).siblings(".dropdown, .megamenu").css("display") == "none"){ 95 $(this).siblings(".dropdown, .megamenu").stop(true, true).delay(settings.delay).fadeIn(settings.speed); 96 return false; 97 } 98 else{ 99 $(this).siblings(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed); 100 $(this).siblings(".dropdown").find(".dropdown").stop(true, true).fadeOut(settings.speed); 101 } 102 window.location.href = $(this).attr("href"); 103 }); 104 105 $(menu).find("li").bind("mouseleave", function(){ 106 $(this).children(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed); 107 }); 108 109 if(settings.hideClickOut == true){ 110 $(document).bind("click.menu touchstart.menu", function(ev){ 111 if($(ev.target).closest(menu).length == 0){ 112 $(menu).find(".dropdown, .megamenu").fadeOut(settings.speed); 113 } 114 }); 115 } 116 } 117 else{ 118 $(menu).find("li").bind("mouseenter", function(){ 119 $(this).children(".dropdown, .megamenu").stop(true, true).delay(settings.delay).fadeIn(settings.speed); 120 }).bind("mouseleave", function(){ 121 $(this).children(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed); 122 }); 123 } 124 } 125 126 function bindClick(){ 127 $(menu).find("li:not(.showhide)").each(function(){ 128 if($(this).children(".dropdown, .megamenu").length > 0){ 129 $(this).children("a").bind("click", function(e){ 130 if($(this).siblings(".dropdown, .megamenu").css("display") == "none"){ 131 $(this).siblings(".dropdown, .megamenu").delay(settings.delay).slideDown(settings.speed).focus(); 132 $(this).parent("li").siblings("li").find(".dropdown, .megamenu").slideUp(settings.speed); 133 return false;
134 } 135 else{ 136 $(this).siblings(".dropdown, .megamenu").slideUp(settings.speed).focus(); 137 firstItemClick = 1; 138 } 139 }); 140 } 141 }); 142 } 143 144 function showCollapse(){ 145 $(menu).children("li:not(.showhide)").hide(0); 146 $(menu).children("li.showhide").show(0); 147 $(menu).children("li.showhide").bind("click", function(){ 148 if($(menu).children("li").is(":hidden")){ 149 $(menu).children("li").slideDown(settings.speed); 150 } 151 else{ 152 $(menu).children("li:not(.showhide)").slideUp(settings.speed); 153 $(menu).children("li.showhide").show(0); 154 $(menu).find(".dropdown, .megamenu").hide(settings.speed); 155 } 156 }); 157 } 158 159 function hideCollapse(){ 160 $(menu).children("li").show(0); 161 $(menu).children("li.showhide").hide(0); 162 } 163 164 function rightAlignMenu(){ 165 $(menu).children("li").addClass("jsright"); 166 var items = $(menu).children("li"); 167 $(menu).children("li:not(.showhide)").detach(); 168 for(var i = items.length; i >= 1; i--){ 169 $(menu).append(items[i]); 170 } 171 fixSubmenuRight(); 172 } 173 174 function fixSubmenuRight(){ 175 $(menu).children("li").removeClass("last"); 176 var items = $(menu).children("li"); 177 for(var i = 1; i <= items.length; i++){ 178 if($(items[i]).children(".dropdown, .megamenu").length > 0){ 179 var lastItemsWidth = 0; 180 for(var y = 1; y <= i; y++){ 181 lastItemsWidth = lastItemsWidth + $(items[y]).outerWidth(); 182 } 183 if($(items[i]).children(".dropdown, .megamenu").outerWidth() > lastItemsWidth){ 184 $(items[i]).addClass("last"); 185 } 186 } 187 } 188 } 189 190 function fixSubmenuLeft(){ 191 $(menu).children("li").removeClass("fix-sub"); 192 var items = $(menu).children("li"); 193 var menuWidth = $(menu).outerWidth(); 194 var itemsWidth = 0; 195 for(var i = 1; i <= items.length; i++){ 196 if($(items[i]).children(".dropdown, .megamenu").length > 0){ 197 if($(items[i]).position().left + $(items[i]).children(".dropdown, .megamenu").outerWidth() > menuWidth){ 198 $(items[i]).addClass("fix-sub"); 199 } 200 } 201 } 202 } 203 204 function unbindEvents(){ 205 $(menu).find("li, a").unbind(); 206 $(document).unbind("click.menu touchstart.menu"); 207 $(menu).find(".dropdown, .megamenu").hide(0); 208 } 209 210 function windowWidth(){ 211 return document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth; 212 } 213 } 214 215}(jQuery)); 216 217 218 219 220 221 222
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.