var componentVerifyCycle = 0; var bottom_of_window = jQuery(window).scrollTop() + jQuery(window).height(); var siteApp = { params : { homepage:{ images:[ '/source/index-4.jpg', '/source/index-2.jpg', '/source/index-1.jpg', '/source/index-3.jpg', '/source/index-5.jpg' ], images_mobile:[ 'https://cmsmedia.titanka.com/visithotelcervia.it/crp767x250-index-1.jpg?o=6', 'https://cmsmedia.titanka.com/visithotelcervia.it/crp767x250-index-2.jpg?o=5', 'https://cmsmedia.titanka.com/visithotelcervia.it/crp767x250-index-3.jpg?o=5', 'https://cmsmedia.titanka.com/visithotelcervia.it/crp767x250-index-5.jpg?o=5', ] }, }, init : function(){ if(siteApp.allComponentIsLoaded()){ siteApp.startApplication(); }else{ componentVerifyCycle++; if(componentVerifyCycle<200){ setTimeout(function(){siteApp.init();}, 100); }else{ console.warn('Init Application Error! waiting for: '+siteApp.params.tmp); return false; } } }, allComponentIsLoaded: function(){ var loaded = true; var msg = ''; if (typeof jQuery == 'undefined'){loaded = false; msg += '-jQuery';} if (typeof hs == 'undefined') {loaded = false; msg += '-hs';} if (typeof jQuery().slick == 'undefined') {loaded = false; msg += '-slick';} if (typeof jQuery().imageLightbox == 'undefined') {loaded = false; msg += '-imagelightbox';} if (typeof cms == 'undefined') {loaded = false; msg += 'cms';} if(!loaded){ //console.info('waiting for: '+msg); siteApp.params.tmp = msg; return false; }else{ return true; } }, startApplication: function(){ console.info('startApplication...'); startImageLightBox(); siteApp.openMenuMobile(); siteApp.openLanguage(); siteApp.openSubMenu(); siteApp.countAnimation(); siteApp.scrollAnimation(); siteApp.fadeInHeader(jQuery('.barra-desktop')); siteApp.accordionTab(); jQuery( ".blk-testo" ).wrapInner( "
"); // Initialize Background Stretcher for homepage if(cmsPageParams.type == 3){ //controllo di essere solo in homepage switch(cms.variables.deviceType) { case "phone": // jQuery('#blk_69682').backstretch(siteApp.params.homepage.images_mobile, {duration: 3300, fade: 1250}); break; default: // jQuery('#blk_69682').backstretch(siteApp.params.homepage.images, {duration: 3300, fade: 1250}); } } //aggiungo una freccia a qualunque voce abbia un sottomenu jQuery(".level1 > li:has('.level2')").addClass('submenu'); //jQuery('#button_email_min').val(''); var pathname = window.location.href; var pathname = pathname.split('&id='); var parametro = pathname[1]; if(parametro){ console.log('passo') goToByScroll('#'+parametro); } /*****************************************************/ // slider camere // jQuery('.slider-commenti').slick({ dots: false, infinite: true, speed: 800, arrows:true, slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, slide:'.blk-commenti' }); jQuery('.slider-home').slick({ dots: false, infinite: true, speed: 800, arrows:false, slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, pauseOnHover:false, fade: true, cssEase: 'linear' }); jQuery('.slider-plus').slick({ dots: false, infinite: true, speed: 800, arrows:true, slidesToShow: 3, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, responsive: [ { breakpoint: 991, settings: { slidesToShow: 2, slidesToScroll: 1 } }, { breakpoint: 767, settings: { slidesToShow: 1, slidesToScroll: 1 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1, centerMode: false } } ] }); // SLIDER OFFERTE // jQuery('.off-scorrevoli').slick({ dots: false, infinite: true, arrows: false, speed: 800, fade:false, slidesToShow: 3, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, responsive: [ { breakpoint: 1460, settings: { slidesToShow: 3 } }, { breakpoint: 991, settings: { slidesToShow: 2, slidesToScroll: 1 } }, { breakpoint: 767, settings: { slidesToShow: 1, slidesToScroll: 1 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1, centerMode: false } } ] }); /* gestione stile prezzo se non presente */ jQuery('.off-scorrevoli .condizioni').each(function(){ var html = jQuery(this).html(); var prezzo = jQuery(html).find('[itemprop=price]').html(); if(typeof prezzo=='undefined'){ jQuery(this).remove(); } }) if (window.innerWidth > 991) { // console.log('ok') jQuery('.moveUp,.moveRight,.moveDown, .moveLeft,.hideme, .image-container').viewportChecker({ classToAdd: 'visible', // Class to add to the elements when they are visible, classToAddForFullView: 'full-visible', // Class to add when an item is completely visible in the viewport repeat: false // Add the possibility to remove the class if the elements are not visible }); } /* gestione tab */ jQuery('.cont-tabs input').click(function(){ jQuery('.tab-content').hide(); var element = jQuery(this).attr('id'); //console.log(element); jQuery(this).parent('.cont-tabs').siblings(jQuery('.'+ element +'').show()) }) /************************/ console.info('startApplication started!'); }, // FUNZIONI AD HOC SITO // // FINE ESEMPIO // // Create the element openMenuMobile: function(){ /* variabili menu */ var $id_menu = '#menu_3055'; var $menu = jQuery($id_menu); var $btn = jQuery('.op_block'); /**************************/ jQuery($btn).click(function() { jQuery($id_menu +' > .level1').toggleClass('slide-menu'); //if(window.innerWidth > 991){ // jQuery('.menu-fix').fadeToggle(); //} $btn.find('.click').toggleClass('open'); $btn.toggleClass('open'); if(jQuery($id_menu+' .level2').hasClass('slide-menu')){ jQuery($id_menu+' .level2').removeClass('slide-menu') } }); /* jquery per chiudere la tendina del menu al click esterno alla tendina */ jQuery(document).bind("click touchstart", function(event){ if(jQuery(event.target).parents('.op_block').size()|(jQuery(event.target).hasClass('open'))|(jQuery(event.target).parents('ul#root_3055 li').size() ) ){ return; } // if(window.innerWidth > 991){ // jQuery('.menu-fix').fadeOut(); //} jQuery(".op_block").removeClass('open'); $btn.find('.click').removeClass('open'); if(jQuery('.level1').hasClass('slide-menu')){ jQuery(".level1").removeClass('slide-menu'); } if(jQuery(".level2").hasClass('slide-menu')){ jQuery(".level2").removeClass('slide-menu'); } }); }, // Effetto Superfish // openSubMenu: function(){ jQuery('#root_3055 ul.level2').css('margin-top','0px'); // setta la posizione verticale dei sottomenu rispetto alle voci principali jQuery('#root_3055 ul.level2').css('margin-left','0px'); // setta la posizione orizzontale dei sottomenu rispetto alle voci principali jQuery('#root_3055, .menu-fix #root_3055').superfish({ delay: 600, // the delay in milliseconds that the mouse can remain outside a submenu without it closing speed: 'normal' // fast, normal }); }, // fine effetto // /* ***************gestione tab a fisarmonica*********** */ accordionTab: function(param){ jQuery('.slider-titolo').click(function(){ if(!jQuery(this).hasClass('opened')){ jQuery('.slider-titolo.opened').removeClass('opened'); jQuery(this).addClass('opened'); jQuery('.slider-corpo.opened').slideUp('fast',function() { jQuery(this).removeClass('opened'); }) jQuery(this).next().slideDown('fast',function() { jQuery(this).addClass('opened'); }); } else{ jQuery(this).removeClass('opened'); jQuery('.slider-corpo.opened').slideUp('fast',function() { jQuery(this).removeClass('opened'); }); } }); }, /**************** tendina lingue ********************/ openLanguage: function(){ //APRO MENU LINGUE jQuery('.tendina-lingue').click(function() { var lingua = jQuery(this).next(); if( lingua.is(':hidden') ) { lingua.slideDown(); jQuery(this).children('.click').addClass('open'); }else{ lingua.slideUp(); jQuery(this).children('.click').removeClass('open'); } }); jQuery("#select_lingue").click(function() { jQuery(this).slideUp(); jQuery('.tendina-lingue').children('.click').removeClass('open') }); /* jquery per chiudere la tendina delle lingue al click esterno alla tendina */ jQuery(document).click(function(event) { if(jQuery(event.target).parents('.tendina-lingue').size()|(jQuery(event.target).hasClass('tendina-lingue'))){ return; } if(!jQuery("#select_lingue").is(':hidden')){ jQuery("#select_lingue").fadeOut(250); jQuery('.tendina-lingue').children('.click').removeClass('open') } }); }, showMe: function(elem){ anim = jQuery(elem).attr('data-anim'); jQuery(elem).addClass('animated '+anim); }, scrollAnimation: function(){ jQuery(window).on('scroll load', function(){ setTimeout(function() { if(window.innerWidth > 991){ jQuery('.hideme.visible').each( function(i){ siteApp.showMe(this); }); } }, 150); }); }, fadeInHeader: function(element){ if(window.innerWidth > 991){ jQuery(window).scroll(function(){ var scrollpos = (document.documentElement.scrollTop || document.body.scrollTop); if(scrollpos > 233){ jQuery(element).fadeIn(); } else{ jQuery(element).fadeOut(); } }); } }, countAnimation: function(){ if(window.innerWidth > 991){ jQuery(window).on('scroll', function(){ jQuery('.count').each(function () { var bottom_of_object = jQuery(this).offset().top + jQuery(this).height(); var bottom_of_window = jQuery(window).scrollTop() + jQuery(window).height(); if( bottom_of_window > bottom_of_object ){ if(!jQuery(this).hasClass('fatto')){ jQuery(this).fadeIn(); jQuery(this).prop('Counter',0).animate({ Counter: jQuery(this).text() }, { duration: 3500, easing: 'swing', step: function (now) { jQuery(this).text(Math.ceil(now)); } }); jQuery(this).addClass('fatto'); } } }); }); } }, adatta: function(elem){ var win_h = window.innerHeight; jQuery(elem).css('height',win_h); } } window.addEventListener("load", function(){siteApp.init();}); /*gestione di funzioni es. onclick="gotobyscroll('.classe')"*/ function add_slide_menu(item) { jQuery('li' + item + ' .level2').toggleClass('slide-menu'); //console.log(item) } function back_menu(item) { jQuery('li' + item + ' .level2').toggleClass('slide-menu'); //console.log('vado') } function goToByScroll(param){ jQuery('html, body').animate({scrollTop: jQuery(param).offset().top-90}, 2000, "easeInOutQuad"); }