PageSourceSearch

https://ncbeonline.com/wp-content/themes/enfold/js/avia-snippet-megamenu.js?ver=4.4.1

js ncbeonline.com collected 2026-09-24 12:07:31 UTC 5,703 bytes, 230 lines download raw bytes

1//this file is only called if a main menu with submenu items is available
2
3(function($)
4{	
5    "use strict";
6
7    $(document).ready(function()
8    {	
9		//activates the mega menu javascript.
10		if($.fn.aviaMegamenu)
11		$(".main_menu .menu").aviaMegamenu({modify_position:true});
12    });
13
14
15
16// -------------------------------------------------------------------------------------------
17// Avia Menu
18// -------------------------------------------------------------------------------------------
19
20
21	$.fn.aviaMegamenu = function(variables)
22	{
23		var defaults =
24		{
25			modify_position:true,
26			delay:300
27		};
28
29		var options = $.extend(defaults, variables),
30		win			= $(window);
31		
32			
33
34		return this.each(function()
35		{
36			var the_html	= $('html:first'),
37				main		= $('#main .container:first'),
38				left_menu	= the_html.filter('.html_menu_left, .html_logo_center').length,
39				isMobile 	= $.avia_utilities.isMobile,
40				menu = $(this),
41				menuItems = menu.find(">li:not(.ignore_menu)"),
42				megaItems = menuItems.find(">div").parent().css({overflow:'hidden'}),
43				menuActive = menu.find('>.current-menu-item>a, >.current_page_item>a'),
44				dropdownItems = menuItems.find(">ul").parent(),
45				parentContainer = menu.parent(),
46				mainMenuParent = menu.parents('.main_menu').eq(0),
47				parentContainerWidth = parentContainer.width(),
48				delayCheck = {},
49				mega_open = [];
50				
51
52			if(!menuActive.length){ menu.find('.current-menu-ancestor:eq(0) a:eq(0), .current_page_ancestor:eq(0) a:eq(0)').parent().addClass('active-parent-item')}
53			if(!the_html.is('.html_header_top')) { options.modify_position = false; }
54			
55			
56			
57			menuItems.on('click' ,'a', function(e)
58			{
59				if(this.href == window.location.href + "#" || this.href == window.location.href + "/#")
60				e.preventDefault();
61			});
62
63			menuItems.each(function()
64			{
65				var item = $(this),
66					pos = item.position(),
67					megaDiv = item.find("div:first").css({opacity:0, display:"none"}),
68					normalDropdown = "";
69
70				//check if we got a mega menu
71				if(!megaDiv.length)
72				{
73					normalDropdown = item.find(">ul").css({display:"none"});
74				}
75
76				//if we got a mega menu or dropdown menu add the arrow beside the menu item
77				if(megaDiv.length || normalDropdown.length)
78				{
79					var link = item.addClass('dropdown_ul_available').find('>a');
80					link.append('<span class="dropdown_available"></span>');
81
82					//is a mega menu main item doesnt have a link to click use the default cursor
83					if(typeof link.attr('href') != 'string' || link.attr('href') == "#"){ link.css('cursor','default').click(function(e){ e.preventDefault(); }); }
84				}
85
86
87				//correct position of mega menus
88				if(options.modify_position && megaDiv.length)
89				{	
90					item.on('mouseenter', function(){ calc_offset(item, pos, megaDiv, parentContainerWidth) });
91				}
92
93
94
95			});
96			
97			
98			function calc_offset(item, pos, megaDiv, parentContainerWidth)
99			{	
100				pos = item.position();
101				
102				if(!left_menu)
103					{
104						if(pos.left + megaDiv.width() < parentContainerWidth)
105						{
106							megaDiv.css({right: -megaDiv.outerWidth() + item.outerWidth()  });
107							//item.css({position:'static'});
108						}
109						else if(pos.left + megaDiv.width() > parentContainerWidth)
110						{
111							megaDiv.css({right: -mainMenuParent.outerWidth() + (pos.left + item.outerWidth() ) });
112						}
113					}
114					else
115					{
116						if(megaDiv.width() > pos.left + item.outerWidth())
117						{
118							megaDiv.css({left: (pos.left* -1)});
119						}
120						else if(pos.left + megaDiv.width() > parentContainerWidth)
121						{
122							megaDiv.css({left: (megaDiv.width() - pos.left) * -1 });
123						}
124					}
125			}
126
127			function megaDivShow(i)
128			{
129				if(delayCheck[i] == true)
130				{
131					var item = megaItems.filter(':eq('+i+')').css({overflow:'visible'}).find("div:first"),
132						link = megaItems.filter(':eq('+i+')').find("a:first");
133						mega_open["check"+i] = true;
134
135						item.stop().css('display','block').animate({opacity:1},300);
136
137						if(item.length)
138						{
139							link.addClass('open-mega-a');
140						}
141				}
142			}
143
144			function megaDivHide (i)
145			{
146				if(delayCheck[i] == false)
147				{
148					megaItems.filter(':eq('+i+')').find(">a").removeClass('open-mega-a');
149
150					var listItem = megaItems.filter(':eq('+i+')'),
151						item = listItem.find("div:first");
152
153
154					item.stop().css('display','block').animate({opacity:0}
154,300, function()
155					{
156						$(this).css('display','none');
157						listItem.css({overflow:'hidden'});
158						mega_open["check"+i] = false;
159					});
160				}
161			}
162
163			if(isMobile)
164			{
165				megaItems.each(function(i){
166
167					$(this).bind('click', function()
168					{
169						if(mega_open["check"+i] != true) return false;
170					});
171				});
172			}
173
174
175			//bind event for mega menu
176			megaItems.each(function(i){
177
178				$(this).hover(
179
180					function()
181					{
182						delayCheck[i] = true;
183						setTimeout(function(){megaDivShow(i); },options.delay);
184					},
185
186					function()
187					{
188						delayCheck[i] = false;
189						setTimeout(function(){megaDivHide(i); },options.delay);
190					}
191				);
192			});
193
194
195			// bind events for dropdown menu
196			dropdownItems.find('li').addBack().each(function()
197			{
198				var currentItem = $(this),
199					sublist = currentItem.find('ul:first'),
200					showList = false;
201
202				if(sublist.length)
203				{
204					sublist.css({display:'block', opacity:0, visibility:'hidden'});
205					var currentLink = currentItem.find('>a');
206
207					currentLink.bind('mouseenter', function()
208					{
209						sublist.stop().css({visibility:'visible'}).animate({opacity:1});
210					});
211
212					currentItem.bind('mouseleave', function()
213					{
214						sublist.stop().animate({opacity:0}
214, function()
215						{
216							sublist.css({visibility:'hidden'});
217						});
218					});
219
220				}
221
222			});
223
224		});
225	};
226})(jQuery);
227
228
229
230

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.