//Welcome to the party jQuery(document).ready(function(){ /*--- Contracts Header When Scrolling ---*/ jQuery(window).scroll(function(e){ if(jQuery(window).scrollTop() > 0){ jQuery('header').addClass('header-sticky'); } else{ jQuery('header').removeClass('header-sticky'); } }) /*--- Handles Submenus ---*/ //Wipes the menu completely when a non-nav item is hovered over jQuery('nav>ul>li>a').mouseover(function(){ if(jQuery(this).parent().parent().parent().is('nav')){ jQuery('nav>ul>li .sub-menu').removeClass('open'); }; }) //Wipes the submenu when another submenu item is hovered over jQuery('nav>ul>li>.sub-menu li').mouseover(function(){ jQuery(this).siblings('.menu-item-has-children').children().removeClass('open'); }) //Opens the menu when an item with a sub-menu is hovered over jQuery('.menu-item-has-children>a').mouseover(function(){ jQuery(this).siblings('.sub-menu').addClass('open'); }) //Wipes the menu in when the user does not hover over another list item or submenu jQuery('nav').mouseleave(function(){ jQuery('.sub-menu').removeClass('open'); }) //Wipes the menu when the user leaves a submenu jQuery('.menu-item-has-children .sub-menu').mouseleave(function(){ jQuery(this).removeClass('open'); }) /*--- Submenu Mobile Support ---*/ //Converts hover elements to click elements. jQuery('.menu-item-has-children>a').on("touchstart", function (e) { "use strict"; //satisfy the code inspectors var link = jQuery(this); //preselect the link if (link.hasClass('open')) { return true; } else { jQuery(this).siblings('.sub-menu').addClass('open'); jQuery('.menu-item-has-children>a').not(this).removeClass("open"); e.preventDefault(); return false; //extra, and to make sure the function has consistent return points } }); //Wipes the menu when a non sub-menu item is clicked. jQuery('body').click(function(){ jQuery('.sub-menu').removeClass('open'); jQuery('nav').removeClass('open'); }) /*--- Mobile Menu Behavior ---*/ jQuery('nav').on("click", function (e) { "use strict"; if(jQuery(window).width() > 1100){ //ignores this function if on a device is not a tablet return true; } if(jQuery('nav').hasClass('open')){ jQuery('nav').removeClass('open'); jQuery('.sub-menu').removeClass('open'); return true; } else { jQuery('nav').addClass('open'); e.preventDefault(); return false; } }) })