jQuery(function($){ // ================================================= // :: Sticky Header :: // ------------------------------------------------- function stickyNav(){ var stickyNavHeight = $('#masthead').outerHeight(); var stickyNavTop = $('#masthead').offset().top; $('#primary-menu').css('top',' '); var scrollTop = $(window).scrollTop(); if (scrollTop > 0) { $('#masthead').addClass('scroll'); $('#content').css('margin-top',stickyNavHeight+'px'); } else { $('#masthead').removeClass('scroll'); $('#masthead').css('top',' '); $('#content').css('margin-top','0px'); } } // ================================================= // :: Print data link :: // ------------------------------------------------- function printData(){ $('a.primary.printme').on('click',function(){ var divToPrint=document.getElementById("toprint"); newWin= window.open(""); newWin.document.write(divToPrint.outerHTML); newWin.print(); newWin.close(); }); } // ================================================= // :: Smooth Anchor Link Scroll :: // ------------------------------------------------- function smoothAnchorScroll(){ $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html, body').animate({ scrollTop: (target.offset().top - 190) }, 1000); return false; } } }); } // ================================================= // :: Asynchronous Google Font Load :: // ------------------------------------------------- function loadGoogleFont(){ WebFontConfig = { google: { families: [ 'Open+Sans:300,400,600,700','Lato:300,400,600,700','Oswald:300,400,600,700' ] } }; (function() { var wf = document.createElement('script'); wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'; wf.type = 'text/javascript'; wf.async = 'true'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wf, s); })(); } // ================================================= // :: Adjust submenu top margin on mobile :: // ------------------------------------------------- function submenumargin(){ if ($(window).width() < 993) { var headerheight = $('#masthead .container-fluid').outerHeight(); $('#primary-menu').css('padding-top', headerheight+'px'); $('#primary-menu .sub-menu').css('padding-top', headerheight+'px'); }else{ $('#primary-menu').attr('style',' '); $('#primary-menu .sub-menu').attr('style',' '); } } // ================================================= // :: Toggle submenu on mobile :: // ------------------------------------------------- function submenuToggle(){ $('a.sub-toggle').click(function(e){ console.log('a.sub-toggle click'); $currtree = $(this).parent().parent().parent(); $currtree.find('.dropdown').each(function() { $(this).toggleClass('active'); }); $currtree.find('.sub-menu.open').each(function() { $(this).toggleClass('open'); subMenuHide($(this)); }); }); $('li.menu-item-has-children .dropdown').click(function(e){ console.log('.dropdown click'); $(this).toggleClass('active'); $smenu = $(this).next().next(); $smenu.toggleClass('open'); subMenuShow($smenu); }); } function subMenuShow(thisObj){ console.log('subMenuShow function'); thisObj.animate({ width: "toggle", opacity: 1, right: 0 },300); } function subMenuHide(thisObj){ console.log('subMenuHide function'); thisObj.animate({ width: "toggle", opacity: 0, right: '-50%' },300); } // ================================================= // :: Lazy Load Images :: // ------------------------------------------------- function lazyLoadImage(){ $('img[data-src]').each(function( index ) { $(this).attr('src',$(this).attr('data-src')); }) $('div[data-bg-src], section[data-bg-src]').each(function( index ) { $(this).css('background-image','url('+$(this).attr('data-bg-src')+')'); }) } // ================================================= // :: matchHeight elements:: // ------------------------------------------------- function heightBalancer(){ //Blog $(' .blog .blog-entry .entry-title').matchHeight(); $(' .blog .blog-entry .entry-content').matchHeight(); //Grid panel // $('.grid-panels .panels .panel .panel-title').matchHeight(); //$('.grid-panels .panels .panel .panel-content').matchHeight(); //How it works /* $('.how-it-works .services .service').matchHeight(); $('.how-it-works .services .content .icon').matchHeight(); $('.how-it-works .services .content .panel-content h3').matchHeight(); $('.how-it-works .services .content .panel-content p').matchHeight(); */ //Book online form $('section.book-online-form .container .icon-col').matchHeight(); $('section.book-online-form .container .header2').matchHeight(); $('section.book-online-form .container .header5').matchHeight(); //Image text table //$('.image_text_table .text-items .item span').matchHeight({byRow: false}); } function imageLeftSlider(){ if($('.image-left-full-width .slider').length){ $('.image-left-full-width .slider').flexslider({ animation: "slide", animationLoop: false, itemMargin: 0, controlNav: false, directionNav: true, slideshow: false, customDirectionNav: $(".image-left-full-width .direction-navigation a") }); } } function loadSlider(){ if ($(window).width() < 768) { $('.load-sizes .slider').flexslider({ animation: "slide", animationLoop: false, itemMargin: 0, controlNav: true, directionNav: false, slideshow: false }); } } function toggleLoadSizes(){ $('.load-sizes .slider .slides .slide .content-wrapper .load-sizes-title .toggle').each(function (index, value){ $(this).click(function(){ $(this).closest('.content-wrapper').find('.load-sizes-description').slideToggle(); $(this).html($(this).html() == 'Read More' ? 'Read Less' : 'Read More'); }); }); } function accordionFAQ(){ var Accordion = function(el, multiple) { this.el = el || {}; this.multiple = multiple || false; var links = this.el.find('.accordion-title'); links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown) } Accordion.prototype.dropdown = function(e) { var $el = e.data.el; $this = $(this), $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('open'); if (!e.data.multiple) { $el.find('.accordion-content').not($next).slideUp().parent().removeClass('open'); }; } var accordion = new Accordion($('.accordion-container'), false); } // ================================================= // :: Close mobile menu on body click:: // ------------------------------------------------- function mobileCanvasCloseMenu(){ $('#mobile-off-menu').click(function(e){ $('.toggled #mobile-off-menu').fadeOut(300); $('html').toggleClass('toggled'); $('#site-navigation').toggleClass('toggled'); $('.menu-toggle').attr( 'aria-expanded', 'false' ); $('#primary-menu').attr( 'aria-expanded', 'false' ); $('#primary-menu').animate({ width: "toggle", opacity: 0, right: '-50%' },300,function() { $('#primary-menu').find('.dropdown').each(function() { $(this).removeClass('active'); }); $('#primary-menu').find('.sub-menu.open').each(function() { $(this).removeClass('open').css({ 'display': 'none', 'opacity': '0', 'right': '-50%' }); }); }); }); } $(window).scroll(function() { stickyNav(); }); jQuery(window).resize(function(){ submenumargin(); heightBalancer(); }); $(document).ready(function() { submenuToggle(); lazyLoadImage(); stickyNav(); printData(); smoothAnchorScroll(); //loadGoogleFont(); submenumargin(); heightBalancer(); setTimeout(function(){ heightBalancer(); }, 2000); imageLeftSlider(); loadSlider(); toggleLoadSizes(); accordionFAQ(); mobileCanvasCloseMenu(); }); });