(function($) { /*-------------------------------------------- Smooth scroll --------------------------------------------*/ $('a[href*="#"]:not([href="#"])').click(function() { if( ! $(this).hasClass( 'menu-toggle' ) && ! $(this).hasClass( 'menu-close' ) ) { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html, body').animate({ scrollTop: target.offset().top - 105 }, 1000); return false; } } } }); /*-------------------------------------------- Animsition --------------------------------------------*/ if( ! $( '#js-off' ).is(':visible') ) { $( '.site-content' ).addClass( 'animsition' ); } $(".animsition").animsition({ inClass: 'fade-in', outClass: 'fade-out', inDuration: 1500, outDuration: 800, linkElement: '.animsition-link', // e.g. linkElement: 'a:not([target="_blank"]):not([href^="#"])' loading: true, loadingParentElement: 'body', //animsition wrapper element loadingClass: 'animsition-loading', loadingInner: '', // e.g '' timeout: false, timeoutCountdown: 5000, onLoadEvent: true, browser: [ 'animation-duration', '-webkit-animation-duration'], // "browser" option allows you to disable the "animsition" in case the css property in the array is not supported by your browser. // The default setting is to disable the "animsition" in a browser that does not support "animation-duration". overlay : false, overlayClass : 'animsition-overlay-slide', overlayParentElement : 'body', transition: function(url){ window.location.href = url; } }); /*-------------------------------------------- Toggle Menu --------------------------------------------*/ // Trigger if( $( '#main-menu' ).length ) { $( '#main-menu-toggle, #main-menu-close' ).on( 'click', function(e) { e.preventDefault(); $( 'body' ).toggleClass( 'menu-open' ); $( '#main-menu-toggle, #main-menu' ).attr( 'aria-expanded', function (i, attr) { return attr == 'true' ? 'false' : 'true'; }); }); $( '#main-menu-toggle' ).one( 'click', function() { $( 'body.menu-open #primary-menu li.menu-item-has-children > a' ).each( function() { $( "" ).insertAfter( $(this) ); }); }); // $( '#main-menu-toggle' ).on( 'click', function() { // $( '.dropdown-opener' ).removeClass('opened'); // }); $( '#primary-menu' ).on( 'click','.dropdown-opener', function() { $( '.dropdown-opener' ).not(this).attr( 'aria-expanded', 'false' ); $(this).attr( 'aria-expanded', function (i, attr) { return attr == 'true' ? 'false' : 'true'; }); }); // if( jRes.getBreakpoint() === 'smartphone' ) { // // allow scroll // $( '.menu-main-container' ).height( $(window).outerHeight() - $( '#navigation-toggle' ).outerHeight() ); // } } /*-------------------------------------------- Debounce --------------------------------------------*/ (function($,sr){ // debouncing function from John Hann // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; } if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100); }; }; // smartresize jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; })(jQuery,'smartresize'); function onResize(){ // margin-top content if( ! $( '#hero' ).length ) { $( '.site-content' ).css( 'marginTop', $( '.site-header-wrap' ).outerHeight() ); } else { $( '#hero' ).css( 'marginTop', $( '.site-header-wrap' ).outerHeight() ); } if( $( '#hero' ).length ) { var width = $(window).width(); if (width > 767){ $( '#hero' ).height( $(window).height() - ($( '.site-header-wrap' ).outerHeight() * 2) ); }else if (width > 575) { $( '#hero' ).height( $(window).height() - $( '.site-header-wrap' ).outerHeight() - $('#cta_footer_mobile') .outerHeight() - 60 ); }else{ $( '#hero' ).height( $(window).height() - $( '.site-header-wrap' ).outerHeight() - $('#cta_footer_mobile') .outerHeight() - 30); } } // if( $( '.imgtext-section' ).length && jRes.getBreakpoint() !== 'smartphone' ) { // $( '.imgtext-section' ).each( function() { // $(this).find('.imgtext-section__valign').height( $(this).outerHeight() ); // }); // } // if( $( '.page__feat-bg' ).length && jRes.getBreakpoint() === 'desktop' ) { // $( '.page__feat-bg' ).height( $(window).height() - $('.site-header-container').outerHeight() ); // } // if( $( '.project__feat-bg' ).length ) { // $( '.project__feat-bg' ).height( $(window).height() - $('.site-header-container').outerHeight() ); // } // if( $( '.same-height' ).length ) { // $( '.same-height' ).matchHeight(); // } } // applico debounce al resize $(window).smartresize(function(){ onResize(); }); $(window).on( 'load', function() { onResize(); }); if ($('body.home').length) { if($(window).width() >= '992'){ autoPlayVideo = true; }else{ autoPlayVideo = false; } /*-------------------------------------------- Video --------------------------------------------*/ var videoOptions = { videoURL: $('#hero-video').data('video'), containment: '.hero', useOnMobile: true, autoPlay: true, loop: false, mute: true, showControls: false, showYTLogo: false, startAt: 0, opacity: 1, optimizeDisplay: true }; var videoBannerOptions = { videoURL: $('#banner-video').data('video'), containment: 'aside.banner', useOnMobile: true, autoPlay: true, loop: true, mute: true, showControls: false, showYTLogo: false, startAt: 0, opacity: 1 }; if($(window).width() >= '992'){ $( '#banner-video' ).YTPlayer(videoBannerOptions); } function videoInit() { $( '#hero-video' ).YTPlayer(videoOptions); $( '#hero-video' ).on( "YTPTime", function(e) { var currentTime = e.time; if (currentTime == 2) { setCookie('vid', 1, 60); $( '#hero-image' ).fadeOut( 'slow' ); } }); $( '#hero-video' ).on( "YTPEnd", function(e) { $( '#hero-image' ).fadeIn( 'slow' ); $( '#hero-video-play' ).fadeIn( 'slow' ); }); } $(document).ready(function() { $( 'body.home' ).addClass( 'video-played' ); $( '#hero-video-play' ).on('click', function(e) { e.preventDefault(); videoInit(); $( '#hero-image' ).fadeOut( 'slow' ); }); if ( ! getCookie('vid') ) { /*setTimeout(function(){ $( '#hero-video-play' ).trigger('click'); } , 2500);*/ } }); /*-------------------------------------------- Video cookie --------------------------------------------*/ function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') c = c.substring(1); if (c.indexOf(name) === 0) return c.substring(name.length, c.length); } return ""; } } /*-------------------------------------------- Sliders --------------------------------------------*/ if( $( '.slider' ).length ) { $('.slider').each(function() { var slider = $(this); var sliderOption = {}; if( $(slider).data('speed') != '') { var speed = $(slider).data('speed'); }else{ var speed = 1600; } sliderOption = { slide: '.' + slider.data('slide'), infinite: true, speed: speed, slidesToShow: 1, adaptiveHeight: false, arrows: false, }; if( slider.data('fade') ) { sliderOption.fade = true; } if( slider.data('autoplay') ) { sliderOption.autoplay = true; } slider.slick(sliderOption); }); $(document).ready(function() { $('.slider_offerte article:not([data-slick-index="0"]) .imgtext-launch__bg').each(function() { $animationOut = $(this).data('animation-out'); $(this).addClass($animationOut); }); }); if( $( '.slider__nav' ).length ) { $( '.slider__prev' ).on( 'click', function(e) { e.preventDefault(); // go to prev slide $(this).parents( '.slider' ).slick( 'slickPrev' ); }); $( '.slider__next' ).on( 'click', function(e) { e.preventDefault(); // go to next slide $(this).parents( '.slider' ).slick( 'slickNext' ); }); } $('.slider').on('afterChange', function(event, slick, currentSlide) { if( $(this).find('.slick-current .animated').length ) { $(this).find('.slick-current .animated').each(function() { $animationIn = $(this).data('animation-in'); $animationOut = $(this).data('animation-out'); $(this).removeClass($animationOut); $(this).addClass($animationIn); }); } }); $('.slider').on('beforeChange', function(event, slick, currentSlide) { if( $(this).find('.slick-current .animated').length ) { $(this).find('.slick-current .animated').each(function() { $animationIn = $(this).data('animation-in'); $animationOut = $(this).data('animation-out'); $(this).addClass($animationOut); $(this).removeClass($animationIn); }); } }); } /*-------------------------------------------- Caoursel Other item --------------------------------------------*/ if( $( '.other_post_type__carousel__container' ).length ) { var slider = $( '.other_post_type__carousel__container' ); var sliderOption = {}; sliderOption = { infinite: true, speed: 1600, slidesToShow: 3, adaptiveHeight: false, arrows: false, responsive: [ { breakpoint: 991, settings: { slidesToShow: 1, slidesToScroll: 1 } }, { breakpoint: 767, settings: { slidesToShow: 1, slidesToScroll: 1 } } ] }; if( slider.data('fade') ) { sliderOption.fade = true; } if( slider.data('autoplay') ) { sliderOption.autoplay = true; } slider.slick(sliderOption); if( $( '.other_post_type__carousel__prev' ).length ) { $( '.other_post_type__carousel__prev' ).on( 'click', function(e) { e.preventDefault(); // go to prev slide $('.other_post_type__carousel__container').slick( 'slickPrev' ); }); } if( $( '.other_post_type__carousel__next' ).length ) { $( '.other_post_type__carousel__next' ).on( 'click', function(e) { e.preventDefault(); // go to next slide $('.other_post_type__carousel__container').slick( 'slickNext' ); }); } $(window).resize(function(){ var width = $(window).width(); if (width > 767){ if ($('.other_post_type__carousel__item').length <= '2') { $( '.other_post_type__carousel__prev' ).hide(); $( '.other_post_type__carousel__next' ).hide(); }else{ $( '.other_post_type__carousel__prev' ).show(); $( '.other_post_type__carousel__next' ).show(); } }else if (width > 575) { if ($('.other_post_type__carousel__item').length <= '1') { $( '.other_post_type__carousel__prev' ).hide(); $( '.other_post_type__carousel__next' ).hide(); }else{ $( '.other_post_type__carousel__prev' ).show(); $( '.other_post_type__carousel__next' ).show(); } }else{ if ($('.other_post_type__carousel__item').length <= '3') { $( '.other_post_type__carousel__prev' ).hide(); $( '.other_post_type__carousel__next' ).hide(); }else{ $( '.other_post_type__carousel__prev' ).show(); $( '.other_post_type__carousel__next' ).show(); } } }); } /*-------------------------------------------- Masonry --------------------------------------------*/ if( $('.grid').length ) { var $grid = $('.grid').imagesLoaded( function() { $grid.isotope({ layoutMode: 'packery', itemSelector: '.grid-item', percentPosition: true, }); }); } $('.news-grid__load-more a').live('click', function(e){ e.preventDefault(); var link = $(this).attr('href'); $('.news-grid__load-more').hide(); $('.news-grid__load-more_gif').show(); $.get(link, function(data) { var post = $(".grid .grid-item ", data); $('.grid').append(post); $('.grid').imagesLoaded( function() { $('.grid').isotope( 'appended', post ); }); }); $('.news-grid__load-more').load(link+' .news-grid__load-more a'); if($('.news-grid__load-more a').attr('href') == '') { $('.news-grid__load-more a').hide(); } $('.news-grid__load-more').show(); $('.news-grid__load-more_gif').hide(); }); /*-------------------------------------------- Tappe Tour --------------------------------------------*/ if( $( '.tappe_info__content_tab' ).length ) { var slider = $( '.tappe_info__content_tab' ); var sliderOption = {}; sliderOption = { infinite: false, speed: 1600, slidesToShow: 1, adaptiveHeight: false, arrows: false, fade: true, }; if( slider.data('fade') ) { sliderOption.fade = true; } if( slider.data('autoplay') ) { sliderOption.autoplay = true; } slider.slick(sliderOption); if( $( '.other_post_type__carousel__prev' ).length ) { $( '.other_post_type__carousel__prev' ).on( 'click', function(e) { e.preventDefault(); // go to prev slide $('.other_post_type__carousel__container').slick( 'slickPrev' ); }); } if( $( '.other_post_type__carousel__next' ).length ) { $( '.other_post_type__carousel__next' ).on( 'click', function(e) { e.preventDefault(); // go to next slide $('.other_post_type__carousel__container').slick( 'slickNext' ); }); } $( '.tappe_info__menu__item' ).on( 'click', function(e) { e.preventDefault(); slider.slick('slickGoTo',$(this).data('slide')); $( '.tappe_info__menu__item' ).removeClass('active'); $(this).addClass('active'); }); } /*-------------------------------------------- Open menu booking --------------------------------------------*/ $('.booking-menu-toggle .booking__btn').click(function() { if($('.booking_menu').hasClass('open')){ $('.booking_menu').removeClass('open'); $( 'body' ).removeClass( 'menu-open' ); }else{ $('.booking_menu').addClass('open'); $( '#main-menu-toggle, #main-menu' ).attr( 'aria-expanded', 'false'); $('body').addClass('menu-open'); } }); $('.cta_footer_mobile__botton--right').click(function() { if($('.booking_menu').hasClass('open')){ $('.booking_menu').removeClass('open'); $( 'body' ).removeClass( 'menu-open' ); }else{ $('.booking_menu').addClass('open'); $( '#main-menu-toggle, #main-menu' ).attr( 'aria-expanded', 'false'); $('body').addClass('menu-open'); } }); $('a.booking-online__link').click(function(e) { e.preventDefault(); if($('.booking_menu').hasClass('open')){ $('.booking_menu').removeClass('open'); $( 'body' ).removeClass( 'menu-open' ); }else{ $('.booking_menu').addClass('open'); $( '#main-menu-toggle, #main-menu' ).attr( 'aria-expanded', 'false'); $('body').addClass('menu-open'); } }); $('.booking_menu .close').click(function(){ $('.booking_menu').removeClass('open'); $( 'body' ).removeClass( 'menu-open' ); }); $('#main-menu-toggle').click(function() { $('.booking_menu').removeClass('open'); $('body').addClass('menu-open'); }); /* sticky */ $(document).scroll(function(){ if ($(document).scrollTop() > 100) { $('.site-header-wrap').addClass('scroll'); }else { $('.site-header-wrap').removeClass('scroll'); } }); /**/ /* lang mobile */ $('a.open_menu_langs').click(function(e) { e.preventDefault(); $('.langs-switcher__item--mobile ul').toggleClass('active'); $(this).toggleClass('open'); }); /**/ /* animation hero */ /*$('.animsition').on('animsition.outEnd', function(){ if( $( '#hero' ).length ) { setTimeout(function(){ $('.hero__title').addClass('fadeInUp'); }, 100); setTimeout(function(){ $('.hero__title:after').css('opacity','1'); }, 1000); setTimeout(function(){ $('.hero__subtitle').addClass('fadeInUp'); }, 1800); } console.log( "fadein intro end" ); }); */ /**/ /* datapicker booking */ jQuery(document).ready(function(){ $( "#arrivo" ).datepicker({ dateFormat: "dd MM yy" }); $( "#partenza" ).datepicker({ dateFormat: "dd MM yy" }); $('#partenza').change(function(){ set_date_booking(); }); $('#arrivo').change(function(){ set_date_booking(); }); $('.booking_menu__widget_booking__send').click(function() { //$('#triqui').submit(); var data_checkin = $("#arrivo").datepicker( "getDate" ); data_checkin = data_checkin.getFullYear() + "-" +(data_checkin.getMonth() + 1) + "-" + data_checkin.getDate(); openbe2('marte', $('input[name="lingua"]').val(), {favroom: '&checkin='+data_checkin+'&nights='+ $('#nights').val()}); }); function set_date_booking() { if($('#partenza').val() == ''){ var result = new Date($("#arrivo").datepicker("getDate").getTime()); result.setDate(result.getDate() + 1); $('#partenza').datepicker('setDate', result); } //get data var d1=new Date($("#arrivo").datepicker("getDate").getTime()); // get date from other text field var d2=new Date($("#partenza").datepicker("getDate").getTime()); // d2 -d1 gives result in milliseconds // calculate number of days by Math.abs((d2-d1)/86400000, as 24*3600*1000 = 86400000 // and populate it to some text field #textfield var nights = Math.abs((d2-d1)/86400000); var month = ($("#arrivo").datepicker("getDate").getMonth() + 1) + ' ' + $("#arrivo").datepicker("getDate").getFullYear(); var day = $("#arrivo").datepicker("getDate").getDate(); /**/ //set data form $('#day').val(day); $('#month').val(month); $('#nights').val(nights); } }); /**/ })(jQuery);