jQuery(document).ready(function($) { "use strict"; var $ = jQuery; var screenRes = $(window).width(), screenHeight = $(window).height(), html = $('html'); var menuItemWidth, submenuItemWidth; jQuery(".fw-nav-menu > li").hover(function(){ var $this = $(this); $this.children('ul').prepend('
  • '); menuItemWidth = $this.innerWidth(); submenuItemWidth = $this.children("ul").innerWidth(); $this.children("ul").css('left' , (menuItemWidth-submenuItemWidth)/2); }, function(){ jQuery('.arrow-dropdown').remove(); }); //DropDown menu if not fit en screen align to left jQuery(".fw-nav-menu li").hover(function(){ var $this = $(this); if($this.hasClass('parent')) { var dropdown = $this.children('ul'), dropdownWidth = dropdown.outerWidth(), dropdownOffset = parseInt(dropdown.offset().left, 10); if (dropdownWidth + dropdownOffset > screenRes) { dropdown.addClass('left'); } else{ dropdown.removeClass('left'); } } }); // IE<8 Warning if (html.hasClass("ie7")) { $("body").empty().html('Please, Update your Browser to at least IE8'); } // Disable Empty Links $("[href=#]").click(function(event){ event.preventDefault(); }); // Body Wrap $(".body-wrap").css("min-height", screenHeight); $(window).resize(function() { screenHeight = $(window).height(); $(".body-wrap").css("min-height", screenHeight); }); // Remove outline in IE $("a, input, textarea").attr("hideFocus", "true").css("outline", "none"); if(jQuery('select[class*="select-"]').length > 0){ jQuery('select[class*="select-"]').selectize({ create: true, sortField: 'text' }); } // Styled Select, CheckBox, RadioBox if ($(".input-styled").length) { $(".input-styled input").customInput(); } // prettyPhoto lightbox, check if has atrr data-rel and hide for Mobiles if($('a').is('[data-rel]') && screenRes > 600) { $('a[data-rel]').each(function() { $(this).attr('rel', $(this).data('rel')); }); $("a[rel^='prettyPhoto']").prettyPhoto({ social_tools:false, theme: 'dark_square', horizontal_padding: 100, overlay_gallery: false, changepicturecallback: function() { var $holder = jQuery('.pp_nav .currentTextHolder'), splitted = $holder.text().split('/'); $holder.html(splitted.join('/')); } }); } // Crop Images in Image Slider // adds .naturalWidth() and .naturalHeight() methods to jQuery for retrieving a normalized naturalWidth and naturalHeight. (function($){ var props = ['Width', 'Height'], prop; while (prop = props.pop()) { (function (natural, prop) { $.fn[natural] = (natural in new Image()) ? function () { return this[0][natural]; } : function () { var node = this[0], img, value; if (node.tagName.toLowerCase() === 'img') { img = new Image(); img.src = node.src, value = img[prop]; } return value; }; }('natural' + prop, prop.toLowerCase())); } }(jQuery)); var carousels_on_page = $('.carousel-inner').length, carouselWidth, carouselHeight, ratio, imgWidth, imgHeight, imgRatio, imgMargin, this_image, images_in_carousel; for(var i = 1; i <= carousels_on_page; i++){ $('.carousel-inner').eq(i-1).addClass('id'+i); } function imageSize() { setTimeout(function () { for(var i = 1; i <= carousels_on_page; i++){ carouselWidth = $('.carousel-inner.id'+i+' .item').width(); carouselHeight = $('.carousel-inner.id'+i+' .item').height(); ratio = carouselWidth/carouselHeight; images_in_carousel = $('.carousel-inner.id'+i+' .item img').length; for(var j = 1; j <= images_in_carousel; j++){ this_image = $('.carousel-inner.id'+i+' .item img').eq(j-1); imgWidth = this_image.naturalWidth(); imgHeight = this_image.naturalHeight(); imgRatio = imgWidth/imgHeight; if(ratio <= imgRatio){ imgMargin = parseInt((carouselHeight/imgHeight*imgWidth-carouselWidth)/2, 10); this_image.css("cssText", "height: "+carouselHeight+"px; margin-left:-"+imgMargin+"px;"); } else{ imgMargin = parseInt((carouselWidth/imgWidth*imgHeight-carouselHeight)/2, 10); this_image.css("cssText", "width: "+carouselWidth+"px; margin-top:-"+imgMargin+"px;"); } } } }, 0); } $(window).load(function(){ imageSize(); }); $(window).resize(function() { $('.carousel-indicators li:first-child').click(); imageSize(); }); //Iframe Serponsive function adjustIframes() { $('iframe').each(function(){ var $this = $(this), proportion = $this.data( 'proportion' ), w = $this.attr('width'), actual_w = $this.width(); if ( ! proportion ) { proportion = $this.attr('height') / w; $this.data( 'proportion', proportion ); } if ( actual_w != w ) { $this.css( 'height', Math.round( actual_w * proportion ) + 'px' ); } }); } $(window).on('resize load',adjustIframes); // Detect Click in Iframe function detectIframeClick() { var overiFrame = -1; jQuery('.myCarousel').find('iframe').hover( function() { overiFrame = 1; }, function() { overiFrame = -1 }); $(window).on('blur', function() { if( overiFrame != -1 ) { jQuery('.myCarousel').carousel('pause'); } }); jQuery('.carousel-control, .carousel-indicators li').click(function() { jQuery('.myCarousel').carousel('cycle'); }); } detectIframeClick(); // Set Column height var totalHeight = 0; jQuery('.column-height').each(function() { var info_height = $(this).outerHeight(); if (info_height > totalHeight) { totalHeight = info_height; } }); jQuery('.column-height').css('height', totalHeight); //Date picker for Bookings Form if(jQuery('#datepicker').length > 0){ jQuery('#datepicker').datetimepicker({ timepicker:false, format:'d.m.Y', closeOnDateSelect:true, minDate:0 }); } //Calendar SideBar function assignCalendar(id){ $('
    ') .insertAfter( $(id) ) .multiDatesPicker({ dateFormat: 'yy-mm-dd', minDate: new Date(), maxDate: '+1y', altField: id, firstDay: 1, showOtherMonths: false }).prev().hide(); } if(jQuery('#calendar-datepicker').length > 0){ assignCalendar('#calendar-datepicker'); } //Contact Form Close & Open Form Button if(jQuery('.wrap-contact-form').length > 0){ jQuery('.hide-open-form').click(function () { if ($(this).parent('.wrap-contact-form').hasClass('open')) { $(this).parent('.wrap-contact-form').removeClass('open', 1000).addClass('close', 1000); jQuery('.hide-open-form[data-toggle="tooltip"]').attr('data-original-title', 'Open Form'); jQuery('.hide-open-form i').removeClass('tficon-close').addClass('tficon-row-up'); } else { $(this).parent('.wrap-contact-form').removeClass('close', 1000).addClass('open', 1000); jQuery('.hide-open-form[data-toggle="tooltip"]').attr('data-original-title', 'Hide Form'); jQuery('.hide-open-form i').removeClass('tficon-row-up').addClass('tficon-close'); } return false; }); } //ToolTip if(jQuery("[data-toggle='tooltip']").length > 0){ jQuery("[data-toggle='tooltip']").tooltip(); } //Sidebar and Content = height if(screenRes > 1000){ var $sidebar = jQuery('.fw-content-area'); if ($sidebar.length) { var $content = jQuery('.fw-sidebar'); setTimeout(function() { var sidebarHeight = $sidebar.outerHeight(), contentHeight = $content.outerHeight(); if (sidebarHeight > contentHeight) { $content.css('height', sidebarHeight); } else { $sidebar.css('height', contentHeight); } }, 0); } } //Contact Form Close & Open Form Button if(jQuery('.fw-contact-form-absolute .wrap-forms').length > 0){ //Calculate Height Form var height_wrap_form = jQuery('.fw-contact-form').addClass('open').outerHeight(); jQuery('.fw-contact-form.open').css('height', height_wrap_form); //Preppend Link Close-Open Form jQuery('.fw-contact-form.open').append(''); jQuery('.hide-open-form').click(function () { if ($(this).parent('.fw-contact-form').hasClass('open')) { $(this).parent('.fw-contact-form').removeClass('open').addClass('close'); jQuery('.hide-open-form[data-toggle="tooltip"]').attr('data-original-title', 'Open Form'); jQuery('.hide-open-form i').removeClass('tficon-close').addClass('tficon-row-up'); } else { $(this).parent('.fw-contact-form').removeClass('close').addClass('open'); jQuery('.hide-open-form[data-toggle="tooltip"]').attr('data-original-title', 'Hide Form'); jQuery('.hide-open-form i').removeClass('tficon-row-up').addClass('tficon-close'); } return false; }); } //Scroll To jQuery(".scroll-to").click(function(){ var selected = $(this).attr('href'); $.scrollTo(selected, 1000); return false; }); // Recalculate Height for Home Post List function recalculateHomePostList() { setTimeout(function () { var $elements = $('.post-list .element'), heights = [], maxHeight; $elements.removeAttr('style').each(function() { heights.push($(this).outerHeight()); }); maxHeight = Math.max.apply(null, heights); $elements.css('height', maxHeight); }, 0); } recalculateHomePostList(); $(window).resize(recalculateHomePostList); // Sticky Menu $(window).on('scroll', function () { var sticky_header = jQuery('.fw-header-sticky .fw-header'); var sticky_header_menu = jQuery('.fw-header-sticky .fw-header.fw-sticky-menu'); if (jQuery(window).scrollTop() > 100) { sticky_header.addClass('fw-sticky-menu'); } else { sticky_header.removeClass('fw-sticky-menu'); }; if (jQuery(window).scrollTop() > 250) { sticky_header_menu.addClass('fw-open'); } else { sticky_header_menu.removeClass('fw-open'); } }); // Responsive Menu (Mobile Menu) var Mobile_Menu = function() { jQuery(".fw-site-navigation ul .mega-menu").hide(); if(jQuery('.fw-site-navigation#fw-menu-secondary').length > 0){ jQuery('.fw-site-navigation#fw-menu-secondary .fw-nav-menu').children('li').appendTo('.fw-site-navigation#fw-menu-primary .fw-nav-menu'); jQuery('.fw-site-navigation#fw-menu-secondary').remove(); } var $menu = jQuery(".fw-site-navigation#fw-menu-primary").clone(); $menu.attr("id", "mobile-menu").removeClass().appendTo('.fw-header .fw-header-main .fw-container'); $menu.find('.mega-menu').remove(); jQuery('').prependTo(".fw-header .fw-header-main .fw-container"); $menu.mmenu({ counters: true, offCanvas: { position : "right" } }, { classNames: { selected: "current-menu-item" } }); }; if(screenRes < 800){ Mobile_Menu(); } // Search Button var searchCloseOpen = function(){ $('.fw-buton-icon').on('click', function(){ $('.fw-wrap-search-form').fadeToggle( 300, function() { $(this).parent().toggleClass('opened'); }); $(this).children('.fw-buton-icon i.fa').toggleClass('fa-search fa-close'); }); } searchCloseOpen(); // Toggles $('.toggle-link').click(function(){ $(this).parents('.toggle').removeClass('collapsed'); if(!$(this).hasClass('collapsed')) { $(this).parents('.toggle').addClass('collapsed'); } }); $(".opened").find(".panel-collapse").addClass("in"); $(".panel-toggle").click (function() { $(this).closest(".toggleitem").toggleClass("opened");; }); // pricing function tablePriceInit() { $(".fw-price-table").each(function () { var this_table_width = $(this).width(); var this_table_cols = $(this).children().size(); var this_col_width = (this_table_width / this_table_cols); $(this).children(".fw-price-col").css('width', this_col_width-1); var table_col_height = 0; var this_col_row = $(this).children().find(".fw-price-row"); this_col_row.each(function() { table_col_height = table_col_height > $(this).height() ? table_col_height : $(this).height(); }); this_col_row.each(function() { $(this).height(table_col_height); }); }); } if($('.fw-price-table').length) { tablePriceInit(); $(window).on('resize', function(){ tablePriceInit(); }); } fw_ajax_post_love_it(); /** * Mega Menu */ jQuery(function ($) { function hoverIn() { var a = $(this); var nav = a.closest('.primary-navigation'); var mega = a.find('.mega-menu'); var offset = rightSide(nav) - leftSide(a); var col_width = 280 + 2; // 2px border left var col_width2 = a.closest('.fw-container').width()/columns(mega); if (columns(mega) < 4 ) { mega.width(Math.min(rightSide(nav), columns(mega)*col_width)); mega.children('.mega-menu-row').each(function () { $(this).children('.mega-menu-col').css('width',col_width); }); } else { mega.width(Math.min(rightSide(nav), columns(mega)*col_width2)); mega.children('.mega-menu-row').each(function () { $(this).children('.mega-menu-col').css('width',col_width2, 'important'); }); } mega.css('left', Math.min(0, offset - mega.width())); var offset_arrow = leftSide(a) - leftSide(a.find('.sub-menu')) + a.width()/2 - 8; mega.children('.sub-menu').prepend('
  • '); $('.arrow-dropdown').css('margin-left', offset_arrow); } function hoverOut() { } function columns(mega) { var columns = 0; mega.children('.mega-menu-row').each(function () { columns = Math.max(columns, $(this).children('.mega-menu-col').length); }); return columns; } function leftSide(elem) { return elem.offset().left; } function rightSide(elem) { return elem.offset().left + elem.width(); } $('.primary-navigation .menu-item-has-mega-menu').hover(hoverIn, hoverOut); }); }); function fw_ajax_post_love_it() { "use strict"; // Author code here var love_post = jQuery(".fw-js-love-post"); love_post.on('click', function(){ var _this = jQuery(this); var id = _this.attr('data-post-id'); var ajax_data = "action=fw_ajax_post_love_it&id="+id; jQuery.ajax({ type: "POST", url: FwPhpVars.ajax_url, data: ajax_data, success: function(rsp){ var obj = jQuery.parseJSON(rsp); console.log(obj); if(obj['success'] == 'post-is-loved'){ // this post is already loved } else if(obj['success']){ // is true _this.removeClass('fw-love-post').addClass('fw-loved'); // obj['count'] - is the number of loves _this.find('span').html(obj['count']); } else{ // is false } } }); }); return false; } /** * Forms */ jQuery(function($) { "use strict"; var formErrorMessageClass = 'form-error', formErrorHideEventNamespace = '.form-error-hide', errorTemplate = '

    {message}

    '; // todo: customize this (add class="" instead of style="") function showFormError($form, inputName, message) { var inputSelector = '[name="'+ inputName +'"]', $input = $form.find(inputSelector).last(), $message = $(errorTemplate.replace('{message}', message)); if ($input.length) { $input.parent().after($message); $form.one('focusout'+ formErrorHideEventNamespace, inputSelector, function(){ $message.slideUp(function(){ $(this).remove(); }); }); } else { // if input not found, show message in form $form.prepend($message); } } function themeGenerateFlashMessagesHtml(types) { var html = [], typeHtml = []; $.each(types, function(type, messages){ typeHtml = []; $.each(messages, function(messageId, messageData){ /*typeHtml.push(messageData.message);*/ typeHtml.push(messageData); }); if (typeHtml.length) { html.push( '' ); } }); if (html.length) { return html.join(''); } else { return '

    Success

    '; } } /** * Display FW_Form errors */ do { if (typeof _fw_form_invalid == 'undefined') { break; } var $form = $('form.fw_form_'+ _fw_form_invalid.id).first(); if (!$form.length) { console.error('Form not found on the page'); break; } $.each(_fw_form_invalid.errors, function(inputName, message){ showFormError($form, inputName, message); }); } while(false); /** * Ajax submit */ { $(document.body).on('submit', 'form[data-fw-ext-forms-type="contact-forms"]', function(e){ e.preventDefault(); var $form = $(this); // todo: show loading jQuery.ajax({ type: "POST", url: FwPhpVars.ajax_url, data: $(this).serialize(), dataType: 'json' }).done(function(r){ if (r.success) { // prevent multiple submit $form.on('submit', function(e){ e.preventDefault(); e.stopPropagation(); }); $form.html( themeGenerateFlashMessagesHtml(r.data.flash_messages) ); } else { // hide all current error messages $form.off(formErrorHideEventNamespace) .find('.'+ formErrorMessageClass).remove(); // add new error messages $.each(r.data.errors, function(inputName, message) { showFormError($form, inputName, message); }); } }).fail(function(){ // todo: show server error }); }); } }); // for display table for special heading (function(){ var tId = setInterval(function() { if (document.readyState == "complete") onComplete(); }, 11); function onComplete(){ clearInterval(tId); var parent = jQuery('.fw-main-row-top'), child = jQuery('.fw-heading'); if(parent.find(child).length > 0){ var t = jQuery('.fw-main-row-top'); t.addClass("fw-middle-align"); } }; })()