jQuery(function () { 'use strict'; $(window).on('load', function () { setTimeout(function () { $(".page_loader").fadeOut("fast"); }, 100) }); // WOW animation library initialization var wow = new WOW( { animateClass: 'animated', offset: 100, mobile: false } ); wow.init(); // Magnify activation $('.car-magnify-gallery').each(function() { $(this).magnificPopup({ delegate: 'a', type: 'image', gallery:{enabled:true} }); }); // Banner slider (function ($) { //Function to animate slider captions function doAnimations(elems) { //Cache the animationend event in a variable var animEndEv = 'webkitAnimationEnd animationend'; elems.each(function () { var $this = $(this), $animationType = $this.data('animation'); $this.addClass($animationType).one(animEndEv, function () { $this.removeClass($animationType); }); }); } //Variables on page load var $myCarousel = $('#carousel-example-generic') var $firstAnimatingElems = $myCarousel.find('.item:first').find("[data-animation ^= 'animated']"); //Initialize carousel $myCarousel.carousel(); //Animate captions in first slide on page load doAnimations($firstAnimatingElems); //Pause carousel $myCarousel.carousel('pause'); //Other slides to be animated on carousel slide event $myCarousel.on('slide.bs.carousel', function (e) { var $animatingElems = $(e.relatedTarget).find("[data-animation ^= 'animated']"); doAnimations($animatingElems); }); $('#carousel-example-generic').carousel({ interval: 3000, pause: "false" }); })(jQuery); // Page scroller. $.scrollUp({ scrollName: 'page_scroller', scrollDistance: 300, scrollFrom: 'top', scrollSpeed: 500, easingType: 'linear', animation: 'fade', animationSpeed: 200, scrollTrigger: false, scrollTarget: false, scrollText: '', scrollTitle: false, scrollImg: false, activeOverlay: false, zIndex: 2147483647 }); // Counter function isCounterElementVisible($elementToBeChecked) { var TopView = $(window).scrollTop(); var BotView = TopView + $(window).height(); var TopElement = $elementToBeChecked.offset().top; var BotElement = TopElement + $elementToBeChecked.height(); return ((BotElement <= BotView) && (TopElement >= TopView)); } $(window).scroll(function () { $( ".counter" ).each(function() { var isOnView = isCounterElementVisible($(this)); if(isOnView && !$(this).hasClass('Starting')){ $(this).addClass('Starting'); $(this).prop('Counter',0).animate({ Counter: $(this).text() }, { duration: 3000, easing: 'swing', step: function (now) { $(this).text(Math.ceil(now)); } }); } }); }); // Slick Sliders $('.slick-carousel').each(function () { var slider = $(this); $(this).slick({ slidesToShow: 4, infinite: true, dots: false, arrows: false, centerMode: true, centerPadding: '0', responsive: [ { breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, infinite: true, dots: true } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } } // You can unslick at a given breakpoint now by adding: // settings: "unslick" // instead of a settings object ] }); $(this).closest('.slick-slider-area').find('.slick-prev').on("click", function () { slider.slick('slickPrev'); }); $(this).closest('.slick-slider-area').find('.slick-next').on("click", function () { slider.slick('slickNext'); }); }); // Video inside modal resizeModalsContent(); function resizeModalsContent() { var winWidth = $(window).width(); var videoWidth = 450; if(winWidth < 992 && winWidth > 767) { videoWidth = 600; } else if(winWidth <= 768) { videoWidth = winWidth - 20; } var ratio = 0.71426666666; var videoHeight = videoWidth * ratio; $('.modalIframe iframe').css('height', videoHeight); } $(window).on('resize', function () { resizeModalsContent(); }); /*{ var carVideoWidth = $('.modal-dialog').width(); if(carVideoWidth < 1) var carVideoWidth = $('.modal').width(); } $('iframe').css('height', (carVideoWidth * .61));*/ var videoWidth = $('.car-details').width(); var videoHeight = videoWidth * .61; $('.car-details iframe').css('height', videoHeight); var SingleRoomSliderdWidth = $('.simple-slider').width(); var SingleRoomSliderdHeight = SingleRoomSliderdWidth * .74; $('.thumb-preview').css('height', SingleRoomSliderdHeight); $('.imng-preview').css('height', SingleRoomSliderdHeight); $('.selectpicker').selectpicker(); var val = $('.price-slider').slider('getValue'); $('.price-slider').on('slide', function (ev) { $('#minPrice').val(ev.value[0]); $('#maxPrice').val(ev.value[1]); }); // Navbar search area $(document).ready(function(){ var submitIcon = $('.navbar-search-icon'); var inputBox = $('.navbar-search-input'); var searchBox = $('.navbar-search'); var isOpen = false; submitIcon.click(function(){ if(isOpen == false){ searchBox.addClass('navbar-search-open'); inputBox.focus(); isOpen = true; } else { searchBox.removeClass('navbar-search-open'); inputBox.focusout(); isOpen = false; } }); submitIcon.mouseup(function(){ return false; }); searchBox.mouseup(function(){ return false; }); $(document).mouseup(function(){ if(isOpen == true){ $('.navbar-search-icon').css('display','block'); submitIcon.click(); } }); }); function buttonUp(){ var inputVal = $('.navbar-search-input').val(); inputVal = $.trim(inputVal).length; if( inputVal !== 0){ $('.navbar-search-icon').css('display','none'); } else { $('.navbar-search-input').val(''); $('.navbar-search-icon').css('display','block'); } } // Multilevel menuus $('[data-submenu]').submenupicker(); function toggleChevron(e) { $(e.target) .prev('.panel-heading') .find(".fa") .toggleClass('fa-minus fa-plus'); } $('.panel-group').on('shown.bs.collapse', toggleChevron); $('.panel-group').on('hidden.bs.collapse', toggleChevron); var windowHeight = $( window ).height(); $('#map').css('height', windowHeight); // Change color plate $('.color-plate').on('click', function () { var name = $(this).attr('data-color'); $('link[id="style_sheet"]').attr('href', 'css/colors/'+name+'.css'); if(name == 'default'){ $('.logo img').attr('src', 'img/logos/logo.png'); } else{ $('.logo img').attr('src', 'img/logos/'+name+'-logo.png'); } }); $('.setting-button').on('click', function () { $('.option-panel').toggleClass('option-panel-collased'); }); $('.show_brand').click(function () { $(this).addClass('hide'); $('.hide_brand').removeClass('hide'); $('.brand-checkbox').removeClass('hide'); $('.brand-checkbox').addClass('show'); }) $('.hide_brand').click(function () { $(this).addClass('hide'); $('.show_brand').removeClass('hide'); $('.brand-checkbox').removeClass('show'); $('.brand-checkbox').addClass('hide'); }) $('p:empty').remove(); manageComparison(); function manageComparison() { var selectedCompareVehicles = getCompareArray(); $( ".single-car-lay" ).each(function( index ) { var currentVehicleId = jQuery(this).find('.add_compare').data( 'id' ); if (jQuery.inArray(currentVehicleId, selectedCompareVehicles)!='-1') { jQuery(this).find('.add_compare').removeClass('show_it'); jQuery(this).find('.add_compare').addClass('hide_it'); jQuery(this).find('.remove_compare').addClass('show_it'); jQuery(this).find('.remove_compare').removeClass('hide_it'); } else { jQuery(this).find('.add_compare').removeClass('hide_it'); jQuery(this).find('.add_compare').addClass('show_it'); jQuery(this).find('.remove_compare').removeClass('show_it'); jQuery(this).find('.remove_compare').addClass('hide_it'); } }); } jQuery(document).on('click', '.add_compare', function(e) { e.preventDefault(); var vehicleId = jQuery(this).data( 'id' ); addCompareItem(vehicleId); manageComparison(); var vehicles = getCompareArray(); if(vehicles.length > 1) { var queryString = '?'; $.each(vehicles, function (index, value) { var incIndex = index+1; queryString += 'v' + (incIndex) + '=' + value + '&' }); var compareUrl = wp_localize.compare_page + queryString; compareUrl = compareUrl.slice(0, -1); cleanCompareItem(); window.location.href = compareUrl; } }); jQuery(document).on('click', '.remove_compare', function(e) { e.preventDefault(); var vehicleId = jQuery(this).data( 'id' ); removeVehicleId(vehicleId); manageComparison(); }); function getCompareArray() { var vehicleIds = JSON.parse(localStorage.getItem('compare_vehicles')); if(!jQuery.isArray(vehicleIds) || vehicleIds == null) { return []; } return vehicleIds; } Array.prototype.remove = function() { var what, a = arguments, L = a.length, ax; while (L && this.length) { what = a[--L]; while ((ax = this.indexOf(what)) !== -1) { this.splice(ax, 1); } } return this; }; function removeVehicleId(vehicleId) { var vehicleIds = getCompareArray(); vehicleIds = vehicleIds.remove(vehicleId); localStorage.setItem('compare_vehicles', JSON.stringify(vehicleIds)); } function cleanCompareItem(vehicleId) { localStorage.setItem('compare_vehicles', null); } function addCompareItem(vehicleId) { var vehicleIds = getCompareArray(); if (jQuery.inArray(vehicleId, vehicleIds)!='-1') { } else { vehicleIds.push(vehicleId); localStorage.setItem('compare_vehicles', JSON.stringify(vehicleIds)); } } // Loading vehicle details jQuery(".load_content").click(function(){ $('#carVideo').modal('show'); $('#modalLoader').show(); var vehicleId = $(this).data( 'id' ); $.ajax({ url: wp_localize.ajax_url, type: 'post', data: { action: 'wp_autocar_vehicle_details', vehicle_id: vehicleId }, success: function(response) { if(response == '0') { $('#carVideo').modal('hide') } else { setTimeout(function () { $('#modalLoader').hide(); }, 1000) $('#modalContent').html(response); resizeModalsContent(); } }, fail: function(error) { $('#modalLoader').hide(); $('#carVideo').modal('hide'); } }); return false; }); var wrapperHeight = $('#wrapper').height(); var docHeight = $(window).height(); if(wrapperHeight < docHeight) { $('.copy-right').addClass('abs-footer'); } });