/* ============================================== Preloader =============================================== */ $(window).load(function(){ $('#preloader').fadeOut('slow',function(){$(this).remove();}); $(".sticky").sticky({topSpacing: 40}); }); $(window).scroll(function(){ if ($(this).scrollTop() > 100) { $('.back-to-top').fadeIn(); } else { $('.back-to-top').fadeOut(); } }); $('.back-to-top').click(function(){ $("html, body").animate({ scrollTop: 0 }, 1000); return false; }); $(document).ready(function () { var today = new Date(); $('.dp2').datepicker({ format: "dd/mm/yyyy", autoclose: true, startDate: today }); $("#testi-carousel, #service-images").owlCarousel({ // Most important owl features items: 1, autoplay: true, autoplaySpeed: 1500, autoplayTimeout: 8000, autoplayHoverPause: true, nav: false, loop: true, dots: true, autoHeight: true }); }); $(document).on("click", ".open-booknow", function () { var myBookId = $(this).data('id'); $(".modal-body #subject2").val( myBookId ); $('#booknow').modal('show'); }); /* ============================================== Contact App =============================================== */ $(function() { $('#booking2').hide(); $('#subject2').change(function(){ if($('#subject2').val() == 'Booking') { $('#booking2').show(); } else { $('#booking2').hide(); } }); }); //var $ = jQuery.noConflict(); //Relinquish jQuery's control of the $ variable. /*global jQuery */ jQuery(function ($) { 'use strict'; /** * Contact Form Application */ var ContactFormApp = { $contactForm: $("#ajax-form"), $contactFormBtn: $("#send"), $contactFormName: $("#name2"), $contactFormPrivacy: $("#privacy"), $contactFormEmail: $("#email2"), $contactFormMessage: $("#message2"), $confirmMessage: $("#ajaxsuccess"), $errorMessages: $(".error"), $errorName: $("#err-name"), $errorPrivacy: $("#err-privacy"), $errorEmail: $("#err-emailvld"), $errorMessage: $("#err-message"), $errorForm: $("#err-form"), $errorTimeout: $("#err-timedout"), $errorState: $("#err-state"), //Validate Contact Us Data validate: function () { var error = false; // we will set this true if the form isn't valid var name = this.$contactFormName.val(); // get the value of the input field if(name == "" || name == " " || name == "Name") { this.$errorName.show(500); this.$errorName.delay(6000); this.$errorName.animate({ height: 'toggle' }, 500, function() { // Animation complete. }); error = true; // change the error state to true } var privacy = document.getElementById("privacy").checked; if(privacy == false) { this.$errorPrivacy.show(500); this.$errorPrivacy.delay(6000); this.$errorPrivacy.animate({ height: 'toggle' }, 500, function() { // Animation complete. }); error = true; // change the error state to true } var email_compare = /^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/; // Syntax to compare against input var email = this.$contactFormEmail.val().toLowerCase(); // get the value of the input field if (email == "" || email == " " || email == "E-mail") { // check if the field is empty this.$contactFormEmail.fadeIn('slow'); // error - empty error = true; } else if (!email_compare.test(email)) { // if it's not empty check the format against our email_compare variable this.$errorEmail.show(500); this.$errorEmail.delay(6000); this.$errorEmail.animate({ height: 'toggle' }, 500, function() { // Animation complete. }); error = true; } var message = this.$contactFormMessage.val(); // get the value of the input field if(message == "" || message == " " || message == "Message") { this.$errorMessage.show(500); this.$errorMessage.delay(6000); this.$errorMessage.animate({ height: 'toggle' }, 500, function() { // Animation complete. }); error = true; // change the error state to true } if(error == true) { this.$errorForm.show(500); this.$errorForm.delay(4000); this.$errorForm.animate({ height: 'toggle' }, 500, function() { // Animation complete. }); } return error; }, //contact form submit handler contactFormSubmit: function (obj) { this.$errorMessages.fadeOut('slow'); // reset the error messages (hides them) if(this.validate() == false) { var data_string = $('#ajax-form').serialize(); // Collect data from form var $this = this; $.ajax({ type: "POST", url: "/mail/contact.php", data: data_string, timeout: 6000, cache: false, crossDomain: false, error: function(request,error) { if (error == "timeout") { $this.$errorTimeout.slideDown('slow'); } else { $this.$errorState.slideDown('slow'); $this.$errorState.html('An error occurred: ' + error + ''); } }, success: function() { $this.$confirmMessage.show(500); $this.$confirmMessage.delay(6000); $this.$confirmMessage.animate({ height: 'toggle' }, 500, function() { }); $this.$contactFormName.val(''); $this.$contactFormEmail.val(''); $this.$contactFormMessage.val(''); document.getElementById("privacy").checked = false; } }); } return false; }, bindEvents: function () { //binding submit event this.$contactFormBtn.on('click', this.contactFormSubmit.bind(this)); }, init: function () { //initializing the contact form console.log('Contact form is initialized'); this.bindEvents(); return this; } }; //Initializing the app ContactFormApp.init({}); });