var notify; var carrello_in_modifica = false; jQuery(document).ready(function () { jQuery( ".dropdown-submenu" ).click(function(event) { // stop bootstrap.js to hide the parents event.stopPropagation(); // hide the open children jQuery( this ).find(".dropdown-submenu").removeClass('open'); // add 'open' class to all parents with class 'dropdown-submenu' jQuery( this ).parents(".dropdown-submenu").addClass('open'); // this is also open (or was) jQuery( this ).toggleClass('open'); }); jQuery(".rating").change(function () { var send_data = { 'id_prodotto': jQuery(this).data('id_prodotto'), 'voto': jQuery(this).val().toString().replace(".",","), 'div_id' : 'rate-' + jQuery(this).data('id_prodotto') }; jQuery.post('/generic-page-w-submenu.html/form/votazione_post/pagina.htm?timestamp=' + Date.now(),decodeURIComponent(jQuery.param(send_data))) .success(function (post_data) { if (post_data.risultato) { jQuery.get('/generic-page-w-submenu.html/prodotti/votazione/pagina.htm?timestamp=' + Date.now(),decodeURIComponent(jQuery.param(send_data))) .success(function (data) { jQuery("#"+send_data.div_id).html(data); }); } notify.success(post_data.messaggio); }); }); jQuery.ajaxSetup({ type: 'POST', headers: { "cache-control": "no-cache" } }); jQuery(document).on( 'scroll', function(){ if (jQuery(window).scrollTop() > 100) { jQuery('.scroll-top-wrapper').addClass('show'); } else { jQuery('.scroll-top-wrapper').removeClass('show'); } }); jQuery('.scroll-top-wrapper').on('click', scrollToTop); function scrollToTop() { verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0; element = jQuery('body'); offset = element.offset(); offsetTop = offset.top; jQuery('html, body').animate({scrollTop: offsetTop}, 500, 'linear'); } jQuery.each(jQuery(".conto_alla_rovescia"), function(){ var tempo = jQuery(this).data().tempo; jQuery(this).countdown(tempo) .on('update.countdown', function(event) { if(event.strftime('%D') != '00'){ jQuery(this).html(event.strftime('%D giorni %H:%M:%S')); }else{ jQuery(this).html(event.strftime('%H:%M:%S')); } }) .on('finish.countdown', function(event) { }); }); if(typeof(elimina) != "undefined"){ for (var i = 0; i < elimina.length; ++i) { jQuery(elimina[i]).remove(); } } jQuery(".submit-change").change(function(){ jQuery(this).closest("form").submit(); }); jQuery("form.ajax input[type='submit']").click(function(e){ ajaxForm(this, e); }); jQuery("#ricerca_parole_chiave").keyup(function(e){ jQuery(this).closest("form").children("input[type='hidden']").remove(); if (e.keyCode == 13){ e.preventDefault(); jQuery(this).closest("form").submit(); } }); jQuery("select.tipo_spedizione").change(function(){ if(jQuery(this).val() == "1"){ jQuery(".spedizione_reale").hide(); }else{ jQuery(".spedizione_reale").show(); } }); notify = humane.create({ timeout:2000, baseCls: 'humane-original' }) notify.error = humane.spawn({ addnCls: 'humane-original-error', timeout: 2000 }) notify.success = humane.spawn({ addnCls: 'humane-original-success', timeout: 2000 }) jQuery("input.carrello_modifica").change(function(){ modifica_carrello(jQuery(this)); }); jQuery("a.carrello_modifica").click(function(){ if (jQuery(this).hasClass("elimina")){ var that = this bootbox.dialog({ message : "Attenzione! Vuoi procedere ?", buttons: { primary: { label: "Conferma", className: "btn btn-primary detail", callback: function() { modifica_carrello(jQuery(that)); } }, main: { label: "Annulla", className: "btn btn-default", callback: function() { } } } }); }else{ modifica_carrello(jQuery(this)); } }); jQuery("input.carrello_modifica").keypress(function(e){ if (e.keyCode == 13){ modifica_carrello(jQuery(this)); } }); jQuery(".modifica_variante").change(function(){ var id_prodotto = jQuery(this).val(); jQuery(".carrello_modifica").attr("data-id_prodotto",id_prodotto) }) jQuery.each(jQuery(".modifica_variante"), function(){ jQuery(this).trigger("change"); }); jQuery(".mostra_oggetto").click(function(){ mostra_nascondi(this); }); jQuery.each(jQuery(".mostra_oggetto:checked"), function(){ mostra_nascondi(this); }); jQuery(".overlay").click(function(){ jQuery("#overlay").show(); }) jQuery("select.paginazione").change(function () { var data = jQuery(this).children("option:selected").data(); for (attribute in data) { var input = document.getElementById(attribute); if (input != null) { input.value = data[attribute]; } } document.forms[form_ricerca].submit(); }); jQuery("a.paginazione").click(function () { var data = jQuery(this).data(); for (attribute in data) { var input = document.getElementById(attribute); if (input != null) { input.value = data[attribute]; } } document.forms[form_ricerca].submit(); }); function paginazione(pagina) { document.getElementById("pagina").value = pagina; document.forms[form_ricerca].submit(); } }); if (jQuery(".attacco").length > 0) { jQuery.each(jQuery(".attacco"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/attacchi/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".lampadina_disponibile").length > 0) { jQuery.each(jQuery(".lampadina_disponibile"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/lampadine_disponibile/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".lampadina_possibile").length > 0) { jQuery.each(jQuery(".lampadina_possibile"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/lampadine_possibile/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".ruolo").length > 0) { jQuery.each(jQuery(".ruolo"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/ruoli/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".utente_padre").length > 0) { jQuery.each(jQuery(".utente_padre"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/utenti_padre/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".nazione").length > 0) { jQuery.each(jQuery(".nazione"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/nazioni/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "Seleziona nazione", true); } }); }); } if (jQuery(".utente").length > 0) { jQuery.each(jQuery(".utente"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/utenti/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".ruolo_utente").length > 0) { jQuery.each(jQuery(".ruolo_utente"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/ruoli_utente/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".tipo_variante").length > 0) { jQuery.each(jQuery(".tipo_variante"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/tipi_variante/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".lingua").length > 0) { jQuery.each(jQuery(".lingua"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/lingue/pagina.htm", function (data) { if (data.length == 1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".categoria_articoli").length > 0) { jQuery.each(jQuery(".categoria_articoli"), function () { var attuale = jQuery(this); var parametro = attuale.data().father; jQuery.post("/generic-page-w-submenu.html/ajax/categorie_articoli/pagina.htm?id_categoria_padre="+ parametro, function (data) { if (data.length == 0) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".categoria_prodotti").length > 0) { jQuery.each(jQuery(".categoria_prodotti"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/categorie_prodotti/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".stato_ordine").length > 0) { jQuery.each(jQuery(".stato_ordine"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/stati_ordine/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".tipo_pagamento").length > 0) { jQuery.each(jQuery(".tipo_pagamento"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/tipi_pagamento/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".tipo_spedizione").length > 0) { jQuery.each(jQuery(".tipo_spedizione"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/tipi_spedizione/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", true); } }); }); } if (jQuery(".tipo_utente").length > 0) { jQuery.each(jQuery(".tipo_utente"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/tipi_utente/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".meta_descrizione_articolo").length > 0) { jQuery.each(jQuery(".meta_descrizione_articolo"), function () { var attuale = jQuery(this); var parametro = attuale.data().idCategoriaArticolo; jQuery.post("/generic-page-w-submenu.html/ajax/meta_descrizioni_articolo/pagina.htm?id_categoria_articolo="+ parametro, function (data) { if (data.length == 0) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".meta_descrizione_categoria_articolo").length > 0) { jQuery.each(jQuery(".meta_descrizione_categoria_articolo"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/meta_descrizioni_categoria_articolo/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } if (jQuery(".anchor").length > 0) { jQuery.each(jQuery(".anchor"), function () { var attuale = jQuery(this); jQuery.post("/generic-page-w-submenu.html/ajax/anchor/pagina.htm", function (data) { if (data.length == -1) { attuale.parent().hide(); } else { select_popola(attuale, data, "", false); } }); }); } jQuery(".nazione").change(function () { var valore = jQuery(this).val(); jQuery.post('/generic-page-w-submenu.html/ajax/regioni/pagina.htm?id_nazione=' + valore, function (data) { select_popola(jQuery(".regione"), data, "Seleziona regione", true); }); }); jQuery(".regione").change(function () { var valore = jQuery(this).val(); jQuery.post('/generic-page-w-submenu.html/ajax/provincie/pagina.htm?id_regione=' + valore, function (data) { select_popola(jQuery(".provincia"), data, "Selezione provincia", false); }); }); function ajaxForm(button, e) { if(e != undefined){ e.preventDefault(); } var form = jQuery(button).closest("form"); if(jQuery(form).attr("data-sendend") != "true"){ jQuery(button).replaceWith("Attendere...") jQuery(form).attr("data-sendend", "true"); return jQuery.post(form[0].action, form.serialize()).success(function (newContent) { jQuery(form).attr("data-sendend", "false"); // scrollTo(form); form.replaceWith(newContent); jQuery("form.ajax input[type='submit']").click(function (e) { ajaxForm(this, e) }) }).error(function () { // scrollTo(form); jQuery(form).attr("data-sendend", "false"); form.append(' Verifica i dati inseriti prima di procedere<\ />span>') }); } return false; } function mostra_nascondi(elemento){ var oggetto = jQuery(elemento).data().oggetto; if(jQuery(oggetto+ ":visible").length){ jQuery(oggetto).hide(); }else{ jQuery(oggetto).show(); } } function isIE(){ var ua = window.navigator.userAgent; var msie = ua.indexOf("MSIE "); var edge = ua.indexOf("Edge/"); return ( edge == 0 && msie > 0) || !!navigator.userAgent.match(/Trident.*rv\:11\./); } function select_popola(selectList, elementi, testo, trigger_conferma) { if(selectList.length > 2){ jQuery(selectList).select2("destroy"); selectList = selectList[1]; } var lista = []; if (!selectList.hasClass("no-empty")) { lista.push(""); } var selezionati = (selectList.data().select + "").split(';'); var trigger = false jQuery.each(elementi, function (key, val) { if (jQuery.inArray('' + val.id, selezionati) > -1) { lista.push(""); trigger = true; } else { lista.push(""); } }); if(selectList.length > 1){ selectList[0].remove(); selectList = jQuery(selectList[1]); } selectList.find('option').remove().end().append(lista); if (selectList.find('option').length == 2 && selectList.hasClass("forse-salta")){ selectList.val(selectList.find('option')[1].value); trigger = true; trigger_conferma = true; } if (elementi.length == 1 && elementi[0].descrizione == 'AZIONE_NASCONDIMI'){ selectList.parent().hide(); }else if(elementi.length > 1){ selectList.parent().show(); } if (trigger && trigger_conferma) { selectList.trigger("change"); } if (selectList.find('option').length > 1){ jQuery(selectList).select2(); } } function modifica_carrello(elemento) { if (!carrello_in_modifica){ carrello_in_modifica = true; jQuery(this).blur(); var data = { id_prodotto : elemento.attr('data-id_prodotto'), quantita : 0, assoluta : elemento.data('assoluta') || false } if(elemento.is("a")){ var quantita = elemento.attr('data-quantita'); if (isNaN(quantita)){ data.quantita = jQuery(quantita).val(); }else{ data.quantita = quantita; } parente = elemento.parent().parent(); }else{ data.quantita = elemento.val(); parente = elemento.parent().parent().parent(); } jQuery.post('/generic-page-w-submenu.html/carrello/modifica/pagina.htm?timestamp=' + Date.now(), decodeURIComponent(jQuery.param(data))) .success(function (data) { if (data.risultato) { jQuery.get('/generic-page-w-submenu.html/carrello/box/pagina.htm?timestamp=' + Date.now(), function (data) { jQuery("#carrello_box").html(data); }); jQuery.get('/generic-page-w-submenu.html/carrello/boxlaterale/pagina.htm?timestamp=' + Date.now(), function (data) { jQuery("#box_carrello_laterale").html(data); }) jQuery.get('/generic-page-w-submenu.html/carrello/corpo/pagina.htm?timestamp=' + Date.now(), function (data) { if(isIE()){ location.href= location.href; } jQuery("#carrello_corpo").html(data); jQuery(".carrello_modifica").unbind("click"); jQuery(".carrello_modifica").unbind("change"); jQuery(".carrello_modifica").unbind("keypress"); jQuery("input.carrello_modifica").change(function(){ modifica_carrello(jQuery(this)); }); jQuery("a.carrello_modifica").click(function(){ modifica_carrello(jQuery(this)); }); jQuery("input.carrello_modifica").keypress(function(e){ if (e.keyCode == 13){ modifica_carrello(jQuery(this)); } }); if(typeof(elimina) != "undefined"){ for (var i = 0; i < elimina.length; ++i) { jQuery(elimina[i]).remove() } } }) notify.success(data.messaggio); } else{ notify.error(data.messaggio); } carrello_in_modifica = false; }); } }