$(document).ready(function() { var width = $(window).width(); var height = $(window).height(); /********* opacity 0 modal home ********/ if ($('body').hasClass('home')) { $('#myModal30').modal('show'); $('.modal-backdrop').css('display', 'none'); } /********* slick ********/ if (width > 767) { $('.section-home .slick').slick({ infinite: true, draggable: false, slidesToShow: 4, slidesToScroll: 4, autoplay: true, responsive: [{ breakpoint: 991, settings: { arrows: true, centerMode: true, centerPadding: '0px', slidesToShow: 3 } }] }); } else { var sliderMobile = $('.row.slick > div'); var countSlider = sliderMobile.length; var count = 0; var flag = false; var interval = setInterval(function() { if ($(sliderMobile[countSlider - 1]).hasClass('active')) { flag = true; } else { flag = false; } $(sliderMobile[count]).removeClass('show'); $(sliderMobile[count + 1]).removeClass('show'); $(sliderMobile[count + 2]).removeClass('show'); $(sliderMobile[count + 3]).removeClass('show'); setTimeout(function() { $(sliderMobile[count]).removeClass('active'); $(sliderMobile[count + 1]).removeClass('active'); $(sliderMobile[count + 2]).removeClass('active'); $(sliderMobile[count + 3]).removeClass('active'); if (flag) { count = -4; } $(sliderMobile[count + 4]).addClass('active'); $(sliderMobile[count + 5]).addClass('active'); $(sliderMobile[count + 6]).addClass('active'); $(sliderMobile[count + 7]).addClass('active'); setTimeout(function() { $(sliderMobile[count + 4]).addClass('show'); $(sliderMobile[count + 5]).addClass('show'); $(sliderMobile[count + 6]).addClass('show'); $(sliderMobile[count + 7]).addClass('show'); count = count + 4; }, 100); }, 300); }, 4000); } /********* slider magazine ********/ if ($('.magazine-slide').size() > 0) { if (width < 768) { $('.section-home .box-magazine .container').height($('.magazine-slide.active').height()); } var balls = $('.box-magazine .carousel-indicators li'); var countBalls = balls.length; var timing = 4000; var i = 1; var interval = setInterval(function() { $(balls[i % countBalls]).trigger('click', [1]); i++; }, timing); $('.box-magazine .carousel-indicators li').on('click', function(e, t) { e.preventDefault(); var index = $(this).index() + 1; $(balls).removeClass('active'); $('.magazine-slide').removeClass('active'); $('.box-magazine .carousel-indicators li:nth-child(' + index + ')').addClass('active'); setTimeout(function() { $('.magazine-slide:nth-child(' + index + ')').addClass('active'); if (width < 768) { $('.section-home .box-magazine .container').height($('.magazine-slide:nth-child(' + index + ')').height()); } }, 300); if (!t) { clearInterval(interval); } }); } /********* sign up ********/ if ($('.section-signup').size() > 0) { $('input[name=live]').on('change', function() { if (this.value == 'yes') { $('.form-group.month').removeClass('active'); } else if (this.value == 'no') { $('.form-group.month').addClass('active'); } }); } /********* open offer modal ********/ $('.link-offer').on('click', function(e) { $('body').addClass('overflow'); $('.modal .modal-overlay .content').show(); $('.modal').addClass('show'); $('.modalHome').removeClass('show'); setTimeout(function() { $('.modal').css('opacity', 1); }, 100); e.preventDefault(); var data = { offer: $(this).data('offer') }; $.post(templateUri + "/get-offer.php", data, function(response) { var res = JSON.parse(response); $('.modal .modal-header .image').attr('src', res.image); $('.modal .modal-header h4').html(res.title); $('.modal .modal-header h5').html(res.term); $('.modal .modal-header .discount span').html(res.discount); $('.modal .modal-content').html(res.content); setTimeout(function() { $('.modal .modal-overlay .content').hide(); $('.modal .box-modal').css('opacity', 1); }, 500); }); }); $('.modal .modal-content').css('max-height', height / 2); $(window).resize(function() { height = $(window).height(); $('.modal .modal-content').css('max-height', height / 2); }); $('.modal .close, .modal .modal-overlay').on('click', function() { $('.modal, .modal .box-modal').css('opacity', 0); $('body').removeClass('overflow'); setTimeout(function() { $('.modal').removeClass('show'); $('#email-offer').val(''); $('.email-contact').hide(); $('.email-contact').removeClass('has-error'); }, 500); }); $('.form-control').on('input', function(e) { $(this).parent().removeClass('has-error'); $(this).parent().find('.message').remove(); }); /********* sign up form ********/ $('.form-group').on('click', '.message', function(e) { $(this).prev().focus(); }); var signUpSent = false; $('#sign-up').on('click', function(e) { e.preventDefault(); if (!signUpSent) { $('.has-error').removeClass('has-error'); $('.form-group .message').remove(); var validate_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/; var error = false; $('.form-signup .form-control').each(function() { if (!error) { if ($(this).hasClass('number')) { if ($(this).val() == '' || isNaN($(this).val())) { $(this).focus(); $(this).parent().addClass('has-error'); $(this).parent().append('
') .appendTo('body').submit().remove(); }; }; '); error = true; } } else if ($(this).hasClass('email')) { if ($(this).val() == '' || !validate_email.test($(this).val())) { $(this).focus(); $(this).parent().addClass('has-error'); $(this).parent().append(' '); error = true; } } else if ($(this).hasClass('check')) { if (!$(this).is(':checked')) { $(this).focus(); $(this).parent().addClass('has-error'); error = true; } } else if ($(this).hasClass('ignore')) { error = false; } else { if ($(this).val() == '') { $(this).focus(); $(this).parent().addClass('has-error'); if ($(this).parent().hasClass('genre')) { $(this).parent().append(' '); } else { $(this).parent().append(' '); } error = true; } } } }); if (!error) { emailSent = true; $('.has-error').removeClass('has-error'); $('.email-contact .actions').css('display', 'inline-block'); $('.email-contact .fa-spin').css('opacity', '1'); var dataForm = $('.form-signup').serialize(); var dataUrl = $('#uri').val() + '/mail.php'; $.ajax({ type: "POST", url: dataUrl, data: dataForm, success: function() { $('.email-contact .fa-spin').css('opacity', '0'); setTimeout(function() { $('.email-contact .fa-check').css('opacity', '1'); $('.form-signup')[0].reset(); }, 500); }, error: function() { $('.email-contact .fa-spin').css('opacity', '0'); setTimeout(function() { $('.email-contact .fa-times').css('opacity', '1'); }, 500); } }); } } }); $('.link-magazine, .magazine-slide a').on('click', function(e) { var url = $(this).data('pdf'); setTimeout(function() { if (is_touch_device()) { e.preventDefault(); window.location = url; } }, 200); }); /********* save pdf offers ********/ $('#save-offer').on('click', function(e) { e.preventDefault(); $.download( templateUri + '/save-offers.php', { image: $('.box-modal .image').attr('src'), percent: $('.box-modal .modal-header .discount span').text(), title: $('.box-modal .modal-header .content h4').text(), subtitle: $('.box-modal .modal-header .content h5').text(), text: $('.box-modal .modal-content').html() } ); }); $('#email-show').on('click', function(e) { e.preventDefault(); $('.box-modal .modal-footer .email-contact').show(); }); var emailSent = false; $('#send-email').on('click', function(e) { e.preventDefault(); if (!emailSent) { var email = $('#email-offer').val(); var validate_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/; if (email == '' || !validate_email.test(email)) { $('#email-offer').focus(); $('#email-offer').parent().addClass('has-error'); } else { emailSent = true; $('.has-error').removeClass('has-error'); $('.email-contact .actions').css('display', 'inline-block'); $('.email-contact .fa-spin').css('opacity', '1'); $.post( templateUri + '/save-offers.php', { isemail: true, email: email, templateuri: templateUri, image: $('.box-modal .image').attr('src'), percent: $('.box-modal .modal-header .discount span').text(), title: $('.box-modal .modal-header .content h4').text(), subtitle: $('.box-modal .modal-header .content h5').text(), text: $('.box-modal .modal-content').html() }, function(data) { $('.email-contact .fa-spin').css('opacity', '0'); if (data == 'Message sent!') { setTimeout(function() { $('.email-contact .fa-check').css('opacity', '1'); }, 500); } else { setTimeout(function() { $('.email-contact .fa-times').css('opacity', '1'); }, 500); } } ); } } }); }); function is_touch_device() { return !!('ontouchstart' in window); } jQuery.download = function(url, data, method) { //url and data options required if (url && data) { //data can be string of parameters or array/object data = typeof data == 'string' ? data : jQuery.param(data); //split params into form inputs var inputs = ''; jQuery.each(data.split('&'), function() { var pair = this.split('='); inputs += ''; }); //send request jQuery('