Advertisement
Guenni007

menu

Jun 24th, 2020
1,759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($)
  2. {
  3.     "use strict";
  4.     $.avia_utilities = $.avia_utilities || {};
  5.    
  6.     $(document).ready(function()
  7.     {  
  8.          //activates the sticky submenu
  9.         $.avia_utilities = $.avia_utilities || {};
  10.         if($.avia_utilities.avia_sticky_submenu)
  11.         $.avia_utilities.avia_sticky_submenu();
  12.     });
  13.    
  14.    
  15.     $.avia_utilities.avia_sticky_submenu = function()
  16.     {
  17.         var win         = $(window),
  18.             html        = $('html:first'),
  19.             header      = $('.html_header_top.html_header_sticky #header'),
  20.             html_margin = parseInt( $('html:first').css('margin-top'), 10),
  21.             setWitdth   = $('.html_header_sidebar #main, .boxed #main'),
  22.             menus       = $('.av-submenu-container'),
  23.             bordermod   = html.is('.html_minimal_header') ? 0 : 1,
  24.             fixed_frame = $('.av-frame-top').height(),
  25.             burger_menu = $('.av-burger-menu-main'),
  26.             calc_margin = function()
  27.             {
  28.                 html_margin = parseInt( html.css('margin-top'), 10);
  29.                 if(!$('.mobile_menu_toggle:visible').length)
  30.                 {
  31.                     $('.av-open-submenu').removeClass('av-open-submenu');
  32.                 }
  33.                
  34.                 menus.filter('.av-sticky-submenu').each(function()
  35.                 {
  36.                     $(this).next('.sticky_placeholder').height($(this).height());
  37.                 });
  38.                
  39.             },
  40.             calc_values = function()
  41.             {
  42.                 var content_width = setWitdth.width();
  43.                 html_margin = parseInt( html.css('margin-top'), 10);
  44.                 menus.width(content_width);
  45.             },
  46.             check       = function(placeholder, no_timeout)
  47.             {
  48.                 var menu_pos    = this.offset().top,
  49.                     top_pos     = placeholder.offset().top,
  50.                     scrolled    = win.scrollTop(),
  51.                     modifier    = html_margin,
  52.                     fixed       = false;
  53.            
  54.                     /****** The if clause for burger visible is changed here only ********/
  55.                     if( burger_menu.is(":visible") && (scrolled + modifier > top_pos) )
  56.                     {
  57.                         this.css({top: header.Height() , position: 'fixed !important'}); fixed = true;
  58.                     }
  59.                                        
  60.                     if(header.length)
  61.                     {
  62.                         modifier += header.outerHeight() + parseInt( header.css('margin-top'), 10);
  63.                     }  
  64.                    
  65.                     if(fixed_frame)
  66.                     {
  67.                         modifier += fixed_frame;
  68.                     }
  69.                    
  70.                     if(scrolled + modifier > top_pos)
  71.                     {
  72.                         if(!fixed)
  73.                         {
  74.                             this.css({top: modifier - bordermod, position: 'fixed'}); fixed = true;
  75.                         }
  76.                     }
  77.                     else
  78.                     {
  79.                         this.css({top: 'auto', position: 'absolute'}); fixed = false;
  80.                     }
  81.                    
  82.             },
  83.             toggle = function(e)
  84.             {
  85.                 e.preventDefault();
  86.                
  87.                 var clicked = $(this),
  88.                     menu    = clicked.siblings('.av-subnav-menu');
  89.                
  90.                     if(menu.hasClass('av-open-submenu'))
  91.                     {
  92.                         menu.removeClass('av-open-submenu');
  93.                     }
  94.                     else
  95.                     {
  96.                         menu.addClass('av-open-submenu');
  97.                     }
  98.             };
  99.        
  100.         win.on("debouncedresize av-height-change",  calc_margin ); calc_margin();
  101.            
  102.         if(setWitdth.length)
  103.         {
  104.             win.on("debouncedresize av-height-change",  calc_values );
  105.             calc_values();
  106.         }
  107.        
  108.        
  109.         menus.each(function()
  110.         {
  111.              var menu = $(this), sticky = menu.filter('.av-sticky-submenu'),  placeholder = menu.next('.sticky_placeholder'), mobile_button = menu.find('.mobile_menu_toggle');
  112.              
  113.              
  114.              if(sticky.length) win.on( 'scroll debouncedresize',  function(){ window.requestAnimationFrame( $.proxy( check, sticky, placeholder) ); } );
  115.  
  116.              if(mobile_button.length)
  117.              {
  118.                 mobile_button.on( 'click',  toggle );
  119.              }
  120.         });
  121.        
  122.        
  123.         html.on('click', '.av-submenu-hidden .av-open-submenu li a', function()
  124.         {
  125.             var current = $(this);
  126.            
  127.             var list_item = current.siblings('ul, .avia_mega_div');
  128.             if(list_item.length)
  129.             {
  130.                 if(list_item.hasClass('av-visible-sublist'))
  131.                 {
  132.                     list_item.removeClass('av-visible-sublist');
  133.                 }
  134.                 else
  135.                 {
  136.                     list_item.addClass('av-visible-sublist');
  137.                 }
  138.                 return false;
  139.             }
  140.         });
  141.        
  142.         $('.avia_mobile').on('click', '.av-menu-mobile-disabled li a', function()
  143.         {
  144.             var current = $(this);
  145.             var list_item = current.siblings('ul');
  146.             if(list_item.length)
  147.             {
  148.                 if(list_item.hasClass('av-visible-mobile-sublist'))
  149.                 {
  150.                    
  151.                 }
  152.                 else
  153.                 {
  154.                     $('.av-visible-mobile-sublist').removeClass('av-visible-mobile-sublist');
  155.                     list_item.addClass('av-visible-mobile-sublist');
  156.                     return false;
  157.                 }
  158.                
  159.             }
  160.         });
  161.        
  162.     };
  163.    
  164. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement