PageSourceSearch

https://www.motif.es/modules/leobootstrapmenu/views/js/leobootstrapmenu.js

js motif.es collected 2026-10-08 09:20:20 UTC 20,567 bytes, 562 lines download raw bytes

1/**
2 * @copyright Commercial License By LeoTheme.Com 
3 * @email leotheme.com
4 * @visit http://www.leotheme.com
5 */
6$(document).ready(function() {
7	
8	$.each(list_menu,function(index,value){
9		// console.log(value.type);
10		if (value.type == "horizontal")
11		{
12			var megamenu_element = $('.cavas_menu[data-megamenu-id='+value.id+']');
13			// console.log(megamenu_element);
14			//DONGND:: type horizontal menu
15			//DONGND:: check active link
16			if($("body").attr("id")=="index") isHomeMenu = 1;
17			megamenu_element.find(".megamenu > li > a").each(function() {
18				menuURL = $(this).attr("href").replace("https://","").replace("http://","").replace("www.","").replace( /#\w*/, "" );
19				if( (currentURL == menuURL) || (currentURL.replace(current_link,"") == menuURL) || isHomeMenu){
20					$(this).parent().addClass("active");
21					return false;
22				}
23			});
24			
25			//DONGND:: check target
26			// console.log($(window).width());
27			if($(window).width() <= 767){
28				set_target_blank(false, megamenu_element);	// set cavas NO
29			}else{
30				set_target_blank(true, megamenu_element);		// set cavas Yes
31			}
32			
33			// console.log('test');
34			// console.log(show_cavas);
35			
36			//DONGND:: off canvas menu
37			if(value.show_cavas == 1)
38			{
39				// console.log('test');
40				$.fn.OffCavasmenu = function(opts) {
41					// default configuration
42					var config = $.extend({}, {
43						opt1: null,
44						text_warning_select: text_warning_select_txt,
45						text_confirm_remove: text_confirm_remove_txt,
46						JSON: null
47					}, opts);
48					// main function
49					// initialize every element
50					this.each(function() {
51						// console.log('test');
52						var $btn = megamenu_element.find('.navbar-toggler');
53						// console.log($btn);
54						var $nav = null;
55						if (!$btn.length)
56							return;
57						var $nav = $("<section class='off-canvas-nav-megamenu' data-megamenu-id="+value.id+"><nav class='offcanvas-mainnav' ><div class='off-canvas-button-megamenu'><span class='off-canvas-nav'></span>"+close_bt_txt+"</div></nav></section>");
58						// console.log($($btn.data('target')).find('.megamenu'));
59						var $menucontent = $($btn.data('target')).find('.megamenu').clone();
60						$("body").append($nav);
61						
62						$('body main').append("<div class='megamenu-overlay' data-megamenu-id="+value.id+"></div>");
63						
64						$(".megamenu-overlay[data-megamenu-id="+value.id+"]").click(function(){
65							$btn.trigger('click');
66						});
67						// console.log('test');
68						$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").append($menucontent);
69						$("html").addClass ("off-canvas");
70						$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"]").find(".off-canvas-button-megamenu").click( function(){							
71							off_canvas_active();
72						} );
73						
74						if($btn.is(':visible')) {
75							$("body").removeClass("off-canvas-active").addClass("off-canvas-inactive");
76						}
77						
78						$btn.click(function(){
79							// if (!$(".off-canvas-megamenu[data-megamenu-id="+value.id+"]").hasClass('off-canvas-nav-megamenu'))
80							// {
81								// $(".off-canvas-megamenu[data-megamenu-id="+value.id+"]").addClass('off-canvas-nav-megamenu');
82							// }
83							// console.log($(window).height());
84							// console.log($('.offcanvas-mainnav').height());
85							// if($(window).height() > $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height())
86							// {
87								// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height($(window).height());
88							// }
89							// else
90							// {
91								// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height('auto');
92							// }
93							off_canvas_active();
94							$('.off-canvas-nav-megamenu').removeClass('active');
95							if (!$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"]").hasClass('active') && $('body').hasClass('off-canvas-active'))
96							{
97								$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"]").addClass('active');
98								auto_height(value.id);
99							}
100							
101							// $(".off-canvas-megamenu[data-megamenu-id!="+value.id+"]").removeClass('off-canvas-nav-megamenu');
102							
103						});
104							
105							
106					});
107					return this;
108				}
109				// console.log(megamenu_element);
110				megamenu_element.OffCavasmenu();
111				megamenu_element.find('.navbar-toggler').click(function() {
112					$('body,html').animate({
113						scrollTop: 0
114					}, 0);
115					return false;
116				});
117				
118				$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"]").find('.offcanvas-mainnav .caret').click(function(){
119					
120					if($(this).parent('li').hasClass('open-sub'))
121					{
122						$(this).parent('li').find('.dropdown-menu').first().slideUp('fast',function (){
123							// console.log($(window).height());
124							// console.log($(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height());
125							// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height('auto');
126							// if($(window).height() > $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height())
127							// {
128								// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height($(window).height());
129							// }
130							auto_height(value.id);
131						});
132						$(this).parent('li').removeClass('open-sub');
133					}
134					else
135					{
136						// $('.offcanvas-mainnav li.open-sub').find('.dropdown-menu').first().slideUp('fast');
137						$(this).parent('li').siblings('.open-sub').find('.dropdown-menu').first().slideUp('fast');
138						$(this).parent('li').siblings().removeClass('open-sub');
139						$(this).parent('li').find('.dropdown-menu').first().slideDown('fast',function (){
140							// console.log($(window).height());
141							// console.log($(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height());
142							// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height('auto');
143							// if($(window).height() > $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height())
144							// {
145								// $(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").height($(window).height());
146							// }
147							auto_height(value.id);
148						});
149						$(this).parent('li').addClass('open-sub');
150					}
151					
152					
153				});
154				
155				$(window).resize(function() {
156					
157					// console.log($(window).width());
158					// if( $(window).width() > 523 ){
159					if( $(window).width() > 991 ){
160						$("body").removeClass("off-canvas-active").addClass("off-canvas-inactive");
161					}
162					else
163					{						
164						auto_height(value.id);
165					}
166				});
167			}
168			else
169			{
170				var $bt = megamenu_element.find('.navbar-toggler');
171				var $menu = megamenu_element.find('.leo-top-menu');
172				//DONGND:: add class for menu element when click button to show menu at mobile, tablet
173				$bt.click(function(){				
174					if ($menu.hasClass('in'))
175					{
176						megamenu_element.removeClass('active');
177					}
178					else
179					{
180						if (!megamenu_element.hasClass('active'))
181						{
182							megamenu_element.addClass('active');
183						}
184					}
185				});
186				megamenu_element.find('.leo-top-menu .dropdown-toggle').removeAttr("disabled");
187				megamenu_element.find(".dropdown-toggle").click(function() {
188					if($(window).width() <= 767){
189						if($(this).parent("li").find("div:first").hasClass("level2"))
190							return false;
191						else
192							return true;
193					}
194				});
195				//DONGND::
196				megamenu_element.find(".leo-top-menu li a").each(function(){
197					// console.log($(this));
198					// console.log((this).hasAttribute('data-toggle'));
199					if((this).hasAttribute('data-toggle')){
200						
201						$(this).removeAttr('data-toggle');
202						
203					}
204				});
205				megamenu_element.find(".leo-top-menu li a.dropdown-toggle").click(function(){			
206					if(!$(this).parent().hasClass('open') && this.href && this.href != '#'){
207						window.location.href = this.href;
208					}
209				})
210				// console.log('aaa');
211				megamenu_element.find(".leo-top-menu .caret").click(function(){
212					// console.log('test');
213					if($(this).parent('li').hasClass('open-sub'))
214					{
215						$(this).parent('li').find('.dropdown-menu').first().slideUp('fast', function(){
216							auto_height_off(megamenu_element);
217						});
218						$(this).parent('li').removeClass('open-sub');
219					}
220					else
221					{
222						// $('.offcanvas-mainnav li.open-sub').find('.dropdown-menu').first().slideUp('fast');
223						$(this).parent('li').siblings('.open-sub').find('.dropdown-menu').first().slideUp('fast');
224						$(this).parent('li').siblings().removeClass('open-sub');
225						$(this).parent('li').find('.dropdown-menu').first().slideDown('fast', function(){
226							auto_height_off(megamenu_element);
227						});
228						$(this).parent('li').addClass('open-sub');
229					}
230				});
231				
232				if ($(document).width() >543)
233				{				
234					megamenu_element.find('.leo-top-menu .dropdown-menu').css('display', '');						
235				}
236				auto_height_off(megamenu_element);
237				$(window).resize(function(){
238					auto_height_off(megamenu_element);
239					if ($(document).width() >543)
240					{
241						megamenu_element.find('.leo-top-menu .dropdown').removeClass('open-sub');
242						megamenu_element.find('.leo-top-menu .dropdown-submenu').removeClass('open-sub');
243						megamenu_element.find('.leo-top-menu .dropdown-menu').css('display', '');	
244					}
245				});
246			}
247		}
248		else
249		{
250			//DONGND:: type vertical menu
251			var megamenu_element = $('.leo-verticalmenu[data-megamenu-id='+value.id+']');
252			megamenu_element.find('.verticalmenu .dropdown-toggle').removeAttr("disabled");
253			megamenu_element.find(".verticalmenu .dropdown-toggle").click(function() {
254				if($(window).width() <= 767){
255					if($(this).parent("li").find("div:first").hasClass("level2"))
256						return false;
257					else
258						return true;
259				}		
260			});
261			// megamenu_element.find('.verticalmenu .dropdown-toggle').prop('disabled', true);
262			// megamenu_element.find('.verticalmenu .dropdown-toggle').data('toggle', '');
263			megamenu_element.find('.verticalmenu .dropdown-toggle').removeAttr('data-toggle');
264			megamenu_element.find(".verticalmenu .caret").click(function(){
265				if($(this).parents('.verticalmenu').hasClass('active-button'))
266				{
267					// console.log('test');
268					var $parent  = $(this).parent('li');
269					// console.log($parent.hasClass('open-sub'));
270					// $parent.toggleClass('open-sub');
271					if($parent.hasClass('open-sub'))
272					{
273						// console.log('test');
274						$parent.find('.dropdown-menu').first().slideUp('fast',function(){
275							$parent.removeClass('open-sub');
276						});
277						
278					}
279					else
280					{
281						
282						if($parent.siblings('.open-sub').length > 0)
283						{
284							$parent.siblings('.open-sub').find('.dropdown-menu').first().slideUp('fast',function(){								
285								$parent.siblings('.open-sub').removeClass('open-sub');								
286							});
287							$parent.find('.dropdown-menu').first().slideDown('fast',function(){
288								$parent.addClass('open-sub');
289							});
290						}
291						else
292						{
293							$parent.find('.dropdown-menu').first().slideDown('fast',function(){
294								$parent.addClass('open-sub');
295							});
296						}
297						
298						
299						
300					}
301					return false;
302				}
303				
304			});
305			if ($(window).width() >991)
306			{
307				megamenu_element.find('.verticalmenu').addClass('active-hover');
308				megamenu_element.find('.verticalmenu').removeClass('active-button');
309				megamenu_element.find('.verticalmenu .dropdown-menu').css('display', '');
310				megamenu_element.find('.leo-verticalmenu').removeClass('active');
311			
312			}
313			else
314			{
315				megamenu_element.find('.verticalmenu').removeClass('active-hover');
316				megamenu_element.find('.verticalmenu').addClass('active-button');
317			}
318			$(window).resize(function(){
319				if ($(window).width() >991)
320				{
321					megamenu_element.find('.verticalmenu .dropdown').removeClass('open-sub');
322					megamenu_element.find('.verticalmenu .dropdown-submenu').removeClass('open-sub');
323					megamenu_element.find('.verticalmenu').addClass('active-hover');
324					megamenu_element.find('.verticalmenu').removeClass('active-button');
325					megamenu_element.find('.verticalmenu .dropdown-menu').css('display', '');
326					megamenu_element.removeClass('active');
327				}else{
328					megamenu_element.find('.verticalmenu').removeClass('active-hover');
329					megamenu_element.find('.verticalmenu').addClass('active-button');
330				}
331			});
332			scrollSliderBarMenu(megamenu_element);
333		}
334		
335		//DONGND:: js for tab html
336		if ( typeof value.list_tab !== 'undefined' && value.list_tab.length > 0)
337		{		
338			$.each(value.list_tab,function(key,val){				
339				megamenu_element.find('#tabhtml'+val+' .nav a').click(function (e) {
340					e.preventDefault();
341					$(this).tab('show');
342				})
343				
344				//DONGND:: fix for widget tab of off canvas menu on mobile
345				$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"]").find('#tabhtml'+val+' .nav a').click(function (e) {
346					e.preventDefault();					
347					if (!$(this).hasClass('active'))
348					{					
349						var wrapper_tab = $(this).closest('.panel-group');
350						var tab_href = $(this).attr('href');
351						wrapper_tab.find('.nav-link').removeClass('active');
352						wrapper_tab.find('.nav-item').removeClass('active');
353						wrapper_tab.find('.tab-pane').removeClass('active');
354						$(this).addClass('active');
355						$(this).parents('.nav-item').addClass('active');
356						wrapper_tab.find(tab_href).addClass('active');
357					}
358				})
359			});		
360		}
361		
362		//DONGND:: js for widget image gallery category
363		if ( typeof value.level !== 'undefined' && typeof value.limit !== 'undefined')
364		{
365			megamenu_element.find('.widget-category_image ul.level0').each(function(){				
366				$(this).find('ul').removeClass('dropdown-sub dropdown-menu');
367			});
368				
369			megamenu_element.find(".widget-category_image ul.level0").each(function() {
370				var check_level = $(this).parents('.widget-category_image').data('level');
371				var check_limit = $(this).parents('.widget-category_image').data('limit');
372				
373				//DONGND:: remove .caret by check level
374				$(this).find("ul.level" + check_level).parent().find('.caret').remove();
375				//DONGND:: remove ul by check level
376				$(this).find("ul.level" + check_level + " li").remove();
377				
378				var element = $(this).find("ul.level" + (check_level - 1) + " li").length;
379				var count = 0;
380				if(check_level > 0) {
381					$(this).find("ul.level" + (check_level - 1) + " >li").each(function(){
382						count = count + 1;
383						if(count > check_limit){
384							$(this).remove();
385						}
386					});
387				}
388			});
389			
390			//DONGND:: add for off canvas menu
391			$(".off-canvas-nav-megamenu[data-megamenu-id="+value.id+"] .offcanvas-mainnav").find(".widget-category_image ul.level0").each(function() {
392				var check_level = $(this).parents('.widget-category_image').data('level');
393				var check_limit = $(this).parents('.widget-category_image').data('limit');
394				//DONGND:: remove .caret by check level
395				$(this).find("ul.level" + check_level).parent().find('.caret').remove();
396				//DONGND:: remove ul by check level
397				$(this).find("ul.level" + check_level + " li").remove();
398				var element = $(this).find("ul.level" + (check_level - 1) + " li").length;
399				var count = 0;
400				if(check_level > 0) {
401					$(this).find("ul.level" + (check_level - 1) + " >li").each(function(){
402						count = count + 1;
403						if(count > check_limit){
404							$(this).remove();
405						}
406					});
407				}
408			});
409		}
410		
411		if (value.type == "horizontal")
412		{
413			$(window).resize(function() {
414				// console.log($(window).width());
415				if( $(window).width() <= 767 ){
416					set_target_blank(false, megamenu_element);	// set cavas NO
417				}
418				else {
419					set_target_blank(true, megamenu_element);		// set cavas Yes
420				}
421			});
422		}
423
424		//if (value.type == "horizontal" && value.show_cavas == 1)
425		if (value.type == "horizontal" && value.show_cavas == 1)
426		{
427			$(document.body).on('click', '[data-toggle="dropdown"]' ,function(){
428				if(!$(this).parent().hasClass('open') && this.href && this.href != '#'){
429					window.location.href = this.href;
430				}
431			});
432		}
433	})
434	//DONGND:: js for widget image gallery product
435	$(".fancybox").fancybox({
436		openEffect	: 'none',
437		closeEffect	: 'none'
438	});
439
440})
441
442//DONGND:: auto calculate height of off canvas menu off
443function auto_height_off(menu_object)
444{	
445	wrapper_height = $("#page").innerHeight();
446	ul_height = menu_object.find(".leo-top-menu ul").innerHeight();
447	ul_offset_top = menu_object.find(".leo-top-menu ul").offset().top;
448	// console.log('test1');
449	// console.log(megamenu_element.find(".leo-top-menu ul").height());
450	// console.log(megamenu_element.find(".leo-top-menu ul").offset().top);
451	// console.log($("#page").height());
452    // $(".off-canvas-nav-megamenu[data-megamenu-id="+menu_id+"] .offcanvas-mainnav").css('min-height', windowHeight);
453	if (ul_offset_top + ul_height > wrapper_height)
454	{
455		if (!$("#page").hasClass('megamenu-autoheight'))
456		{
457			$("#page").addClass('megamenu-autoheight');
458		}
459	}
460	else
461	{
462		$("#page").removeClass('megamenu-autoheight');
463	}
464}
465
466//DONGND:: auto calculate height of off canvas menu
467function auto_height(menu_id)
468{	
469	windowHeight = $(window).innerHeight();
470    $(".off-canvas-nav-megamenu[data-megamenu-id="+menu_id+"] .offcanvas-mainnav").css('min-height', windowHeight);
471}
472
473function off_canvas_active()
474{
475	// console.log($(window).height());
476	if($('body').hasClass('off-canvas-active'))
477	{
478		$("body").removeClass("off-canvas-active").addClass("off-canvas-inactive");
479	}
480	else if($('body').hasClass('off-canvas-inactive'))
481	{
482		$("body").removeClass("off-canvas-inactive").addClass("off-canvas-active");
483	}
484	else
485	{
486		$("body").addClass("off-canvas-active");
487	}
488	
489}
490
491function set_target_blank( show, megamenu_element)
492{
493	if (show)
494	{
495		
496		megamenu_element.find(".leo-top-menu li a").each(function(){
497		   if( $(this).hasClass('has-category') && (this).hasAttribute('data-toggle') && $(this).attr('target')== '_blank' ){
498				var value = $(this).attr('data-toggle');
499				$(this).removeAttr('data-toggle');
500				$(this).attr('remove-data-toggle', value);
501		   }
502		})
503	}else 
504	{
505		// console.log('test');
506		megamenu_element.find(".leo-top-menu li a").each(function(){	
507		   if( $(this).hasClass('has-category') && (this).hasAttribute('remove-data-toggle') && $(this).attr('target')== '_blank' ){
508				var value = $(this).attr('remove-data-toggle');
509				$(this).removeAttr('remove-data-toggle');
510				$(this).attr('data-toggle', value);
511		   }
512		})
513	}
514
515}
516
517function scrollSliderBarMenu(megamenu_element){
518	var menuElement = megamenu_element;
519	var columnElement = null;
520	var maxWindowSize = 991;
521	
522	// if($(menuElement).hasClass('float-vertical-right'))
523		// columnElement = $("#right_column");
524	// else if($(menuElement).hasClass('float-vertical-left'))
525		// columnElement = $("#left_column");
526	//auto display slider bar menu when have left or right column
527	if($(columnElement).length && $(window).width()>=maxWindowSize) showOrHideSliderBarMenu(columnElement, menuElement, 1);
528	megamenu_element.find(".verticalmenu-button").click(function(){
529		if($(menuElement).hasClass('active'))
530		{
531			showOrHideSliderBarMenu(columnElement, menuElement, 0);
532		} 
533		else
534		{
535			showOrHideSliderBarMenu(columnElement, menuElement, 1);
536		}
537	});
538
539	var lastWidth = $(window).width();
540	$(window).resize(function() {
541		if($(window).width()!=lastWidth){
542			if($(window).width()<maxWindowSize) {
543				if($(menuElement).hasClass('active')) showOrHideSliderBarMenu(columnElement, menuElement, 0);
544			}else{
545				if($(columnElement).length && !$(menuElement).hasClass('active')) showOrHideSliderBarMenu(columnElement, menuElement, 1);
546			}
547			lastWidth = $(window).width();
548		}
549	});
550}
551
552function showOrHideSliderBarMenu(columnElement, menuElement, active){
553	if(active){
554		$(menuElement).addClass('active');
555		if($(columnElement).length && $(window).width()>=991) 
556			columnElement.css('padding-top',($('.block_content',$(menuElement)).height())+'px');
557	}else{
558		$(menuElement).removeClass('active');
559		if($(columnElement).length) columnElement.css('padding-top','');
560	}
561}
562

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.