1(function($) { 2 'use strict'; 3 4 $(document).on('click', '.print-o-generate-pdf-button', function(e) { 5 e.preventDefault(); 6 7 const $button = $(this); 8 const originalText = $button.html(); // Store original content (could include icon) 9 const postId = $button.data('post-id'); 10 11 if (!postId) { 12 console.error('Print-o Error: Post ID not found on button.'); 13 alert('Erreur: ID du post manquant.'); 14 return; 15 } 16 17 if ($button.hasClass('print-o-generating')) { 18 return; // Already generating 19 } 20 21 // Disable button and show generating text 22 $button.prop('disabled', true); 23 // Get custom generating text from data attribute, or fall back to global, or default string 24 const customGeneratingText = $button.data('generating-text'); 25 const generatingTextToShow = customGeneratingText || (typeof print_o_data !== 'undefined' ? print_o_data.generating_text : null) || 'Generating...'; 26 $button.html(generatingTextToShow).addClass('print-o-generating'); 27 28 // Get the page language from the <html lang="..."> attribute 29 const lang = $('html').attr('lang'); 30 31 // Construct the AJAX URL for PDF generation 32 const ajaxUrl = new URL(print_o_data.ajax_url); 33 ajaxUrl.searchParams.append('action', 'print_o_generate_pdf'); 34 ajaxUrl.searchParams.append('post_id', postId); 35 ajaxUrl.searchParams.append('nonce', print_o_data.nonce); 36 if (lang) { 37 ajaxUrl.searchParams.append('lang', lang); // Add language parameter if it exists 38 } 39 40 // Redirect the browser to the generation URL 41 // The PHP script will force download the PDF 42 window.location.href = ajaxUrl.toString(); 43 44 // Re-enable the button after a short delay 45 // (download starts almost immediately, but good for UX) 46 setTimeout(function() { 47 $button.prop('disabled', false); 48 $button.html(originalText).removeClass('print-o-generating'); 49 }, 3000); // Re-enable after 3 seconds 50 51 }); 52 53 // Add Debug Content Button/Link dynamically *only if debug mode is enabled* 54 if (typeof print_o_data !== 'undefined' && print_o_data.debug_enabled) { 55 $('.print-o-generate-pdf-button').each(function() { 56 var $pdfButton = $(this); 57 var postId = $pdfButton.data('post-id'); 58 59 // Create debug button/link 60 var $debugLink = $('<a href="#" class="print-o-debug-content-link" style="margin-left: 10px; text-decoration: underline; font-size: 0.9em;">Déboguer Contenu</a>'); 61 $debugLink.data('post-id', postId); // Store post-id on the debug link as well 62 63 // Create containers for debug output (initially hidden or empty)
64 var $debugOutputContainer = $('<div class="print-o-debug-output" style="margin-top: 10px; padding: 10px; border: 1px dashed #ccc; display: none;"></div>'); 65 var $defaultContentContainer = $('<div><h4>Contenu Standard (post_content) :</h4><textarea style="width: 100%; height: 150px; font-family: monospace;" readonly></textarea></div>'); 66 var $acfContentContainer = $('<div style="margin-top: 10px;"><h4>Données Brutes ACF Repeater (section_de_la_newsletter - JSON) :</h4><textarea style="width: 100%; height: 250px; font-family: monospace;" readonly></textarea></div>'); 67 68 $debugOutputContainer.append($defaultContentContainer).append($acfContentContainer); 69 70 // Insert the debug link and output container after the PDF button 71 $pdfButton.after($debugLink); 72 $debugLink.after($debugOutputContainer); // Place output container after the debug link 73 }); 74 } // End if debug_enabled 75 76 // Handle Debug Content link click (this handler remains, but button won't exist if debug is disabled) 77 $(document).on('click', '.print-o-debug-content-link', function(e) { 78 e.preventDefault(); 79 var $debugLink = $(this); 80 var postId = $debugLink.data('post-id'); 81 var $outputContainer = $debugLink.next('.print-o-debug-output'); // Find the associated output container 82 var $defaultTextarea = $outputContainer.find('textarea').eq(0); 83 var $acfTextarea = $outputContainer.find('textarea').eq(1); // It's the second textarea now 84 85 $defaultTextarea.val('Chargement du contenu standard...'); 86 $acfTextarea.val('Chargement des données ACF...'); 87 $outputContainer.slideDown(); // Show the container 88 89 $.ajax({ 90 url: print_o_data.ajax_url, 91 type: 'GET', 92 data: { 93 action: print_o_data.debug_action, 94 post_id: postId, 95 nonce: print_o_data.debug_nonce 96 }, 97 success: function(response) { 98 if (response.success) { 99 $defaultTextarea.val(response.data.default_content); 100 $acfTextarea.val(response.data.acf_repeater_data); 101 } else { 102 var errorMessage = response.data && response.data.message ? response.data.message : 'Erreur inconnue.'; 103 $defaultTextarea.val('Erreur lors de la récupération du contenu standard: ' + errorMessage); 104 $acfTextarea.val('Erreur lors de la récupération des données ACF: ' + errorMessage); 105 } 106 }, 107 error: function(jqXHR, textStatus, errorThrown) { 108 $defaultTextarea.val('Erreur AJAX (standard): ' + textStatus + ' - ' + errorThrown); 109 $acfTextarea.val('Erreur AJAX (ACF): ' + textStatus + ' - ' + errorThrown); 110 } 111 }); 112 }); 113 114})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.