jQuery(document).ready(function($) { console.log("************************ v1.7 ******************************"); // Click handler for the Glamour button to get face images and start swaps $(document).on('click', '.glamour', function(e) { e.preventDefault(); var $btn = $(this); if ($btn.hasClass('loading')) return; // prevent double clicks $btn.addClass('loading'); $.ajax({ url: afFaceswap.ajax_url, type: 'POST', data: { action: 'af_get_face_images', product_id: $btn.closest('[data-product_id]').data('product_id') }, success: function(response) { $btn.removeClass('loading'); if (response.success && response.data.face_images && response.data.face_images.length) { showFaceSwapModal(response.data.face_images.slice(0, 3)); // limit max 3 } else { alert('No valid face images found for this product.'); } }, error: function() { $btn.removeClass('loading'); alert('Error fetching face images.'); } }); }); // Show modal with face images function showFaceSwapModal(faceImages) { if ($('#faceSwapModal').length) $('#faceSwapModal').remove(); var modalHtml = `
×
${faceImages.map(img => `
Waiting...
`).join('')}
`; $('body').append(modalHtml); $('#faceSwapClose').on('click', function() { $('#faceSwapModal').remove(); }); startFaceSwapsSequential(faceImages); } // Get face token from cookie function getFaceToken() { const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(c => c.trim().startsWith('af_face_token=')); return tokenCookie ? tokenCookie.split('=')[1] : null; } // Sequentially swap faces on images function startFaceSwapsSequential(images, index = 0) { if (index >= images.length) { console.log('All face swaps complete!'); return; } var imgUrl = images[index]; var $container = $(`#faceSwapImages .face-swap-container`).eq(index); var $status = $container.find('.swap-status'); $status.text('Swapping face...'); var faceToken = getFaceToken(); if (!faceToken) { alert('Face token missing or expired, please upload your face again.'); $('#faceSwapModal').remove(); return; } $.ajax({ url: afFaceswap.ajax_url, method: 'POST', data: { action: 'af_apply_faceswap', image_url: imgUrl, _wpnonce: afFaceswap.nonce }, success: function(resp) { if (!resp.success) { $status.text('Error: ' + (resp.data?.message || 'Unknown error')); return startFaceSwapsSequential(images, index + 1); } // Poll for swap result pollForResult(resp.data.task_id, $container, function(success, newUrlOrMsg) { if (success) { $container.find('img').attr('src', newUrlOrMsg); $status.text('Done!'); } else { $status.text('Failed: ' + newUrlOrMsg); } startFaceSwapsSequential(images, index + 1); }); }, error: function() { $status.text('AJAX error'); startFaceSwapsSequential(images, index + 1); } }); } // Poll server until faceswap task completes or times out function pollForResult(taskId, $container, callback) { var start = Date.now(); var timeout = 60000; // 60 seconds var interval = setInterval(function() { if (Date.now() - start > timeout) { clearInterval(interval); callback(false, 'Timeout'); return; } $.ajax({ url: 'https://kittydarling.co.uk/pollit.php', method: 'GET', data: { task_id: taskId }, success: function(data) { var imageUrl = data.image || (data.data && data.data.output && data.data.output.image_url); if (imageUrl) { clearInterval(interval); callback(true, imageUrl); } }, error: function() { clearInterval(interval); callback(false, 'Poll error'); } }); }, 3000); } }); 50s Dresses - Kitty Darling – Retro Styled 40s & 50s Swing Dresses | Modern Vintage-Inspired Glamour
0

Search

Sort by
Show
Back to Top
Product has been added to your cart