Advertisement
Guenni007

menu

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