PageSourceSearch

https://rvkstudios.is/wp-content/themes/enfold/js/avia-snippet-megamenu.js?ver=4.8.6.5

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

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.