/** * Layers Pro JS * * This file contains all theme JS functions. */ jQuery(function($){ if( !layersCheckMobile() ){ $.stellar({ horizontalScrolling: false, verticalOffset: 40 }); }; jQuery(window).resize(function(){ resizeVideos(); }); $(document).on('layers-slider-init', function(s){ resizeVideos(); }); function resizeVideos(){ $( '.swiper-container .layerspro-slider-video' ).each(function(){ var $that = $(this); var $parent = $that.closest( '.layers-slider-widget' ); $ratio = ( $parent.outerHeight()/$parent.outerWidth() ) * 100; $that.removeClass( 'layers-slider-video-ultra-wide layers-slider-video-super-wide layers-slider-video-wide layers-slider-video-square layers-slider-video-tall layers-slider-video-super-tall' ); if( $ratio <= 20 ){ var $video_css = 'layers-slider-video-ultra-wide'; } else if( $ratio <= 32 ){ var $video_css = 'layers-slider-video-super-wide'; } else if( $ratio <= 56 ){ var $video_css = 'layers-slider-video-wide'; } else if( $ratio <= 75 ){ var $video_css = 'layers-slider-video-square'; } else if( $ratio <= 100 ){ var $video_css = 'layers-slider-video-tall'; } else { var $video_css = 'layers-slider-video-super-tall'; } $that.addClass( $video_css ); }); } playActiveVideos(); function playActiveVideos(){ setTimeout( function(){ var video = $( '.swiper-slide-active' ).find( 'video' ); if( 'undefined' == typeof( video.attr( 'customizer' ) ) ) $( '.swiper-slide-active' ).find( 'video' ).trigger( 'play' ); }, 100 ); } // Move videos in the customizer to their first frame $( '.swiper-container .layerspro-slider-video' ).each(function(){ if( layersCheckMobile() ) $(this).remove(); }); $( '.swiper-container video' ).each(function(){ if( layersCheckMobile() ) $(this).remove(); // Get the video object video = $(this); // Generate a preview if( !video.prop( 'autoplay' ) && video.prop( 'customizer' ) ) { // Trigger play video.trigger( 'play' ); // As soon as we play then trigger a stop video.on( 'play', function(){ setTimeout( function(){ // Trigger pause video.trigger( 'pause' ); }, 100); }); }; }); /** * Tabs */ $('.layers-pro-tabs').each(function( index, element ){ var $widget = $( element ); var $tab_buttons_holder = $widget.find('.nav-tabs'); var $tab_buttons = $tab_buttons_holder.find('li'); var $tab_contents_holder = $widget.find('.tab-content'); var $tab_contents = $tab_contents_holder.children(); $tab_buttons.each(function( index, element ){ $( element ).on( 'click', function() { var $related_tab_button = $(this); var $related_tab_content = $tab_contents.eq(index); $tab_buttons.not($related_tab_button).removeClass('active'); $related_tab_button.addClass('active'); $tab_contents.not($related_tab_content).hide(); $related_tab_content.show(); return false; }); }); }); /** * Accordion */ $('.layers-pro-accordion').each(function( index, element ){ var $widget = $( element ); var $accordion_list = $widget.find('.accordion-list'); var $accordion_items = $widget.find('.accordion-list li'); $accordion_items.each(function( index, element ){ $( element ).children('section').slideUp(0).css({ position: 'relative', visibility: 'visible' }); $( element ).children('a').on( 'click', function() { var $related_accordion_title = $(this); var $related_accordion_item = $related_accordion_title.parent(); var $related_accordion_content = $related_accordion_item.children('section'); if ( $related_accordion_item.hasClass('active') ) { // Close $related_accordion_item.removeClass('active'); $related_accordion_content.slideUp({ duration:200, easing: 'layersEaseInOut' }); } else { // Open $related_accordion_item.addClass('active'); $related_accordion_content.slideDown({ duration:200, easing: 'layersEaseInOut' }); } return false; }); }); }); /** * Search */ $(document).on( 'click', '.search-close', function(){ $('.search-interface-overlay') .removeClass('search-interface-play-in') .addClass('search-interface-play-out'); return false; }); $(document).on( 'click', '.header-search > a, .menui-item-layers-search > a', function(){ var $search_field = $('#layers-modal-search-field'); $('.search-interface-overlay') .removeClass('search-interface-play-out') .addClass('search-interface-play-in'); setTimeout(function() { $search_field .focus() .layers_pro_set_cursor_postion( $search_field.val().length ); }, 600 ); return false; }); /** * Allow animation if x-animation is found */ // For all the animations on page animate as soon as the // scrolling reaches 25% above the widget /** * X - Scroll Animations. */ var bodyEl = $('body'); var footerEl = $('#footer'); if ( bodyEl.hasClass('layers-animate') ) { var sectionsToAnimate = [ "#wrapper-content > .widget", ".title-container .title", "#post-list .post", ".sidebar", "#wrapper-content :not(\".swiper-container\") .grid > article:not('.layers-masonry-column')" ]; // Special header animation // Header site to fade in with downward direction $(".header-site").addClass("do-animate delay-200 animated-1s layers-default-fade-in-down"); // Header block container to fade in upward direction $(".header-block.container").addClass("do-animate delay-200 animated-1s layers-default-fade-in-up"); $(sectionsToAnimate.join(",")).not(".do-animate").addClass("do-animate translucent animated-1s layers-default-fade-in-up"); footerEl.addClass("animated-1s"); $('.do-animate').waypoint({ offset : '75%', handler : layersAnimationHandler('layers-default', false) }); footerEl.waypoint({ offset : '90%', handler : layersAnimationHandler('layers-default', false) }); // As we are using delay-200 for header and footer lets remove // the class of opacity from body for more smooth animations setTimeout(function(){ bodyEl.removeClass('opacity-0'); }, 200); } // For all the animations on page animate as soon as the // scrolling reaches 25% above the widget $('.do-animate').waypoint({ handler: layersAnimationHandler('x', false), offset: '75%' }); }); /** * Helper function that initialsizes our Carousel. It expects that there * is a row of our standard Layers post list HTML that it will convert * * @param string widget_id Widgets id selector eg #widget_66 * @param object settings Settings object * @return Swiper Swiper object */ function layers_pro_init_post_carousel( widget_id, settings ) { // Debigging disable. // return; // Get the all important row that will will contain our carousel. var carousel_row = jQuery( widget_id ).find( '.post-carousel-row' ); var carousel_row_grid = carousel_row.find('.grid'); /** * Prepare a cloned Mimic row that we will grab our sizing from - which allows for responsive resizing. */ // Create a holder to hold the cloned elements that we will subsequently mimic in our carousel. var mimic_row = jQuery( '