$(document).ready(function() { var cookie = $.cookie("rcsDonnaLogin"); if (cookie != null) { $(".newsletter-btn a").attr("href","http://community.leiweb.it/user/login?destination=/account/user/profile"); $(".cerca-newsletter-invia a.newsletter").attr("href","http://community.leiweb.it/node/view/25591"); } else { $(".newsletter-btn a").attr("href","http://community.leiweb.it/user/login?destination=/account/user/profile"); $(".cerca-newsletter-invia a.newsletter").attr("href","http://community.leiweb.it/node/view/25591"); } $("span[itemprop='recipeInstructions'] p:last").css({"margin-bottom" : "20px"}); if($(".invia-ricetta form").length > 0){ if($("#testoListaIngredienti").val() != ""){ var listaIngredienti = $("#testoListaIngredienti").val().split("||"); for (var i = 0; i < listaIngredienti.length -1; i++){ var singoloIngrediente = listaIngredienti[i].replace("|", " - "); $("#lista-ingredienti").append("
  • " + singoloIngrediente + '
  • '); } } $(".invia-ricetta form ul li a").click(function(){ if($("#ingredienti").val() == ""){ return false; } else { if($("#quantita").val() != ""){ $("#lista-ingredienti").append('
  • ' + $('#ingredienti').val() + ' - ' + $('#quantita').val() + '
  • '); } else { $("#lista-ingredienti").append('
  • ' + $('#ingredienti').val() + '
  • '); } populateIngredients(); return false; } $("#ingredienti").val(""); return false; }); //forzo alcuni campi del form ad essere numerici $(".short-input, #numero-persone").keydown(function(event) { // Allow: backspace, delete, tab and escape if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || // Allow: Ctrl+A (event.keyCode == 65 && event.ctrlKey === true) || // Allow: home, end, left, right (event.keyCode >= 35 && event.keyCode <= 39)) { // let it happen, don't do anything return; } else { // Ensure that it is a number and stop the keypress if ( event.shiftKey|| (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 ) ) { event.preventDefault(); } } }); } if($("#correlati-automatici-ricetta").length > 0){ $("#correlati-automatici-ricetta li p a").each(function(){ var testo = $(this).text(); var testoTagliato = testo.substr(0, 40); $(this).text(testoTagliato + "..."); }); } /*$("#lista-ingredienti .removeIngredient").click(function(){ $(this).parent("li").remove(); populateIngredients(); });*/ }); function populateIngredients(){ $("#testoListaIngredienti").val(""); var ingrediente; $("#lista-ingredienti").append(''); $("#lista-ingredienti li").each(function(){ ingrediente = $(this).text().replace(/ - /g, "|") + "||"; $("#lista-ingredienti p").append(ingrediente); }); $("#testoListaIngredienti").val($("#lista-ingredienti p:last").text()); } function deleteIngredient(){ $("#lista-ingredienti .removeIngredient").click(function(){ $(this).parent("li").remove(); populateIngredients(); }); $(this).click(); return false; }