var wpHotel = { createAuto: function() { wpHotel.create(); }, create: function() { jQuery(document).ready(function() { wpHotel.rooms(); wpHotel.reviews(); wpHotel.starRank(); wpHotel.inputs(); wpHotel.selectMenuLink(); wpHotel.sectionGallery(); wpHotel.footerSpacer(); wpHotel.formContact(); wpHotel.galleryBar(); wpHotel.sideGallery(); wpHotel.carousel(); jQuery('input, textarea').placeholder(); }); jQuery(window).ready(function() { wpHotel.homeBgGallery(); wpHotel.initMobileMenu(); }); }, carousel: function() { jQuery('.jcarousel li').width(jQuery(window).width()); jQuery(window).resize(function() { jQuery('.jcarousel li').width(jQuery(window).width()); }) jQuery('.jcarousel').jcarousel({ center: true, wrap: 'both' }).jcarouselAutoscroll({ interval: 3000, autostart: true }); jQuery('.jcarousel-pagination').on('jcarouselpagination:active', 'a', function() { jQuery(this).addClass('active'); }) .on('jcarouselpagination:inactive', 'a', function() { jQuery(this).removeClass('active'); }).jcarouselPagination({ item: function(page) { return ''; } }); }, footerSpacer: function() { jQuery("#frame-footer-spacer").css('height', jQuery("#frame-footer").height() + 'px'); jQuery(window).on('resize', function() { jQuery("#frame-footer-spacer").css('height', jQuery("#frame-footer").height() + 'px'); }); }, initMobileMenu: function() { jQuery('head').append( '' ); this.mobile_menu_active = false; jQuery("#mobile-menu-link").on('click', function() { var $this = jQuery(this); if (!wpHotel.mobile_menu_active) { /* jQuery("#mobile-menu-css").html( '#frame-top nav.menu {' + 'top: ' + jQuery("#frame-top").height() + 'px;' + '}' ); */ jQuery('#frame-top nav.menu').fadeIn('fast'); wpHotel.mobile_menu_active = true; } else { jQuery('#frame-top nav.menu').fadeOut('fast'); wpHotel.mobile_menu_active = false; } return false; }); jQuery("body").on('click', function(e) { if (wpHotel.mobile_menu_active && !jQuery(e.target).closest('nav.menu').length) { jQuery('#frame-top nav.menu').fadeOut('fast'); wpHotel.mobile_menu_active = false; } }); }, selectMenuLink: function() { jQuery("#menu-main-menu li.current_page_item").addClass('active'); if (jQuery('body').hasClass('home')) { } if (!jQuery("#menu-main-menu li.current_page_item").prev().length) { // this is home page jQuery('body').addClass('page-home'); } else { // another page } }, sectionGallery: function() { if (jQuery('#section-gallery').length) { Code.photoSwipe('a', '#section-gallery'); } }, reviews: function() { if (this.noElements('.section-reviews .reviews')) { return false; } var ele = document.querySelector('.section-reviews .reviews'); var msnry = new Masonry(ele); }, rooms: function() { if (this.noElements('.section-accommodation .rooms')) { return false; } var ele = document.querySelector('.section-accommodation .rooms'); var msnry = new Masonry(ele); }, homeBgGallery: function() { if (this.noElements('.bg-gallery')) { return false; } jQuery('.bg-gallery').mosaicflow({ itemSelector: '.item', minItemWidth: 320 }).show(); }, inputs: function() { if (this.noElements('.datepicker')) { return false; } // jQuery('.datepicker').pikaday({ minDate: new Date() }); jQuery('.datepicker.from').change(function() { var minDate = new Date(jQuery(this).val()); var picker = new Pikaday({field: jQuery('.datepicker.to')[0]}); picker.setMinDate(minDate); }) jQuery('select').selectric({ arrowButtonMarkup: 'a' }); }, starRank: function() { if (this.noElements('.star-rank')) { return false; } // jQuery('.star-rank').each(function() { var $this = jQuery(this), this_value = $this.attr('data-value') * 1, this_html = ''; for (var i = 0; i < this_value; ++i) { this_html += ''; } $this.html(this_html); }); }, galleryBar: function() { if (this.noElements('.section-gallery-bar > .scroll-wrap')) { return false; } // jQuery(".section-gallery-bar").hide(); // var image_length = 0, image_activated = 0, image_arr = {}; var imageLengthCheck = function() { image_activated++; if (image_length == image_activated) { wpHotel.galleryBarActivate(); } }; var n = 0; jQuery(".section-gallery-bar img").each(function() { image_length++; image_arr[n] = new Image(); image_arr[n].src = this.getAttribute('src'); image_arr[n].onload = function() { imageLengthCheck(); }; }); //add fluidbox preview jQuery(window).load(function() { jQuery('.section-gallery-bar a').magnificPopup({type: 'image'}); }); }, sideGallery: function() { (function($) { $('.side-gallery').each(function() { var gallery = $(this); $(this).find('.scroll-wrap img').click(function() { var src = $(this).attr('src'); gallery.find('>img').attr('src', src); }) }); })(jQuery); }, galleryBarActivate: function() { jQuery(".section-gallery-bar").show(); var $scrollBar = jQuery(".section-gallery-bar > .scroll-wrap"); if (!$scrollBar.length) return false; // var scroll_width = 0; $scrollBar.children().each(function() { scroll_width += jQuery(this).innerWidth(); }); $scrollBar.css('width', scroll_width + 'px'); }, noElements: function(selector) { if (document.querySelector(selector)) { return false; } else { return true; } }, formContact: function() { jQuery(".contact-form").on('submit', function() { var $this = jQuery(this), $alert = $this.find('.alert-form-message'), this_err = null; $alert.removeClass('alert-success alert-danger'); $this.find('input[type=text],input[type=email],textarea,select').each(function() { var $this_input = jQuery(this), this_required = $this_input.attr('required'); if (!this_required) { return true; } if (this.value && this.getAttribute('type') == 'email' && this.value.indexOf('@') == -1 && this.value.indexOf('.') == -1) { this_err = true; $this_input.addClass('input-err'); } else if (!this.value) { this_err = true; $this_input.addClass('input-err'); } else { $this_input.removeClass('input-err'); } }); if (!this_err) { $alert.addClass('alert-success').text('Message was sent!').slideDown('fast').delay(2500).slideUp('fast'); wpHotel.formContactSendMessage(); this.reset(); } else { $alert.addClass('alert-danger').text('You have not filled in all the fields!').slideDown('fast'); } return false; }); }, formContactSendMessage: function(_func) { if (typeof _func != 'function') _func = function() { }; // var $form = jQuery('.contact-form'), form_data = []; $form.find('[placeholder]').each(function() { var $this = jQuery(this); form_data.push([$this.attr('placeholder'), $this.val()]); }); form_data = JSON.stringify(form_data); jQuery.ajax({ url: app_url.ajax + '?action=hotel_contact_form_message', data: { formData: encodeURIComponent(form_data) }, type: 'POST' }).done(function() { }); } };