(function ($) { "use strict"; // Config //------------------------------------------------------------------------------- var companyName = 'Escape Spa & Massage'; var address = '6 Sansome Walk, Worcester, WR1 1LH'; // Enter your Address // Parallax Scrolling //------------------------------------------------------------- // var $w = $(window); //var newsletterSimple = $('.newsletter-simple'); //var productInfo = $('.product-info'); //function move($c) { // var offset = $c.offset().top; // var scroll = $w.scrollTop(); // var diff = offset - scroll; // var pos = 'center ' + (-diff) * 0.2 + 'px'; // $c.css({'backgroundPosition': pos}); //} //$w.bind('scroll', function (e) { // move(newsletterSimple); // move(productInfo); //}); // Preloader //------------------------------------------------------------------------------- window.onscroll = function () { window.scrollTo(0, 0); }; $(window).load(function () { setTimeout(function () { window.onscroll = function () { }; $('#page-preloader').addClass('slideOutUp'); // Fix for IE 9 setTimeout(function () { $('#page-preloader').addClass('hidden'); }, 700); }, 100); }); // Initialize Tooltip //------------------------------------------------------------- $('.my-tooltip').tooltip(); // Initialize Datetimepicker //------------------------------------------------------------------------------- $('.datepicker').datepicker().on('changeDate', function () { $(this).datepicker('hide'); }); // Scroll To Animation //------------------------------------------------------------------------------- $('body').scrollspy({target: '#navigation-top-1', offset: 88}); var scrollTo = $(".scroll-to"); scrollTo.click(function (event) { $('.modal').modal('hide'); var position = $(document).scrollTop(); var scrollOffset = 87; var marker = $(this).attr('href'); $('html, body').animate({scrollTop: $(marker).offset().top - scrollOffset}, 'slow'); return false; }); // Scroll Up Btn //------------------------------------------------------------------------------- $(window).scroll(function () { if ($(this).scrollTop() > 100) { $('.scroll-up-btn').removeClass("animated fadeOutRight"); $('.scroll-up-btn').fadeIn().addClass("animated fadeInRight"); } else { $('.scroll-up-btn').removeClass("animated fadeInRight"); $('.scroll-up-btn').fadeOut().addClass("animated fadeOutRight"); } }); // Navigation Top //------------------------------------------------------------- $(document).scroll(function () { var y = $(this).scrollTop(); if (y > 300) { $('.navbar-hidden').fadeIn(); } else { $('.navbar-hidden').fadeOut(); } }); // Gallery //------------------------------------------------------------- $(".gallery .gallery-thumbnail-container").on("click", function () { var src = $(this).find("img").data('img'); var galleryImg = $('').attr('src', src).addClass('img-responsive'); var galleryImgWidth; galleryImg.load(function () { galleryImgWidth = this.width; }); var imgTitle = $(this).find('.gallery-img-title').html(); var imgSubtitle = $(this).find('.gallery-img-subtitle').html(); $('#galleryModal').modal(); $('#galleryModal').on('shown.bs.modal', function () { $('#galleryModal .modal-dialog').css('max-width', galleryImgWidth); $('#galleryModal .modal-body').html(galleryImg); $('#galleryModal .modal-nav .title').html(imgTitle + ' - ' + imgSubtitle); }); $('#galleryModal').on('hidden.bs.modal', function () { $('#galleryModal .modal-body').html(''); }); }); /* fix vertical when not overflow call fullscreenFix() if .fullscreen content changes */ function fullscreenFix() { var h = $('body').height(); // set .fullscreen height $(".content-b").each(function (i) { if ($(this).innerHeight() <= h) { $(this).closest(".fullscreen").addClass("not-overflow"); } }); } $(window).resize(fullscreenFix); fullscreenFix(); /* resize background images */ function backgroundResize() { var windowH = $(window).height(); $(".header-full-screen-img").each(function (i) { var path = $(this); // variables var contW = path.width(); var contH = path.height(); var imgW = path.attr("data-img-width"); var imgH = path.attr("data-img-height"); var ratio = imgW / imgH; // overflowing difference var diff = parseFloat(path.attr("data-diff")); diff = diff ? diff : 0; // remaining height to have fullscreen image only on parallax var remainingH = 0; if (path.hasClass("parallax")) { var maxH = contH > windowH ? contH : windowH; remainingH = windowH - contH; } // set img values depending on cont imgH = contH + remainingH + diff; imgW = imgH * ratio; // fix when too large if (contW > imgW) { imgW = contW; imgH = imgW / ratio; } // path.data("resized-imgW", imgW); path.data("resized-imgH", imgH); path.css("background-size", imgW + "px " + imgH + "px"); }); } $(window).resize(backgroundResize); $(window).focus(backgroundResize); backgroundResize(); // Contact Form //------------------------------------------------------------- $('#contact-form-gmap').on('submit', function (event) { event.preventDefault(); $.ajax({ url: Routing.generate("service.contact"), method: 'POST', data: $(this).serialize(), // data: JSON.stringify({var:'val'}), // send data in the request body // contentType: "application/json; charset=utf-8", // if sending in the request body dataType: 'json' }).done(function (data, textStatus, jqXHR) { $('.flash-bag').addClass('alert alert-success').append(data.message).fadeIn(2000).delay(2500).fadeOut(2000, function () { $(this).empty().removeClass('alert alert-success'); }); }).fail(function (jqXHR, textStatus, errorThrown) { if (typeof jqXHR.responseJSON !== 'undefined') { if (jqXHR.responseJSON.hasOwnProperty('form')) { $('#form-body').html(jqXHR.responseJSON.form); } $('.form_error').html(jqXHR.responseJSON.message); } else { if (jqXHR.responseJSON.hasOwnProperty('message')) { $('.flash-bag').addClass('alert alert-danger').append(jqXHR.message).fadeIn(2000).delay(2500).fadeOut(2000, function () { $(this).empty().removeClass('alert alert-danger'); }); } } }).always(function (dataOrjqXHR, textStatus, jqXHRorErrorThrown) { console.log('always'); }); return false; }); // end document ready })(jQuery); // Load Contact Gmap //------------------------------------------------------------- var map; function initMap() { // The location of address var address = {lat: 52.195770, lng: -2.220360}; // The map, centered at address var map = new google.maps.Map( document.getElementById('map'), { zoom: 16, center: address }); // The marker, positioned at address var marker = new google.maps.Marker({position: address, map: map}); }