/* global businessCommerceScreenReaderText */ /** * Theme functions file. * * Contains handlers for navigation and widget area. */ (function($) { // Masonry if ( typeof $.fn.masonry === 'function' ) { //Masonry blocks $blocks = $('.infinite-grid'); $blocks.imagesLoaded(function() { $blocks.masonry({ itemSelector: '.grid-item', columnWidth: '.grid-item', // slow transitions transitionDuration: '1s' }); // Fade blocks in after images are ready (prevents jumping and re-rendering) $('.grid-item').fadeIn(); $blocks.find('.grid-item').animate({ 'opacity': 1 }); }); $(function() { setTimeout(function() { $blocks.masonry(); }, 2000); }); $(window).on( 'resize',function() { $blocks.masonry(); }); } // Show the first tab and hide the rest $('#tabs-nav li:first-child').addClass('active'); $('.tab-content').hide(); $('.tab-content:first').show(); // Click function $('#tabs-nav li').on('click', function() { $('#tabs-nav li').removeClass('active'); $(this).addClass('active'); $('.tab-content').hide(); var activeTab = $(this).find('a').attr('href'); $(activeTab).fadeIn(); return false; }); // map-toggle $("#map-toggle").on('click', function() { $(".gmap_canvas_inner").toggle(); }); if ( $('#counter-section').length ) { jQuery(window).on("resize scroll", function(){ var scrollPosition = jQuery(window).scrollTop(); var viewportHeight = window.innerHeight; var offset = jQuery("#counter-section").offset(); var elementHeight = jQuery("#counter-section").height(); if(offset.top > scrollPosition - elementHeight && offset.top < scrollPosition + viewportHeight) { $('.counter-nos').each(function() { var $this = $(this), countTo = $this.attr('data-count'); $({ countNum: $this.text() }).animate({ countNum: countTo }, { duration: 2000, easing: 'linear', step: function() { $this.text(Math.floor(this.countNum)); }, complete: function() { $this.text(this.countNum); } }); }); } }); } // When Jetpack Infinite scroll posts have loaded $(document.body).on('post-load', function() { $blocks.masonry('reloadItems'); $blocks.imagesLoaded(function() { $blocks.masonry({ itemSelector: '.grid-item', columnWidth: '.grid-item', // slow transitions transitionDuration: '1s', }); // Fade blocks in after images are ready (prevents jumping and re-rendering) $('.grid-item').fadeIn(); $blocks.find('.grid-item').animate({ 'opacity': 1 }); }); $(document).ready(function() { setTimeout(function() { $blocks.masonry(); }, 2000); }); }); // Add header video class after the video is loaded. $(document).on('wp-custom-header-video-loaded', function() { $('body').addClass('has-header-video'); }); /** * Functionality for scroll to top button */ $(function() { $(window).on('scroll', function() { if ($(this).scrollTop() > 100) { $('#scrollup').fadeIn('slow'); $('#scrollup').show(); } else { $('#scrollup').fadeOut('slow'); $("#scrollup").hide(); } }); $('#scrollup').on('click', function() { $('body, html').animate({ scrollTop: 0 }, 500); return false; }); }); // Fixed header. $(window).on('scroll', function() { if ($('.sticky-enabled').length && $(window).scrollTop() > $('.sticky-enabled').offset().top && !($('.sticky-enabled').hasClass('sticky-header'))) { $('.sticky-enabled').addClass('sticky-header'); } else if (0 === $(window).scrollTop()) { $('.sticky-enabled').removeClass('sticky-header'); } }); var body, masthead, menuToggle, siteNavigation, searchNavigation, siteHeaderMenu, resizeTimer; function initMainNavigation(container) { // Add dropdown toggle that displays child menu items. var dropdownToggle = $('