jQuery(document).ready(function($) { // Check if our tool application exists on the page const toolApp = $('#pdf-tool-app'); if (toolApp.length === 0) { return; // Exit if the tool is not found } // --- ELEMENT SELECTORS --- const toolType = toolApp.data('tool-type'); const uploadForm = $('#pdf-upload-form'); const fileInput = $('#pdf-file-input'); const steps = { upload: $('#upload-step'), options: $('#options-step'), processing: $('#processing-step'), result: $('#result-step'), }; let selectedFile = null; // --- CORE FUNCTIONS --- // Function to switch between views function showStep(stepName) { Object.values(steps).forEach(step => step.hide()); steps[stepName].show(); } // Function to set up the options view after a file is selected function setupOptionsView() { if (!selectedFile) return; let optionsHtml = `

${selectedFile.name} (${(selectedFile.size / 1024 / 1024).toFixed(2)} MB)

`; let submitButtonText = 'Start'; // Generate options based on the tool type switch (toolType) { case 'compress': optionsHtml += '

Ready to compress your PDF. Click the button to begin.

'; submitButtonText = 'Compress PDF'; break; case 'split': optionsHtml += `
`; submitButtonText = 'Split PDF'; break; // Add more cases here for 'pdf-to-word', 'add-watermark', etc. } optionsHtml += ``; steps.options.html(optionsHtml); showStep('options'); } // Function to set up the result view function setupResultView(isSuccess, data) { let resultHtml = ''; if (isSuccess) { resultHtml = `

Success!

Your file is ready to be downloaded.

Download File `; } else { resultHtml = `

Oops, something went wrong.

${data}

`; } resultHtml += `

`; steps.result.html(resultHtml); showStep('result'); } // --- EVENT LISTENERS --- // Trigger file selection when the label is clicked $('.upload-area .button-primary').on('click', function() { fileInput.click(); }); // Handle file selection fileInput.on('change', function() { if (this.files.length > 0) { selectedFile = this.files[0]; setupOptionsView(); } }); // Handle form submission via AJAX uploadForm.on('submit', function(e) { e.preventDefault(); showStep('processing'); // Show loading animation immediately const formData = new FormData(); formData.append('pdf_file', selectedFile); // This makes sure we get the values from the dynamic options form const optionsData = new FormData(this); for(let pair of optionsData.entries()) { formData.append(pair[0], pair[1]); } const ajaxAction = toolType.replace(/-/g, '_'); formData.append('action', ajaxAction); formData.append('nonce', pdf_press_ajax.nonce); $.ajax({ url: pdf_press_ajax.ajax_url, type: 'POST', data: formData, processData: false, contentType: false, success: function(response) { if (response.success) { setupResultView(true, response.data); } else { setupResultView(false, response.data); } }, error: function() { setupResultView(false, 'A server communication error occurred. Please try again.'); } }); }); // Handle "Start Over" button click toolApp.on('click', '#start-over-btn', function() { selectedFile = null; fileInput.val(''); // Clear the file input showStep('upload'); }); // --- INITIALIZATION --- showStep('upload'); // Show the initial upload view when the page loads }); https://desertsafaridxbpro.com/post-sitemap.xml 2025-04-02T12:16:03+00:00 https://desertsafaridxbpro.com/page-sitemap.xml 2025-08-08T11:49:41+00:00 https://desertsafaridxbpro.com/templately_library-sitemap.xml 2025-05-05T09:15:01+00:00 https://desertsafaridxbpro.com/category-sitemap.xml 2025-04-02T12:16:03+00:00 https://desertsafaridxbpro.com/news-sitemap.xml 2025-08-08T10:51:30+00:00 https://desertsafaridxbpro.com/local-sitemap.xml 2024-12-30T08:45:18+00:00