var cartUpdatesRunning = 0; function startCartUpdate() { cartUpdatesRunning++; $('#contactSendButton').prop('disabled', true); } function endCartUpdate() { cartUpdatesRunning--; if (cartUpdatesRunning < 0) { cartUpdatesRunning = 0; } if (cartUpdatesRunning === 0) { $('#contactSendButton').prop('disabled', false); } } var postQueue = $.Deferred().resolve().promise(); function queuedPost(url, data) { var result = $.Deferred(); postQueue = postQueue.then(function () { var request = $.post(url, data); request .done(function () { result.resolve.apply(result, arguments); }) .fail(function () { result.reject.apply(result, arguments); }); return request.then( function () { return $.Deferred().resolve(); }, function () { return $.Deferred().resolve(); } ); }); return result.promise(); } function onShopSuccessRecaptcha(token) { actual_form.submit(); }; // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var shop_last_width; // larghezza usata per il cambio di posizione del search_box var shop_breakpoint = 766; // sposta elementi del modulo shpp al passaggio da xs a sm e viceversa function shop_show_hide_element() { if ($(window).width() < (shop_breakpoint + 1)) shop_actual_width = shop_breakpoint; else shop_actual_width = shop_breakpoint + 1; if (shop_last_width != shop_actual_width) { shop_last_width = shop_actual_width; if (shop_last_width == shop_breakpoint) { $('#shop-category-box .title').removeClass("open"); $('#shop-category-box .list').hide(); var shop_info_img = $('.shop-info-img').detach(); $('#shop-image-box-sm').hide(); $('#shop-image-box-xs').append(shop_info_img).show(); } else { $('#shop-category-box .list').show(); var shop_info_img = $('.shop-info-img').detach(); $('#shop-image-box-xs').hide(); $('#shop-image-box-sm').append(shop_info_img).show(); } } } $(window).resize(function () { shop_show_hide_element(); }); $(document).ready(function () { const today = new Date().toISOString().split('T')[0]; /* $('#from_date').attr('min', today); $('#to_date').attr('min', new Date(Date.now() + 86400000).toISOString().split('T')[0]); function updateToDateMin() { const fromDate = new Date($('#from_date').val()); const nextDay = new Date(fromDate); nextDay.setDate(fromDate.getDate() + 1); const nextDayStr = nextDay.toISOString().split('T')[0]; $('#to_date').attr('min', nextDayStr); if ($('#to_date').val() < nextDayStr) { $('#to_date').val(nextDayStr); } updateDays(); } function updateDays() { const fromVal = $('#from_date').val(); const toVal = $('#to_date').val(); if (fromVal && toVal) { const fromDate = new Date(fromVal); const toDate = new Date(toVal); const diffTime = toDate - fromDate; const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24)); $('#number_of_days').val(diffDays); if (diffDays > 0) { startCartUpdate(); queuedPost ( 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php?module=shop&type=updatePrice', { days: diffDays, from_date: fromVal, to_date: toVal, updateDays: 1 } ) .done ( function (data) { datiJSON = JSON.parse(data); $(datiJSON.prezzo).each(function (index, element) { //console.log(index); var e = element.split('|||'); $('#calculated_price_' + e[0]).html(e[1]); $('#input_price_' + e[0]).val(e[2]); }) $('#totals').html(datiJSON.prezzoTotale_format); $('#input_totals').val(datiJSON.prezzoTotale); } ) .always(function () { endCartUpdate(); }); } } else { $('#number_of_days').val(''); } } $('#from_date').on('change', updateToDateMin); $('#to_date').on('change', updateDays); // aggiorna giorni al primo caricamento updateDays(); */ $('#from_date').attr('min', today); $('#to_date').attr('min', new Date(Date.now() + 86400000).toISOString().split('T')[0]); var previousFromDate = $('#from_date').val(); var previousToDate = $('#to_date').val(); function restorePreviousDates() { $('#from_date').val(previousFromDate); $('#to_date').val(previousToDate); } function updateToDateMin() { var fromVal = $('#from_date').val(); if (!fromVal) { updateDays(); return; } var fromDate = new Date(fromVal); var nextDay = new Date(fromDate); nextDay.setDate(fromDate.getDate() + 1); var nextDayStr = nextDay.toISOString().split('T')[0]; $('#to_date').attr('min', nextDayStr); if ($('#to_date').val() < nextDayStr) { $('#to_date').val(nextDayStr); } updateDays(); } function updateDays() { var fromVal = $('#from_date').val(); var toVal = $('#to_date').val(); if (fromVal && toVal) { var fromDate = new Date(fromVal); var toDate = new Date(toVal); var diffTime = toDate - fromDate; var diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24)); $('#number_of_days').val(diffDays); if (diffDays > 0) { startCartUpdate(); queuedPost( 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php?module=shop&type=updatePrice', { days: diffDays, from_date: fromVal, to_date: toVal, updateDays: 1 } ) .done(function (data) { try { var datiJSON = JSON.parse(data); $(datiJSON.prezzo).each(function (index, element) { var e = element.split('|||'); $('#calculated_price_' + e[0]).html(e[1]); $('#input_price_' + e[0]).val(e[2]); }); $('#totals').html(datiJSON.prezzoTotale_format); $('#input_totals').val(datiJSON.prezzoTotale); previousFromDate = fromVal; previousToDate = toVal; } catch (e) { alert($('#error_price_label').text()); restorePreviousDates(); } }) .fail(function () { alert($('#error_server_label').text()); restorePreviousDates(); }) .always(function () { endCartUpdate(); });; } } else { $('#number_of_days').val(''); } } $('#from_date').on('change', updateToDateMin); $('#to_date').on('change', updateDays); updateDays(); $('.shop_table_carriage').on('click', function (e) { var el = $(this); el.toggleClass('fa-caret-square-o-down').toggleClass('fa-caret-square-o-up'); el.next('div').toggle(); }); $('#shop-contact-modal').on('click', function (e) { $('#shop_product_popup .response_positive').detach(); $('#form_shop_contact_ajax')[0].reset(); $('#form_shop_contact_ajax').show(); $('#shop_product_popup').modal('toggle'); }); // nasconde il menu delle categorie if ($(window).width() < (shop_breakpoint + 1)) { shop_last_width = 10000; shop_show_hide_element(); // visualizza il menu delle categorie } else { shop_last_width = (shop_breakpoint + 1); shop_show_hide_element(); } $('#shop-category-box .title').on('click', function (e) { $('#shop-category-box .list').toggle("slow", "swing"); if ($(this).hasClass("open")) $(this).removeClass("open"); else $(this).addClass("open"); }); $('.qty').change( function () { $(this).data('confirm', 0); } ); var previousShippingOption = $('#shippingOption').val(); $('#shippingOption').change(function changeShipping() { var select = $(this); var currentValue = select.val(); startCartUpdate(); queuedPost( 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php?module=shop&type=changeShipping', { shippingOption: currentValue, carriage: select.find('option:selected').attr('data-value'), } ) .done(function (data) { try { var datiJSON = JSON.parse(data); if (datiJSON.return_message == 'ok') { $('#inputShippingOption').val(datiJSON.shippingOption); $('#carriage').html(datiJSON.carriage_format); $('#input_carriage').val(datiJSON.carriage); $('#totals').html(datiJSON.prezzoTotale_format); $('#input_totals').val(datiJSON.prezzoTotale); previousShippingOption = currentValue; } else { alert($('#error_carriage_label').text()); select.val(previousShippingOption); } } catch (e) { alert($('#error_carriage_label').text()); select.val(previousShippingOption); } }) .fail(function () { alert($('#error_server_label').text()); select.val(previousShippingOption); }) .always(function () { endCartUpdate(); }); }); $('.cart').click( function toCart(action) { if ($(this).data("action") == 'update') { $("#qty_" + $(this).data("id")).data('confirm', 1); } startCartUpdate(); queuedPost( 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php?module=shop&type=' + $(this).data("action"), { id: $(this).data("id"), qty: $("#qty_" + $(this).data("id")).val() } ) .done ( function (data) { datiJSON = JSON.parse(data); //console.log(datiJSON); if (datiJSON.cartTotal != null) $('#cartTotalItem').html(' x ' + datiJSON.cartTotal) else { $('#cartTotalItem').html(''); $('#listing').html('Il tuo carrello è vuoto'); } // aggiunto nuovo articolo nel carrello if (datiJSON.action == 'add') { $('#shop-alert-add').modal('show'); setTimeout(function () { $("#shop-alert-add").modal('hide') }, 5000); } // aggiornamento quantità singolo prodotto nel carrello if (datiJSON.action == 'update') { var e = datiJSON.prezzo[0].split('|||'); if ($('#qty_' + e[0]).hasClass('confirm-error')) $('#qty_' + e[0]).removeClass('confirm-error'); $('#calculated_price_' + e[0]).html(e[1]); $('#input_price_' + e[0]).val(e[2]); $('#deposit').html(datiJSON.deposit_format); $('#input_deposit').val(datiJSON.deposit); $('#carriage').html(datiJSON.carriage_format); $('#input_carriage').val(datiJSON.carriage); $('#totals').html(datiJSON.prezzoTotale_format); $('#input_totals').val(datiJSON.prezzoTotale); $('#cartTotalItemInput').val(datiJSON.totalQty); } // rimozione singolo prodotto dal carrello if (datiJSON.action == 'remove') { var removingLines = true; $.each(datiJSON.prodotti, function (index, value) { if (index == datiJSON.id) removingLines = false; }); $('#deposit').html(datiJSON.deposit_format); $('#input_deposit').val(datiJSON.deposit); $('#carriage').html(datiJSON.carriage_format); $('#input_carriage').val(datiJSON.carriage); $('#totals').html(datiJSON.prezzoTotale_format); $('#input_totals').val(datiJSON.prezzoTotale); $('#cartTotalItemInput').val(datiJSON.totalQty); $('#shippingOption option[data-value]').addClass('noshow'); $('#shippingOption option[data-value=0]').removeClass('noshow'); $.each(datiJSON.carriageValid, function (index, value) { $('#shippingOption option[data-value=' + value + ']').removeClass('noshow'); }); if (removingLines) { $('#row-shop-' + datiJSON.id).hide('slow'); setTimeout(function () { $('#row-shop-' + datiJSON.id).remove(); }, 1000); } if (datiJSON.cartTotal == null) { $('.shop_cart_hide').hide('slow'); setTimeout(function () { $('.shop_cart_show').show(); }, 1000); } } // rimozione intero carrello if (datiJSON.action == 'removeAll') { $('.shop_cart_hide').hide('slow'); $('.shop_cart_show').show(); setTimeout(function () { $('.shop_cart_show').show(); }, 1000); } } ) .fail( function (data) { $('#shop-alert-ajax .modal-title .title').html('Avviso'); $('#shop-alert-ajax .modal-body p').html('Operazione non riuscita. Riprovare più tardi!'); $('#shop-alert-ajax').modal('show'); setTimeout(function () { $("#shop-alert").modal('hide') }, 5000); } ) .always(function () { endCartUpdate(); }); }) }); // funzioni CALLBACK per il carrello // esito positivo function shop_cart_positive_response(element, datiJSON, value_class_hide) { queuedPost( 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php?module=shop&type=removeAll' ) $(element.content).hide(); $(element.content).after('
' + datiJSON.positive_response + '
'); if (value_class_hide !== undefined) $('.' + value_class_hide).hide(); } // esito negativo function shop_cart_error_code(element, datiJSON, value_class_hide) { $('#upload_container_' + element.content.id).hide(); $('#shop-alert-ajax .modal-title .title').html('Avviso'); $('#shop-alert-ajax .modal-body p').html('Ordine non registrato con successo!'); $('#shop-alert-ajax').modal('show'); setTimeout(function () { $("#shop-alert").modal('hide') }, 5000); } // errore chiamata AJAX function shop_cart_failure(element, datiJSON, value_class_hide) { $('#upload_container_' + element.content.id).hide(); $('#shop-alert-ajax .modal-title .title').html('Avviso'); $('#shop-alert-ajax .modal-body p').html('Operazione non riuscita. Riprovare più tardi!'); $('#shop-alert-ajax').modal('show'); setTimeout(function () { $("#shop-alert").modal('hide') }, 5000); } // funzione di controllo function shop_cart_check(element) { var error = false; // controllo che le select delle quantità dei prodotti siano state tutte confermate, altrimenti eseguo il focus sulla prima quantità non confermata $('.qty').each( function () { if (!($(this).data('confirm'))) { // debbo settare la classe per l'errore e spostare lo scroll $(this).addClass('confirm-error'); var firstQty = ($(this).offset().top); var body = $("html, body"); body.stop().animate({ scrollTop: firstQty }, '500', 'swing'); error = true; return false; } }); return error; } // funzioni CALLBACK per il contatti del prodotto // esito positivo function shop_product_modal_positive_response(element, datiJSON, value_class_hide) { $(element.content).hide(); $(element.content).after('
' + datiJSON.positive_response + '
'); if (value_class_hide !== undefined) $('.' + value_class_hide).hide(); } // funzioni CALLBACK per il contatti del prodotto // esito positivo function shop_product_positive_response(element, datiJSON, value_class_hide) { $('#form_shop_contact_ajax')[0].reset(); $('#popup_positive_result .response_positive').html(datiJSON.positive_response); $('#popup_positive_result').modal('show'); setTimeout(function () { $("#popup_positive_result").modal('hide') }, 5000); if (value_class_hide !== undefined) $('.' + value_class_hide).hide(); } 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 ""; } // lunghezza calcolata al caricamento della pagina e ad ogni resize della schermata var lastWidth; // larghezza usata per il cambio di posizione del search_box var width_change_search_box_position = 766; // sposta il box della ricerca prima del corpo principale con risoluzione tablet e smartphone // di lato in modalit� desktop function search_box_position() { if ($(window).width() < (width_change_search_box_position + 1)) actualWidth = width_change_search_box_position; else actualWidth = width_change_search_box_position + 1; if (lastWidth != actualWidth) { lastWidth = actualWidth; if (lastWidth == width_change_search_box_position) { var search_box = $('#search-box').detach(); $('#search-box-2').append(search_box).hide(); } else { var search_box = $('#search-box').detach(); $('#search-box-1').append(search_box); } } } /** ESEMPIO PER UTILIZZO SLIDE // ID della slide $( "#slide-example" ).slide_carousel({}); element : '.example-item', // elemento contenuto nel carousel breakpoint : [ // numero di elementi e righe in base alla risoluzione // >risoluzione minima // | numero di items // | | numero di righe // | | | [ 1199, 4, 1], [ 768, 2, 1], [ 0, 1, 1] ] }); ***/ // slide $( "#slide" ).slide_carousel({element : '.slide-item', breakpoint : [[ 0, 1, 1]]}); $( "#slide-shop-category-box" ).slide_carousel({ element : '.slide-shop-category-item', breakpoint : [ [ 767, 14, 2], [ 480, 4, 1], [ 0, 2, 1] ] }); /** ESEMPIO PER L'UTILIZZO DELLE IMMAGINI ADATTATIVE // indicare la classe delle immagini $( ".img-adapter-4-3" ).imgadapter({ w_prop : 4, // proporzione per la lunghezza h_prop : 3, // proporzione per l'altezza outer_div : true, // true: non � richiusa all'interno del wrapper, false � rinchiusa all'interno del wrapper breakpoint : [ // risoluzioni in cui ricalcolare il rapporto // >min-width [ 1400], [ 1200], [ 768], [ 480], [ 0] ] }); ***/ // immagini adattative all'interno del riquadro $( ".img-adapter-in-4-3" ).imgadapter({ w_prop : 4, h_prop : 3, outer_div : false }); $( ".img-adapter-in-1-1" ).imgadapter({ w_prop : 4, h_prop : 3, outer_div : false }); // immagini adattative all'esterno del riquadro $( ".img-adapter-16-9" ).imgadapter({ w_prop : 16, h_prop : 9, outer_div : false }); $( ".img-adapter-4-3" ).imgadapter({ w_prop : 4, h_prop : 3, outer_div : false }); $( ".img-adapter-1-1" ).imgadapter(); /** ESEMPIO PER L'UTILIZZO DELLA GALLERY // indicare la gallery $( ".simple-gallery" ).gallery({ w_prop : 4, // proporzione per la lunghezza h_prop : 3, // proporzione per l'altezza breakpoint : [ // percentuali da applicare in base alla larghezza minima della pagina // >min-width // | width % // | | margin px // | | | [ 768, 33, 15], [ 480, 50, 15], [ 0, 100, 15] ] }); **/ // margine applicato 15px $( ".simple-gallery" ).gallery({ w_prop : 1, h_prop : 1, outer_div : false, breakpoint : [ // >min-width width % margin px [ 768, 33, 15], [ 480, 50, 15], [ 0, 100, 15] ] }); $(window).resize(function() { search_box_position(); }); // funzione di successo per il recaptcha di Google var actual_form = null; function onSuccessRecaptcha(token) { actual_form.submit(); } var clmrecaptchaID = []; var clmrecaptchaFunc = []; var onloadCallback = function() { $('.btn-submit').each(function( index ) { recaptcha_form = $(this).closest("form"); $(this).before('
') }); $('.clm-recaptcha').each(function( index ) { recaptcha_form = $(this).closest("form"); // recupera la callback success per il recaptcha di google del form, // se non esiste mette quella di default if (recaptcha_form.data('gcallback') === undefined) gcallback = onSuccessRecaptcha; else gcallback = window[recaptcha_form.data('gcallback')]; // render il recaptcha clmrecaptchaID[index] = this.id; clmrecaptchaFunc[index] = grecaptcha.render(this.id, { 'sitekey' : '6LdIcRgUAAAAAPqxP2-P1h1HaFM2hVJvcGWHO0hs', 'callback' : gcallback, 'size' : 'invisible' }); }); }; $( document ).ready(function() { var policyCookie = getCookie('policyCookie'); if ((policyCookie == "") || (policyCookie == 0)) { $('#cookie_third').hide(); } // visualizza il box di ricerca nel punto corretto if ($(window).width() < (width_change_search_box_position + 1)) { lastWidth = 10000; search_box_position(); } else { lastWidth = (width_change_search_box_position + 1); } $('#search-xs').on('click', function (e) { $('#search-box-2').toggle("slow"); }); // 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) { var error = false; actual_form = $(this).closest("form"); // recupera la classe da applicare in caso di successo var func_check = actual_form.data('check'); if (func_check !== undefined) { var fn = window[func_check]; if (typeof fn === "function") error = fn.apply(null, [this]); } if ( error ) // esco da on click return false; // ricerca il recaptcha del form cmlrecaptcha = actual_form.find('.clm-recaptcha'); cmlrecaptcha_id = -1; for (var i = 0; i < clmrecaptchaID.length; i++) { if (clmrecaptchaID[i] == cmlrecaptcha[0].id) cmlrecaptcha_id = i; } if (typeof actual_form[0].checkValidity != 'undefined' && !actual_form[0].checkValidity()) { } else { e.preventDefault(); // esegue il recaptcha se esiste per il form altrimenti richiama la funzione di successo if (cmlrecaptcha_id != -1) { grecaptcha.reset(clmrecaptchaFunc[cmlrecaptcha_id]); grecaptcha.execute(clmrecaptchaFunc[cmlrecaptcha_id]); } else { if (actual_form.data('gcallback') === undefined) gcallback = onSuccessRecaptcha; else gcallback = window[actual_form.data('gcallback')]; gcallback(); } } }); /*EFFECT MENU*/ document.querySelector(".hamburguer").addEventListener("click", function() { document.querySelector(".full-menu").classList.toggle("active"); document.querySelector(".hamburguer").classList.toggle("close-hamburguer"); }); $('[data-toggle="tooltip"]').tooltip(); $( ".table" ).wrap( "
" ); $('.carousel').carousel(); $('.modal').modal('hide'); $('.dropdown-submenu a').click(function(){ if ($(this).next().hasClass('dropdown-menu')) { $('.dropdown-submenu > .dropdown-menu').css('display','block'); return false; } }); //One Animated var is_iOS = ( /iPhone|iPad|iPod/i.test(navigator.userAgent) ); // le animazioni waypoint laterali estendono la pagina causando problemi di visualizzazione nei sistemi operativi IOS // le animazioni waypoint disabilitate if(is_iOS) { $('.animated').css("opacity", "1"); } else { $('.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.gardaservice4u.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.gardaservice4u.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.gardaservice4u.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(); if (cartUpdatesRunning > 0) { alert('Attendi il completamento del calcolo del preventivo.'); return false; } $('#alert-code-'+this.id).remove(); $('#upload_container_'+this.id).show(); // recupera le classi da nascondere var class_hide = $(this).find( 'input[name=class_hide]' ); var value_class_hide = class_hide.val(); // recupera la classe da applicare in caso di errore var func_error_code = $(this).data('error_code'); // recupera la classe da applicare in caso di successo var func_positive_response = $(this).data('positive_response'); // recupera la classe da applicare in caso di failure var func_fail = $(this).data('fail'); //grab all form data var formData1 = new FormData(); $(this).find( ':input' ).each( function( index, el ) { switch (el.name) { case "submit": case "code": case "type": case "lang": case "lang_id": case "from": case "module": case "em": case "class_hide": case "g-recaptcha-response": formData1.append(el.name, el.value); break; default: field = $(el); tagName = field.prop("tagName").toLowerCase(); appendField = true; if (field.attr('type') != "file") { lbl_client = lbl_admin = order = required = type = 'undefined'; lbl_client = field.data('label'); if (typeof lbl_client === 'undefined') lbl_client = el.name; lbl_admin = field.data('admin'); if (typeof lbl_admin === 'undefined') lbl_admin = lbl_client; order = field.data('order'); if (typeof order === 'undefined') order = -1; required = field.attr('required'); if (typeof required === 'undefined') required = 0; else required = 1; type = field.attr('type'); if (typeof type === 'undefined') type = ""; if (tagName == "select") { option = field.find(":selected"); val_client = option.data('label'); if (typeof val_client === 'undefined') val_client = option.val(); val_admin = option.data('admin'); if (typeof val_admin === 'undefined') val_admin = val_client; } else if ((type == "radio") || (type == "checkbox")) { checked = field[0].checked; if (checked == false) appendField = false; else { val_client = el.value; val_admin = val_client; } } else { val_client = el.value; val_admin = val_client; } if (appendField) { value = val_client+"|||"+val_admin+"|||"+lbl_client+"|||"+lbl_admin+"|||"+order+"|||"+required+"|||"+type; formData1.append(el.name, value); } } else { formData1.append(el.name, field[0].files[0]); } } } ); $.ajax({ type: "POST", url: 'https://www.gardaservice4u.it/admin/includes/ajax/ajax_frontend.php', content: this, data: formData1, // 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')) { if (func_error_code === undefined) { $( this.content ).before('

    '+datiJSON.error_code+'

    '); $( "#alert-code-"+this.content.id )[0].scrollIntoView(); } else { var fn = window[func_error_code]; if (typeof fn === "function") fn.apply(null, [this, datiJSON, value_class_hide]); } } // 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')) { if (func_positive_response === undefined) { // 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(); if (value_class_hide !== undefined) $('.'+value_class_hide).hide(); } else { var fn = window[func_positive_response]; if (typeof fn === "function") fn.apply(null, [this, datiJSON, value_class_hide]); } } }) .fail(function(data) { if (func_fail === undefined) { $('#upload_container_'+this.content.id).hide(); $( this.content ).before('

    Errore nell\'invio. Riprovare pi� tardi

    '); } else { var fn = window[func_fail]; if (typeof fn === "function") fn.apply(null, [this, data, value_class_hide]); } }); });