jQuery (document ).ready(function($){ /** * ---------------------------------------------------------------------------- * * Detect for IE and apply body class. * * ---------------------------------------------------------------------------- */ function getInternetExplorerVersion() { var rv = -1; if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } else if (navigator.appName == 'Netscape') { var ua = navigator.userAgent; var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } //If its IE, place "IE" and IE version number class on body tag if(getInternetExplorerVersion() != "-1") { var bodyClass = "IE" + getInternetExplorerVersion(); $("body").addClass("IE").addClass(bodyClass); } /** * ---------------------------------------------------------------------------- * * Apply fast click polyfill for mobile browsers * * ---------------------------------------------------------------------------- */ FastClick.attach(document.body); /** * ---------------------------------------------------------------------------- * * Detect Browser and Mobile and apply it as a class to the body element * * ---------------------------------------------------------------------------- */ var browser = BrowserDetect.browser; $("body").addClass(browser); var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; var mobileBrowser = isMobile.any(); //will return true of false if( mobileBrowser ) { $('body').addClass("mobile"); } /** * ---------------------------------------------------------------------------- * * Sticky header when scrolling up * * ---------------------------------------------------------------------------- */ var lastScrollTop = 0; $(window).scroll(function(event){ var st = $(this).scrollTop(); var header = $(".site-header").offset().top; var headerHeight = $(".site-header").height(); var navHeight = $("#site-navigation").height(); var navPos = $("#site-navigation").offset().top; var mobileOn = $(".site-header").hasClass("mobileOn"); var brandingHeight = $(".site-branding").height(); //brandingHeight = "-" + brandingHeight; var headerPlacement = st - headerHeight; if(mobileBrowser) { $(".site-header").css("top","0px").css("position","fixed"); if(st > headerHeight) { $(".site-header").addClass("red"); } else { $(".site-header").removeClass("red"); } } else { if (st > lastScrollTop){ // downscroll code header = $(".site-header").offset().top; $(".site-header").css("top",header).removeClass("sticky"); if(st > (header+headerHeight)) { $(".site-header").css("top",headerPlacement); //console.log(headerPlacement); } } else { // upscroll code if(!mobileOn) { if(st <= navPos) { $(".site-header").addClass("sticky").css("top","-"+brandingHeight+"px"); } } else { if(st <= header) { $(".site-header").addClass("sticky").css("top","0px"); } } } if(st > headerHeight) { $(".site-header").addClass("red"); } else { $(".site-header").removeClass("red"); } if(!mobileOn) { if(st < brandingHeight) { $(".site-header").removeClass("red").removeClass("sticky").css("top","0px"); } } else { if(st < 1) { $(".site-header").removeClass("red").removeClass("sticky").css("top","0px"); } } } lastScrollTop = st; }); /** * ---------------------------------------------------------------------------- * * Hide Menus When clicking elsewhere * * ---------------------------------------------------------------------------- */ $(window).click(function(e) { //close your uw menu $(".youruwmenu, .subLevel1, .subLevel2").removeClass("visible"); }); /** * ---------------------------------------------------------------------------- * * Mobile Menu Logic * * ---------------------------------------------------------------------------- */ var menuWidth = $(".site-navigation-container .menu").width(); var totalWidth = 0; $(".site-navigation-container .menu > ul > li, .site-navigation-container ul.menu > li").each(function() { totalWidth = totalWidth + $(this).width(); //console.log(totalWidth); }); function mobileMenu() { var windowWidth = $(window).width(); var menuWidth = $(".site-navigation-container .menu").width(); //console.log(menuWidth); /*$(".menu > ul > li").each(function() { totalWidth = totalWidth + $(this).width(); });*/ //console.log(totalWidth + " " + menuWidth); if(windowWidth < 600) { $("#site-navigation").css("visibility","hidden").css("height","0px"); $(".mobileTrigger").addClass("shown"); $(".logoImage").addClass("mobileMenuOn"); $(".site-header").addClass("mobileOn"); $("body").addClass("mobileNavOn"); } else { if(totalWidth > menuWidth) { //console.log("switch to mobile"); $("#site-navigation").css("visibility","hidden").css("height","0px"); $(".mobileTrigger").addClass("shown"); $(".logoImage").addClass("mobileMenuOn"); $(".site-header").addClass("mobileOn"); $("body").addClass("mobileNavOn"); } else { if(totalWidth == 0) { //console.log("switch to mobile"); $("#site-navigation").css("visibility","hidden").css("height","0px"); $(".mobileTrigger").addClass("shown"); $(".logoImage").addClass("mobileMenuOn"); $(".site-header").addClass("mobileOn"); $("body").addClass("mobileNavOn"); } else { //console.log("switch to full"); $("#site-navigation").css("visibility","visible").css("height","auto"); $(".mobileTrigger").removeClass("shown"); $(".logoImage").removeClass("mobileMenuOn"); $(".site-header").removeClass("mobileOn"); $("body").removeClass("mobileNavOn"); } } } } mobileMenu(); $(window).resize(function() { mobileMenu(); }); $(".mobileTrigger, .menuOverlay").click(function(e) { e.preventDefault(); $(".mobileMenu").toggleClass("mobileMenuShown"); $(".menuOverlay").toggleClass("mobileMenuShown"); $("#page").toggleClass("blur"); }); $(".mobileMenu li.page_item_has_children > a").click(function(e) { e.preventDefault(); e.stopPropagation(); var subItems = $(this).next().html(); var clickedLinkTitle = $(this).text() + " Overview"; var clickedLinkHref = $(this).attr("href"); var overviewLink = "