function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie.replace(/\+/g, ' ')); var ca = decodedCookie.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 ""; } $(window).load(function() { var policyCookie = getCookie('policyCookie'); if (policyCookie == "0") { $('#cookie_third').hide(); } if (policyCookie == "") { $('.cookie-btn-erase').hide(); } if($("#modalHome").length > 0) { setTimeout(function() { $("#modalHome").modal("show"); }, 500); } }) var $slides = $( "#slide" ).resCarousel({element : '.slide-item', numElement : [[ 0, 1]]}); //var $slide_offers = $( "#slide-offers" ).resCarousel({element : '.offers-item'}); // margine applicato 15px var $gallery = $( ".simple-gallery" ).gallery({ w_prop : 4, h_prop : 3, percWidth : [ // >min-width width % margin px [ 991, 25, 15], [ 768, 33, 15], [ 480, 50, 15], [ 0, 100, 15] ] }); var $img_adapter_16_9 = $( ".img-adapter-16-9" ).imgadapter({w_prop : 16,h_prop : 9}); var $img_adapter_4_3 = $( ".img-adapter-4-3" ).imgadapter({w_prop : 4,h_prop : 3}); var $img_adapter_3_5 = $( ".img-adapter-3-5" ).imgadapter({w_prop : 3,h_prop : 5}); var $img_adapter_1_1 = $( ".img-adapter-1-1" ).imgadapter(); var h_window = $( window ).height(); $(window).resize(function() { $slides.update(); //$slide_offers.update(); $gallery.update(); $img_adapter_16_9.update(); $img_adapter_4_3.update(); $img_adapter_3_5.update(); $img_adapter_1_1.update(); h1 = $( window ).height(); if (h_window != h1) { h_window = h1; $('.wrapper-flexslider').height(h_window); } }); $(window).load(function(){ $('.flexslider').flexslider({ animation: "fade", start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide before: function(){captionMoveOut();}, //Callback: function(slider) - Fires asynchronously with each slider animation after: function(){captionMoveIn();}, //Callback: function(slider) - Fires after each slider animation completes end: function(){}, //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous) added: function(){}, //{NEW} Callback: function(slider) - Fires after a slide is added removed: function(){} }); $('.flex-caption').hide(); $('.flex-caption').fadeIn(2000); }); function captionMoveIn() { $('.flex-caption') .show() .animate({opacity: 1.0},2000) }; function captionMoveOut() { $('.flex-caption') .hide() .animate({opacity: 0.0},0) .fadeOut("normal"); }; function boxRemoveHeight() { $('.box').css("height", "0"); } // funzione di successo per il recaptcha di Google var actual_form = null; function onSuccessRecaptcha(token) { actual_form.submit(); } // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var actualWidth; $( document ).ready(function() { // pulsante di conferma del form // memorizza il form dell'elemento (utilizzato alla conferma del recaptcha) // effettua la validation HTML5 // se andato a buon fine $('.btn-submit').on('click', function (e) { actual_form = $(this).closest("form"); if (typeof actual_form[0].checkValidity != 'undefined' && !actual_form[0].checkValidity()) { grecaptcha.reset(); } else { e.preventDefault(); grecaptcha.execute(); } }); $('[data-toggle="tooltip"]').tooltip(); $( ".table" ).wrap( "
" ); $('.carousel').carousel(); $('.modal').modal('hide'); if ($('#banner_popup').length > 0) $('#banner_popup').modal('show'); $('.dropdown-submenu a').click(function(){ if ($(this).next().hasClass('dropdown-menu')) { $('.dropdown-submenu > .dropdown-menu').css('display','block'); return false; } }); $( "#index #menu_home" ).click(function() { var x = $("main").offset().top - $("#top_content").outerHeight(true); $('html, body').animate({scrollTop: x}, 1000); }); $('.wrapper-flexslider').height(h_window); $( "#toggle-nav" ).click(function() { if ($("#toggle-nav").is(':checked')) { $('.box').css("height", "calc(100% - 54px)"); $('.top').addClass('fixed toggle'); $('.logo-grande').addClass('fixed'); } else { $('.top').removeClass('toggle'); if ($( ".top" ).hasClass( "wrapper" ) == false) { $('.top').removeClass('fixed'); $('.logo-grande').removeClass('fixed'); } window.setTimeout(boxRemoveHeight, 600); } }); $('.btn-text-show').click(function () { var textHide = $(this).data('text'); $('.'+textHide).slideToggle(700, "linear"); $(this).hide(); }); var waypoints = $('.wrapper-flexslider').waypoint(function(direction) { if( direction === 'down' ) { $('.top').addClass('fixed wrapper'); $('.logo-grande').addClass('fixed'); } else if( direction === 'up'){ $('.top').removeClass('wrapper'); if ($( ".top" ).hasClass( "toggle" ) == false) { $('.top').removeClass('fixed'); $('.logo-grande').removeClass('fixed'); } } }, { offset: -$('.top').outerHeight() }); var waypoints = $('#slide').waypoint(function(direction) { if( direction === 'down' ) { $('.top').addClass('fixed wrapper'); $('.logo-grande').addClass('fixed'); } else if( direction === 'up'){ $('.top').removeClass('wrapper'); if ($( ".top" ).hasClass( "toggle" ) == false) { $('.top').removeClass('fixed'); $('.logo-grande').removeClass('fixed'); } } }, { offset: -$('.top').outerHeight() }); //One Animated $('.animated').waypoint(function() { var myAnimated = $(this).data('animated'); var oneSomeAnimated = $(this).data('oneanimated'); // animazione da eseguire una singola volta if (oneSomeAnimated == true) { // animazione non e' stata gia' eseguita in tal caso la esegue if (!($(this).hasClass(myAnimated))) $(this).toggleClass($(this).data('animated')).css("opacity", "1"); // animazione da eseguire sempre } else $(this).toggleClass($(this).data('animated')); }, { offset: '80%' }); // Effect input $(document).on("blur", 'form input, form textarea', function(){ if($(this).val().length !== 0) { $(this).addClass('filled'); } else { $(this).removeClass('filled'); } }); // Effect input $(document).on("blur", 'form input, form textarea, form select', function(){ if($(this).val().length !== 0) { $(this).addClass('filled'); } else { $(this).removeClass('filled'); } }); // visualizza il form per contattare l'autore $("#users-contact").on('click', function(event) { $( '#form_users_ajax' ).toggle(); }); function updateFileList() { var filesToUpload = $(' #filesToUpload ') var fileList = $(' #fileList ').html(''); fileList.html(''); if (filesToUpload[0].files.length == 0) { fileList.append('
  • Nessun file selezionato
  • '); } else { for (var i = 0; i < filesToUpload[0].files.length; i++) fileList.append('
  • ' + filesToUpload[0].files[i].name + '
  • '); } } function errorFileList(msg) { var fileList = $(' #fileList ').html(''); fileList.html(''); fileList.append('
  • ' + msg + '
  • '); } // carica l'immagine $("#filesToUpload").on('change', function(event) { var file = event.target.files[0]; if(file.size>=2*1024*1024) { $(this).val(''); errorFileList('ERRORE: GRANDEZZA DEL FILE'); return; } var matchAccepter = $( this ).attr('accept').split(','); var accept_ok = false; for (i=0; i < matchAccepter.length; i++) { if (file.type.match(matchAccepter[i])) accept_ok = true; } if (!accept_ok) { $(this).val(''); errorFileList('ERRORE: FORMATO NON VALIDO'); return; } $( this ).attr('mime', file.type); if ( window.FileReader && window.File && window.FileList && window.Blob ) { var fileReader = new FileReader(); fileReader.onload = function(e) { var filesToUpload = $("#filesToUpload"); var int32View = new Uint8Array(e.target.result); // verify the magic number var magicNumber = new Array(); // https://www.sitepoint.com/web-foundations/mime-types-complete-list/ // https://en.wikipedia.org/wiki/List_of_file_signatures magicNumber['image/png'] = new Array(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A); magicNumber['image/jpeg'] = new Array(0xFF, 0xD8, 0xFF); magicNumber['image/pjpeg'] = new Array(0xFF, 0xD8, 0xFF); var mimeType = filesToUpload.attr('mime'); filesToUpload.removeAttr('mime'); var magic_number_ok = true; lenght_mn = magicNumber[mimeType].length; if (int32View.length > lenght_mn) { for (i=0; i < lenght_mn; i++) { if (int32View[i] != magicNumber[mimeType][i]) magic_number_ok = false; } } else magic_number_ok = false; if (magic_number_ok) { updateFileList(); } else { filesToUpload.val(''); errorFileList('ERRORE: FORMATO NON VALIDO'); } }; fileReader.readAsArrayBuffer(file); } else { updateFileList(); } }); }); $('.input-search').keyup(function() { var value = $(this).val().toLowerCase(); var container = $(this).attr("for"); if (value == "") { $('#'+container+' .panel-search').hide(); $('#'+container+' .panel-search').each(function( index ) { if (index < 12) { $( this ).show(); } else return; }); } else { var li_search = $('#'+container+' .panel-search[data-search*="'+value+'"]'); $('#'+container+' .panel-search').hide(); li_search.each(function( index ) { if (index < 12) { $( this ).show(); } else return; }); } }); // Inizializza l'effetto input function init_form(form_id) { $.each($('input, textarea, select', '#'+form_id),function(e){ if($(this).val().length !== 0) { $(this).addClass('filled'); } else { $(this).removeClass('filled'); } }) } /****************************************************/ /* REGISTRAZIONE */ /****************************************************/ /*FUNZIONI PER REGIONI, PROVINCE E COMUNI*/ function load_zone_province(region_id, province_target, city_funcall, city_target, class1, required){ $.ajax({ type: "POST", url: "https://www.latiummorini.it/admin/includes/ajax/ajax_frontend.php", data: "type=zone_province&class=" + class1 + "&city_funcall=" + city_funcall + "&city_target=" + city_target + "&required=" + required + "&id=" + region_id, success: function(html){ $("#" + province_target).html(html); } }); } function load_zone_city(province_id, city_target, class1, required){ $.ajax({ type: "POST", url: "https://www.latiummorini.it/admin/includes/ajax/ajax_frontend.php", data: "type=zone_city&class=" + class1 + "&required=" + required + "&id=" + province_id, success: function(html){ $("#" + city_target).html(html); } }); } /****************************************************/ /* LOGIN / LOGOUT */ /****************************************************/ $( '#logout' ).click(function() { $.ajax({ type: "POST", url: 'https://www.latiummorini.it/admin/includes/ajax/ajax_frontend.php', data: { type: "logout" }, context: this, dataType: 'text' }) .done(function(data){ location.reload(); }); }); /****************************************************/ /* COMMENTI */ /****************************************************/ /* GESTIONE REPLY COMMENTI */ $( '.a_reply' ).click(function() { parent = parseInt($( this ).attr('parent')); $('#reply_comment input[name="parent"]').val(parent); $('#reply_comment form')[0].reset(); $('#reply_comment .response_positive').hide(); $('#reply_comment form').show(); title = $('#comment_title_'+parent).html(); $('#reply_comment input[name="title"]').val('RE: '+title); $('#reply_comment input[name="rate"]').val(''); $('#reply_comment').find('.star').removeClass('fa-star-chosen').removeClass('fa-star-current').removeClass('fa-star').addClass('fa-star-o'); init_form($('#reply_comment form').attr("id")); $('#reply_comment').modal('show'); }); /* GESTIONE RATE */ function setRateChosen(current) { current.addClass('fa-star-chosen').addClass('fa-star-current').addClass('fa-star').removeClass('fa-star-o'); current.prevAll('.star').addClass("fa-star-chosen").addClass('fa-star').removeClass('fa-star-o'); current.nextAll('.star').addClass('fa-star-o').removeClass('fa-star'); current.parent().prev('#rate').val($current.attr("value")); } $(".box-rate").hover(function(){ $(this).find('.star').removeClass('fa-star-chosen'); }, function(){ $current = $(this).find('.fa-star-current'); setRateChosen($current); /* $current.addClass('fa-star-chosen').addClass('fa-star-current').addClass('fa-star').removeClass('fa-star-o'); $current.prevAll('.star').addClass("fa-star-chosen").addClass('fa-star').removeClass('fa-star-o'); $current.nextAll('.star').addClass('fa-star-o').removeClass('fa-star'); $current.parent().prev('#rate').val($current.attr("value")); */ }); $(".star").hover(function(){ $(this).parent().find('.star').removeClass('fa-star-chosen'); $(this).addClass('fa-star').removeClass('fa-star-o'); $(this).prevAll('.star').addClass('fa-star').removeClass('fa-star-o'); }, function(){ $(this).removeClass('fa-star').addClass('fa-star-o'); $(this).prevAll('.star').removeClass('fa-star').addClass('fa-star-o'); }); $('.star').click(function(e) { $(this).parent().find('.fa-star-current').removeClass('fa-star-current'); $current = $(this); setRateChosen($current); /* $current.addClass('fa-star-chosen').addClass('fa-star-current').addClass('fa-star').removeClass('fa-star-o'); $current.prevAll('.star').addClass("fa-star-chosen").addClass('fa-star').removeClass('fa-star-o'); $current.nextAll('.star').addClass('fa-star-o').removeClass('fa-star'); $current.parent().prev('#rate').val($current.attr("value")); */ }); /****************************************************/ /* GESTIONE AJAX DEI FORM */ /* - REGISTRAZIONE */ /* - NEWSLETTER */ /* - LOGIN */ /* - COMMENTI */ /****************************************************/ /* GESTIONE AJAX DEI FORM */ $( '.form_ajax' ).each(function( index ) { $( this ).before(''); init_form(this.id); }); $( '.form_ajax' ).on('submit', function (e) { e.preventDefault(); $('#alert-code-'+this.id).remove(); $('#upload_container_'+this.id).show(); //grab all form data var formData = new FormData($(this)[0]); $.ajax({ type: "POST", url: 'https://www.latiummorini.it/admin/includes/ajax/ajax_frontend.php', content: this, data: formData, // Data sent to server, a set of key/value pairs (i.e. form fields and values) contentType: false, // The content type used when sending data to the server. cache: false, // To unable request pages to be cached processData:false // To send DOMDocument or non processed data file it is set to false }) .done(function(data){ $('#upload_container_'+this.content.id).hide(); datiJSON = JSON.parse(data); // errore if (datiJSON.hasOwnProperty('error_code')) { $( this.content ).before('

    '+datiJSON.error_code+'

    '); $( "#alert-code-"+this.content.id )[0].scrollIntoView(); } // azione non legato a risposta positiva if (datiJSON.hasOwnProperty('action')) { switch (datiJSON.action) { case 'refresh': location.reload(); break; } } // risposta positiva if (datiJSON.hasOwnProperty('positive_response')) { // action legata a risposta positiva if (datiJSON.hasOwnProperty('action')) { switch (datiJSON.action) { case 'popup': $('#popup_result .response_positive').html(datiJSON.positive_response); $('#popup_result').modal('show'); $( this.content ).find('.star').removeClass('fa-star-chosen').removeClass('fa-star-current').removeClass('fa-star').addClass('fa-star-o'); $( this.content )[0].reset(); return; } } $( this.content ).after('
    '+datiJSON.positive_response+'
    '); $( this.content ).detach(); } }) .fail(function(data) { $('#upload_container_'+this.content.id).hide(); $( this.content ).before('

    Errore nell\'invio. Riprovare pił tardi

    '); }); });