jQuery(document).ready(function($) { "use strict"; /* window */ var window_width, window_height, scroll_top; /* admin bar */ var adminbar = $('#wpadminbar'); var adminbar_height = 0; /* header menu */ var header = $('#cshero-header'); var header_top = 0; /* scroll status */ var scroll_status = ''; $(".tnp-email").attr("placeholder", "Your email..."); /** * window load event. * * Bind an event handler to the "load" JavaScript event. * @author Fox */ /* Wow animation */ function initWow(){ var wow = new WOW( { mobile: false, } ); wow.init(); }; $(window).on('load', function() { if ( $('.wow').length ) { initWow(); }; /** current scroll */ scroll_top = $(window).scrollTop(); /** current window width */ window_width = $(window).width(); /** current window height */ window_height = $(window).height(); /* get admin bar height */ adminbar_height = adminbar.length > 0 ? adminbar.outerHeight(true) : 0 ; /* get top header menu */ header_top = header.length > 0 ? header.offset().top - adminbar_height : 0 ; cms_lightbox_popup(); /* check sticky menu. */ cms_stiky_menu(); }); if ($('.ef3-back-to-top').length) { $('.ef3-back-to-top').on('click', function(event) { event.stopPropagation(); $('html, body').stop().animate({ scrollTop: 0 }, 1500, 'swing'); }); $(window).on('scroll', function() { if ($(window).scrollTop() > 480) { $('.ef3-back-to-top').addClass('active'); } else { $('.ef3-back-to-top').removeClass('active'); } }); } /** * reload event. * * Bind an event handler to the "navigate". */ window.onbeforeunload = function(){ } /** * resize event. * * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @author Fox */ $(window).on('resize', function(event, ui) { /** current window width */ window_width = $(event.target).width(); /** current window height */ window_height = $(window).height(); /** current scroll */ scroll_top = $(window).scrollTop(); /* check sticky menu. */ cms_stiky_menu(); }); /** * scroll event. * * Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. * @author Fox */ $(window).on('scroll', function() { /** current scroll */ scroll_top = $(window).scrollTop(); /* check sticky menu. */ cms_stiky_menu(); }); /** * Stiky menu * * Show or hide sticky menu. * @author Fox * @since 1.0.0 */ function cms_stiky_menu() { console.log(scroll_top); console.log(header_top); if (header.hasClass('sticky-desktop') && scroll_top > (header_top + 1) && window_width > 1199) { header.addClass('header-fixed'); $('body').addClass('hd-fixed'); if($('.sticky_logo').length > 0) { $('.sticky_logo').removeClass('hide'); $('.main_logo').addClass('hide'); } $('.sticky-desktop').addClass('fadeInDown'); $('.sticky-desktop').addClass('animated'); } else { header.removeClass('header-fixed'); $('body').removeClass('hd-fixed'); $('.sticky-desktop').removeClass('fadeInDown'); $('.sticky-desktop').removeClass('animated'); if($('.sticky_logo').length > 0) { $('.sticky_logo').addClass('hide'); $('.main_logo').removeClass('hide'); } } } function cms_lightbox_popup() { $('.cms-gallerys').magnificPopup({ delegate: '.magic-popups', type: 'image', tLoading: 'Loading image #%curr%...', mainClass: 'mfp-3d-unfold', removalDelay: 500, callbacks: { beforeOpen: function() { this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim'); } }, gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] }, image: { tError: 'The image #%curr% could not be loaded.', } }); } /** * Mobile menu * * Show or hide mobile menu. * @author Fox * @since 1.0.0 */ $('body').on('click', '#cshero-menu-mobile', function(){ var navigation = $(this).parent().find('#cshero-header-navigation'); if(!navigation.hasClass('collapse')){ navigation.addClass('collapse'); } else { navigation.removeClass('collapse'); } }); /** * Back to top */ $('body').on('click', '.ef3-back-to-top', function () { $('body, html').animate({scrollTop:0}, '1000'); }) /** * One page * * @author Fox */ if(typeof(one_page_options) != "undefined"){ one_page_options.speed = parseInt(one_page_options.speed); $('#site-navigation').singlePageNav(one_page_options); } });