Kuchen, Torten und Tartes

'; return content; } window.importFromRecipe = function() { var recipeData = extractRecipeData(); if (recipeData.ingredients.length > 0) { $('#ingredients').val(recipeData.ingredients.join('\n')); if (recipeData.bakeTime > 0) { $('#bake_time').val(recipeData.bakeTime); } alert('Rezeptdaten erfolgreich übernommen!'); } else { alert('Keine Rezeptdaten gefunden!'); } }; function extractRecipeData() { var ingredients = []; var bakeTime = 0; $('.wp-recipe-maker-recipe-ingredient').each(function() { var amount = $(this).find('.wp-recipe-maker-recipe-ingredient-amount').text().trim(); var unit = $(this).find('.wp-recipe-maker-recipe-ingredient-unit').text().trim(); var name = $(this).find('.wp-recipe-maker-recipe-ingredient-name').text().trim(); if (amount && name) { ingredients.push(amount + (unit ? ' ' + unit : '') + ' ' + name); } }); var instructionText = $('.wp-recipe-maker-recipe-instructions').text(); var timeMatch = instructionText.match(/(\d+)\s*(?:min|minuten|minutes)/i); if (timeMatch) { bakeTime = parseInt(timeMatch[1]); } return { ingredients: ingredients, bakeTime: bakeTime }; } $('#original_type, #target_type').change(function() { var type = $(this).attr('id').replace('_type', ''); updateDimensions(type); }); $(document).on('input', '.backform-input', function() { var id = $(this).attr('id'); if (id && (id.includes('_diameter') || id.includes('_width') || id.includes('_height') || id.includes('_depth') || id.includes('_count'))) { var type = id.split('_')[0]; calculateVolume(type); } }); updateDimensions('original'); updateDimensions('target'); checkForRecipe(); loadFromURLParams(); $('#backform_calculate').click(function() { var button = $(this); var originalText = button.text(); button.prop('disabled', true).text('Berechne...'); var data = { action: 'backform_calculate', nonce: backform_ajax.nonce, original_type: $('#original_type').val(), target_type: $('#target_type').val(), ingredients: $('#ingredients').val(), bake_time: $('#bake_time').val() || 0, unit_system: $('#unit_system').val() || 'metric' }; var originalType = $('#original_type').val(); var targetType = $('#target_type').val(); if (originalType === 'springform' || originalType === 'tortenform') { data.original_diameter = $('#original_diameter').val(); data.original_height = $('#original_height').val(); } else if (originalType === 'muffinform') { data.original_count = $('#original_count').val(); data.original_diameter = $('#original_diameter').val(); data.original_height = $('#original_height').val(); } else { data.original_width = $('#original_width').val(); data.original_depth = $('#original_depth').val(); data.original_height = $('#original_height').val(); } if (targetType === 'springform' || targetType === 'tortenform') { data.target_diameter = $('#target_diameter').val(); data.target_height = $('#target_height').val(); } else if (targetType === 'muffinform') { data.target_count = $('#target_count').val(); data.target_diameter = $('#target_diameter').val(); data.target_height = $('#target_height').val(); } else { data.target_width = $('#target_width').val(); data.target_depth = $('#target_depth').val(); data.target_height = $('#target_height').val(); } $.ajax({ url: backform_ajax.ajax_url, type: 'POST', data: data, success: function(response) { if (response.success) { $('#factor_result').html('
Faktor: ' + response.data.factor + '
'); $('#explanation_result').html('Multipliziere alle Zutatenmengen mit ' + response.data.factor + '. Bei 100g Mehl verwendest du ' + Math.round(100 * response.data.factor) + 'g.'); $('#ingredients_result').html(response.data.ingredients); $('#time_result').html(response.data.time); $('#pieces_result').html(response.data.pieces || ''); $('#volume_result').html(response.data.volume_info || ''); $('#backform_results').fadeIn(); $('html, body').animate({ scrollTop: $('#backform_results').offset().top - 20 }, 500); } else { alert('Fehler: ' + (response.data || 'Unbekannter Fehler')); } }, error: function() { alert('Ein Fehler ist aufgetreten. Bitte versuche es erneut.'); }, complete: function() { button.prop('disabled', false).text(originalText); } }); }); });}})();