1jQuery(document).ready(function ($) { 2 if (jQuery(".upgrade-overlay-container").length > 0) { 3 jQuery("#genrate_form_logo").addClass("blur_form"); 4 jQuery("#generate-logo").attr("disabled", true); 5 } 6 // Download button handler 7 $(document).on( 8 "click", 9 ".logo-download-button, .dashboard-logo-download", 10 function () { 11 const button = $(this); 12 13 if (button.data("needs-login")) { 14 alert("Please Login or Register to download this image."); 15 window.location.href = "/register"; 16 return; 17 } else { 18 const imageUrl = button.data("image-url"); 19 const altText = button.data("alt-text"); 20 21 // Set the download file name using the alt text, with a fallback name 22 const fileName = (altText ? altText : "logo-image") + ".png"; 23 24 const link = document.createElement("a"); 25 link.href = imageUrl; 26 link.download = fileName; 27 link.click(); 28 } 29 } 30 ); 31 32 // Delete button 33 $(document).on("click", ".logo-delete-button", function () { 34 const button = $(this); 35 const logoId = button.data("logo-id"); 36 console.log(logoId); 37 38 // Select the existing modal content 39 const $modalContent = jQuery("#logoAIModalContent"); 40 41 // Clear previous content and add confirmation message with dynamic yes/no buttons 42 $modalContent.html(` 43 <div class="logo-delete-confirmation"> 44 <p>Are you sure you want to delete this logo?</p> 45 <div class="confirmation-buttons"> 46 <button class="logo-btn delete-yes-button btn btn-danger">Yes, Delete</button> 47 <button class="logo-btn delete-no-button btn btn-secondary">No, Cancel</button> 48 </div> 49 </div> 50 `); 51 52 // Show the modal 53 jQuery("#logoAIModal").fadeIn(); 54 55 // Handle Yes button click 56 $modalContent.find(".delete-yes-button").on("click", function () { 57 $.ajax({
58 url: logoAIGeneratorSettings.ajaxUrl, 59 method: "POST", 60 data: { 61 action: "delete_user_logo", 62 logo_id: logoId, 63 }, 64 success: function (response) { 65 if (response.success) { 66 // Remove the Logo item from the dashboard 67 button.closest(".dashboard-logo-item").remove(); 68 69 // Update modal content with success message 70 $modalContent.html(` 71 <div class="logo-delete-success"> 72 <p>${response.data}</p> 73 </div> 74 `); 75 76 // Add close button event 77 $modalContent.find(".logo-ai-close-btn").on("click", function () { 78 jQuery("#logoAIModal").fadeOut(); 79 window.location.reload(); 80 }); 81 } else { 82 // Show error message in the modal 83 $modalContent.html(` 84 <div class="logo-delete-error"> 85 <p>${response.data}</p> 86 </div> 87 `); 88 89 // Add close button event 90 $modalContent.find(".logo-ai-close-btn").on("click", function () { 91 jQuery("#logoAIModal").fadeOut(); 92 }); 93 } 94 }, 95 error: function () { 96 // Show error message in the modal 97 $modalContent.html(` 98 <div class="logo-delete-error"> 99 <p>An error occurred while deleting the logo.</p> 100 </div> 101 `); 102 103 // Add close button event 104 $modalContent.find(".logo-ai-close-btn").on("click", function () { 105 jQuery("#logoAIModal").fadeOut(); 106 }); 107 }, 108 }); 109 }); 110 111 // Handle No button click 112 $modalContent.find(".delete-no-button").on("click", function () { 113 // Simply hide the modal 114 jQuery("#logoAIModal").fadeOut(); 115 }); 116 }); 117 let isGenerating = false; 118 let generationTimer = null; 119 let userIp = null; // Declare a global variable to store the user's IP 120 121 function getStableFingerprint(callback) { 122 if (typeof Fingerprint2 === "undefined") { 123 console.error("Fingerprint2 is not loaded."); 124 return; 125 } 126 127 // Wait for page load and a small delay 128 if (document.readyState !== "complete") { 129 window.addEventListener("load", () => 130 setTimeout(getMinimalFingerprint, 500, callback) 131 ); 132 } else { 133 setTimeout(() => getMinimalFingerprint(callback), 500); 134 } 135 } 136 137 function getMinimalFingerprint(callback) { 138 // Get basic hardware information directly 139 const hardwareInfo = { 140 screen: { 141 width: window.screen.width, 142 height: window.screen.height, 143 colorDepth: window.screen.colorDepth, 144 }, 145 timezone: new Date().getTimezoneOffset(), 146 cores: navigator.hardwareConcurrency || "", 147 platform: navigator.platform, 148 }; 149 150 // Convert hardware info to a stable string 151 const hardwareString = JSON.stringify({ 152 screenWidth: hardwareInfo.screen.width, 153 screenHeight: hardwareInfo.screen.height, 154 colorDepth: hardwareInfo.screen.colorDepth, 155 timezone: hardwareInfo.timezone, 156 cores: hardwareInfo.cores, 157 platform: hardwareInfo.platform, 158 }); 159 160 // Use a more stable hashing approach 161 const hash = Fingerprint2.x64hash128(hardwareString, 31); 162 callback(hash); 163 } 164 // Function to fetch and set the user's IP address 165 function getUserIp() { 166 getStableFingerprint(function (fingerprint) { 167 console.log("Stable Device Fingerprint:", fingerprint); 168 saveUserIp(fingerprint); 169 userIp = fingerprint; 170 return fingerprint; 171 }); 172 } 173 function checkVPN(ip) { 174 return $.ajax({ 175 url: `https://api.ipapi.is/?q=${ip}`, 176 method: "GET", 177 dataType: "json", 178 }) 179 .then((response) => { 180 // The response typically contains a flag indicating if it's a VPN 181 // Assuming `vpn` field is present and boolean 182 return response.is_vpn || false; // Return true if VPN is detected 183 }) 184 .catch((error) => { 185 console.error("Error checking VPN status:", error); 186 return false; // Default to false if there's an error 187 }); 188 } 189 // Call getUserIp to retrieve and store the user's IP 190 getUserIp(); 191 192 $("#generate-logo").on("click", function (e) { 193 e.preventDefault(); 194 195 // Ensure user IP is fetched 196 if (!userIp || userIp === null) { 197 userIp = "Unknown"; 198 } else { 199 console.log(`User IP: ${userIp}`); 200 } 201 proceedWithlogoGeneration(); 202 }); 203 204 // Function to handle the Logo generation process 205 function proceedWithlogoGeneration() { 206 if (isGenerating) { 207 alert("Please wait for the current generation to complete."); 208 return; 209 } 210 211 // Form validation 212 const logo_business_name = $("#form-field-logo_business_name").val(); 213 const logo_slogan = $("#form-field-logo_slogan").val(); 214 const color_preferences = $("#form-field-logo_color_preferences").val(); 215 const logo_style = $("#form-field-logo_style").val(); 216 const logo_description = $("#form-field-logo_description").val(); 217 const ai_model = $("#form-field-ai_model").val(); 218 if ( 219 ai_model === 220 "Premium AI (no spelling errors, advanced designs, faster speed, more creations, commercial rights granted)" 221 ) { 222 223 clearInterval(generationTimer); 224 setTimeout(function () { 225 window.location.href = "/pricing/"; 226 }, 100); 227 return; 228 } 229 if (!logo_business_name) { 230 alert("Please add a business name."); 231 return; 232 } 233 234 isGenerating = true; 235 236 // Create or clear result container and show loader immediately 237 if ($("#logo-result").length === 0) { 238 $('<div id="logo-result"></div>').insertAfter(".elementor-form"); 239 } 240 241 // Show loading UI 242 $("#logo-result").html(` 243 <div class="loading-overlay"> 244 <div class="loading-spinner"> 245 <div class="spinner"></div> 246 <p>Creating your unique logo design...</p> 247 <div class="progress-container"> 248 <div class="progress-bar" style="width: 100%; background-color:rgba(130, 145, 195, 0.48); height: 20px; border-radius: 10px; overflow: hidden;"> 249 <div class="progress-bar-inner" style="width: 0%; height: 100%; background-color: #254edb; transition: width 1s linear;"></div> 250 </div> 251 <p id="progress-time" style="text-align: center; margin-top: 10px; font-weight: bold;">Processing...</p> 252 </div> 253 <div id="progress-message" style="text-align: center; margin-top: 15px; color: #666;"> 254 Processing your preferences and style... 255 </div> 256 </div> 257 </div> 258 `); 259 260 const progressMessages = [ 261 "Processing your preferences and style...", 262 "Exploring creative possibilities...", 263 "Crafting your unique logo concept...", 264 "Perfecting the details...", 265 "Your logo is almost ready...", 266 ]; 267 268 let timeElapsed = 0; 269 const totalTime = parseInt(logoAIGeneratorSettings.generationTime) || 20; 270 const progressBar = $(".progress-bar-inner"); 271 272 // Start progress timer 273 generationTimer = setInterval(() => { 274 timeElapsed++; 275 const progress = Math.min((timeElapsed / totalTime) * 100, 90); 276 progressBar.css("width", progress + "%"); 277 278 const timeRemaining = totalTime - timeElapsed; 279 $("#progress-time").text(timeRemaining + " seconds remaining"); 280 281 const messageIndex = 282 Math.floor(timeElapsed / 6) % progressMessages.length; 283 $("#progress-message").text(progressMessages[messageIndex]); 284 285 if (timeElapsed >= totalTime) { 286 clearInterval(generationTimer); 287 } 288 }, 1000); 289 290 // Make AJAX request 291 $.ajax({
292 type: "POST", 293 url: logoAIGeneratorSettings.ajaxUrl, 294 data: { 295 action: "generate_logo", 296 logo_business_name: logo_business_name, 297 color_preferences: color_preferences, 298 logo_style: logo_style, 299 logo_description: logo_description, 300 logo_slogan: logo_slogan, 301 userIp: userIp, 302 nonce: logoAIGeneratorSettings.nonce, 303 }, 304 }) 305 .then((response) => { 306 console.log(response); 307 if (response.success) { 308 isGenerating = false; 309 if (response.data.needs_login) { 310 $("#logo-result").css("display", "none"); 311 clearInterval(generationTimer); 312 setTimeout(function () { 313 window.location.href = "/pricing/"; 314 }, 100); 315 return; 316 } 317 318 setTimeout(() => { 319 setTimeout(() => { 320 // Reset values and display placeholders 321 // jQuery( 322 // "#form-field-logo_business_name, #form-field-logo_slogan, #form-field-logo_color_preferences, #form-field-logo_description" 323 // ).val(""); 324 // jQuery( 325 // "#form-field-logo_style" 326 // ).prop("selectedIndex", 0); 327 jQuery("#generate-logo").text("Create Another Logo"); 328 }, 1000); 329 if (response.data.percentage !== null) { 330 var progress = response.data.percentage; 331 332 jQuery(window).on("scroll", function () { 333 jQuery(".span.eael-progressbar-line-fill") 334 .css("width", progress + "%") 335 .attr("data-max", progress); 336 }); 337 338 jQuery(".span.eael-progressbar-line-fill") 339 .css("width", progress + "%") 340 .attr("data-max", progress); 341 } 342 if (response.data.credits_remaining !== null) { 343 jQuery(".eael-progressbar-title").text( 344 response.data.credits_remaining 345 ); 346 } 347 348 $("#logo-result").html(` 349 <div class="logo-generated"> 350 ${response.data.html} 351 </div> 352 `); 353 }, Math.max(0, (totalTime - timeElapsed) * 1000)); 354 } else { 355 console.log(response); 356 if (response.data === "No credits left") { 357 window.location.href = "/pricing/"; 358 } 359 clearInterval(generationTimer); 360 $("#logo-result").html(` 361 <div class="error-message"> 362 <p>${response.data}</p> 363 </div> 364 `); 365 isGenerating = false; 366 $("#generate-logo").prop("disabled", false).text("Generate my logo"); 367 } 368 }) 369 .catch((error) => { 370 clearInterval(generationTimer); 371 $("#logo-result").html(` 372 <div class="error-message"> 373 <p>Error: Unable to generate Logo design. Please try again later.</p> 374 <p>Details: ${error?.message || "Unknown error occurred"}</p> 375 </div> 376 `); 377 isGenerating = false; 378 $("#generate-logo").prop("disabled", false).text("Generate my logo"); 379 }) 380 .always(() => { 381 setTimeout(() => { 382 isGenerating = false; 383 $("#generate-logo").prop("disabled", false).text("Generate my logo"); 384 }, Math.max(0, (totalTime - timeElapsed) * 1000)); 385 }); 386 } 387 388 // Find elements containing the text and hide them 389 $("p").each(function () { 390 let text = $(this).text(); 391 if ( 392 text.includes( 393 "From your account dashboard you can view your recent orders" 394 ) && 395 text.includes("manage your shipping and billing addresses") && 396 text.includes("edit your password and account details") 397 ) { 398 $(this).hide(); 399 } 400 }); 401 402 // Also handle the "Hello [name] (not [name]? Log out)" text 403 $("p").each(function () { 404 let text = $(this).text(); 405 if (text.match(/Hello .* \(not .*\? Log out\)/)) { 406 $(this).hide(); 407 } 408 }); 409 jQuery(".woocommerce-MyAccount-navigation-link--dashboard a").text( 410 "My logos" 411 ); 412 jQuery(".e-my-account-tab__dashboard").fadeIn(); 413 414 // Password Change Form Submission 415 $("#change-password-form").on("submit", function (e) { 416 e.preventDefault(); 417 418 var currentPassword = $("#current_password").val(); 419 var newPassword = $("#new_password").val(); 420 var confirmPassword = $("#confirm_password").val(); 421 422 // Basic client-side validation 423 if (newPassword !== confirmPassword) { 424 alert("New passwords do not match."); 425 return; 426 } 427 428 // Ajax password change 429 $.ajax({
430 url: logoAIGeneratorSettings.ajaxUrl, 431 type: "POST", 432 data: { 433 action: "change_password", 434 security: accountSettings.nonce, 435 current_password: currentPassword, 436 new_password: newPassword, 437 confirm_password: confirmPassword, 438 }, 439 success: function (response) { 440 if (response.success) { 441 alert(response.data); 442 // Optional: Redirect or clear form 443 $("#change-password-form")[0].reset(); 444 } else { 445 alert(response.data); 446 } 447 }, 448 error: function () { 449 alert("An error occurred. Please try again."); 450 }, 451 }); 452 }); 453 454 // Account Deletion Button 455 $("#btn-delete-account").on("click", function (e) { 456 // Select the existing modal content 457 const $modalContent = jQuery("#logoAIModalContent"); 458 459 // Clear previous content and add confirmation message with dynamic yes/no buttons 460 $modalContent.html(` 461 <div class="account-delete-confirmation"> 462 <p class="text-center font-weight-bold">Are you absolutely sure you want to delete your account?</p> 463 <p class="text-danger text-center">This action CANNOT be undone.</p> 464 <div class="confirmation-buttons d-flex justify-content-center mt-3"> 465 <button class="logo-btn delete-yes-button btn btn-danger mr-2">Yes, Delete My Account</button> 466 <button class="logo-btn delete-no-button btn btn-secondary">No, Cancel</button> 467 </div> 468 </div> 469 `); 470 471 // Show the modal 472 jQuery("#logoAIModal").fadeIn(); 473 474 // Handle Yes button click 475 $modalContent.find(".delete-yes-button").on("click", function () { 476 $.ajax({
477 url: logoAIGeneratorSettings.ajaxUrl, 478 type: "POST", 479 data: { 480 action: "delete_account", 481 security: accountSettings.nonce, 482 }, 483 success: function (response) { 484 if (response.success) { 485 // Update modal content with success message 486 $modalContent.html(` 487 <div class="account-delete-success text-center"> 488 <p class="text-success">${response.data}</p> 489 </div> 490 `); 491 492 setTimeout(() => { 493 jQuery("#logoAIModal").fadeOut(); 494 // Redirect to home page or login page 495 window.location.href = "/"; 496 }, 2000); 497 498 // Add close button event 499 $modalContent.find(".logo-ai-close-btn").on("click", function () { 500 jQuery("#logoAIModal").fadeOut(); 501 // Redirect to home page or login page 502 window.location.href = "/"; 503 }); 504 } else { 505 // Show error message in the modal 506 $modalContent.html(` 507 <div class="account-delete-error text-center"> 508 <p class="text-danger">Account deletion failed.</p> 509 510 </div> 511 `); 512 513 // Add close button event 514 $modalContent.find(".logo-ai-close-btn").on("click", function () { 515 jQuery("#logoAIModal").fadeOut(); 516 }); 517 } 518 }, 519 error: function () { 520 // Show error message in the modal 521 $modalContent.html(` 522 <div class="account-delete-error text-center"> 523 <p class="text-danger">An error occurred. Please try again.</p> 524 525 </div> 526 `); 527 528 // Add close button event 529 $modalContent.find(".logo-ai-close-btn").on("click", function () { 530 jQuery("#logoAIModal").fadeOut(); 531 }); 532 }, 533 }); 534 }); 535 536 // Handle No button click 537 $modalContent.find(".delete-no-button").on("click", function () { 538 // Simply hide the modal 539 jQuery("#logoAIModal").fadeOut(); 540 }); 541 }); 542 jQuery(".bdt-login").attr("href", "/login"); 543 544 jQuery(".bdt-lost-password").attr("href", "/password-recovery/"); 545 546 // jQuery("#customer_details, #order_review").wrapAll( 547 // '<div id="custom-checkout-form-logos"></div>' 548 // ); 549 // // remove <h3 id="order_review_heading">Your order</h3> 550 // jQuery("h3#order_review_heading").remove(); 551 // insert inside <div id="custom-checkout-form-logos"> 552 // jQuery('#order_review').appendTo('<h3 id="order_review_headings">Your order</h3>'); 553 // jQuery("#order_review").prepend("<h3>Your Order </h3>"); 554 setTimeout(() => { 555 jQuery("form.checkout.woocommerce-checkout").css("visibility", "visible"); 556 var logoDetails = jQuery("#logo-order-details").html(); 557 var customerDetails = jQuery("#customer_details").html(); 558 559 // Swap the contents 560 jQuery("#logo-order-details").html(customerDetails); 561 jQuery("#customer_details").html("<h3>Your Order</h3>" + logoDetails); 562 }, 1000); 563 jQuery(".woocommerce-checkout-review-order-table").wrapAll( 564 '<div id="logo-order-details"></div>' 565 ); 566 567 // if page is checkout then after 3s .blockUI.blockOverlay display none 568 setTimeout(() => { 569 if (window.location.href.includes("checkout")) { 570 jQuery(".blockUI.blockOverlay").css("display", "none"); 571 } 572 }, 3000); 573 574 // Close button functionality 575 $(".logo-ai-close-btn").on("click", function () { 576 $("#logoAIModal").fadeOut(); 577 }); 578 579 // Optional: Close modal if clicked outside 580 $(window).on("click", function (event) { 581 if ($(event.target).hasClass("logo-ai-modal")) { 582 $("#logoAIModal").fadeOut(); 583 } 584 }); 585 586 // const iframe = document.querySelector("fieldset#wc-stripe-upe-form iframe"); 587 const iframe = jQuery("fieldset#wc-stripe-upe-form iframe"); 588 589 if (iframe) { 590 console.log("Iframe loaded."); 591 iframe.onload = function () { 592 const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; 593 const style = iframeDoc.createElement("style"); 594 style.innerHTML = ` 595 zlabel.p-FieldLabel.Label.Label--empty { 596 color: white !important; 597 } 598 `; 599 iframeDoc.head.appendChild(style); 600 }; 601 } else { 602 console.log("Iframe not loaded."); 603 } 604 if (window.location.href.includes("order-received")) { 605 setTimeout(function () { 606 var redirectUrl = "/ai-logo-generator/"; 607 window.location.href = redirectUrl; 608 }, 5000); // Delay of 2 seconds 609 } 610 jQuery(".forget-pass a").attr("href", "/password-recovery/"); 611 var logoutlink = jQuery("#logoutlink").val(); 612 if (logoutlink) { 613 jQuery(".menu-item-51742 a").attr("href", logoutlink); 614 } 615 616 // Usage 617 618 // Fetch the user's IP address 619 620 // Save the user IP address via AJAX 621 function saveUserIp(userIp) { 622 $.ajax({
623 url: logoAIGeneratorSettings.ajaxUrl, // WordPress provides this variable 624 type: "POST", 625 data: { 626 action: "save_user_ip", // The action hook for the AJAX request 627 user_ip: userIp, // The IP address to be saved 628 }, 629 success: function (response) { 630 console.log(response); // Log the response 631 632 if (response.success && response.data) { 633 var creditsRemaining = parseInt(response.data.credits_remaining); 634 console.log("Credits remaining:", creditsRemaining); 635 636 // If no credits remaining, hide the field 637 if (creditsRemaining > 0) { 638 $(".elementor-field-group-ai_model").css("display", "none"); 639 } 640 } 641 }, 642 error: function (xhr, status, error) { 643 console.error("AJAX error:", status, error); 644 }, 645 }); 646} 647 648// Call the getUserIp function to start the process 649getUserIp(); 650 651}); 652 653// album cover js code start 654jQuery(document).ready(function ($) { 655 // Get user IP (you might need to implement this function) 656 let userIp = null; 657 658 // Function to get user IP - same as logo generation 659 function getStableFingerprint(callback) { 660 if (typeof Fingerprint2 === "undefined") { 661 console.error("Fingerprint2 is not loaded."); 662 return; 663 } 664 665 if (document.readyState !== "complete") { 666 window.addEventListener("load", () => 667 setTimeout(getMinimalFingerprint, 500, callback) 668 ); 669 } else { 670 setTimeout(() => getMinimalFingerprint(callback), 500); 671 } 672 } 673 674 function getMinimalFingerprint(callback) { 675 const hardwareInfo = { 676 screen: { 677 width: window.screen.width, 678 height: window.screen.height, 679 colorDepth: window.screen.colorDepth, 680 }, 681 timezone: new Date().getTimezoneOffset(), 682 cores: navigator.hardwareConcurrency || "", 683 platform: navigator.platform, 684 }; 685 686 const hardwareString = JSON.stringify({ 687 screenWidth: hardwareInfo.screen.width, 688 screenHeight: hardwareInfo.screen.height, 689 colorDepth: hardwareInfo.screen.colorDepth, 690 timezone: hardwareInfo.timezone, 691 cores: hardwareInfo.cores, 692 platform: hardwareInfo.platform, 693 }); 694 695 const hash = Fingerprint2.x64hash128(hardwareString, 31); 696 callback(hash); 697 } 698 699 function getUserIp() { 700 getStableFingerprint(function (fingerprint) { 701 console.log("Stable Device Fingerprint:", fingerprint); 702 userIp = fingerprint; 703 return fingerprint; 704 }); 705 } 706 707 // Call getUserIp to retrieve and store the user's IP 708 getUserIp(); 709 710 let isGenerating = false; 711 let generationTimer = null; 712 713 $("#generate-album-cover").on("click", function (e) { 714 e.preventDefault(); 715 716 // Ensure user IP is fetched 717 if (!userIp || userIp === null) { 718 userIp = "Unknown"; 719 } else { 720 console.log(`User IP: ${userIp}`); 721 } 722 proceedWithAlbumGeneration(); 723 }); 724 725 // Function to handle the Album Cover generation process 726 function proceedWithAlbumGeneration() { 727 if (isGenerating) { 728 alert("Please wait for the current generation to complete."); 729 return; 730 } 731 732 // Form validation with updated field names 733 const description = $("#form-field-description").val(); 734 const main_text = $("#form-field-main_text").val(); 735 const secondary_text = $("#form-field-secondary_text").val(); 736 const color_preferences = $("#form-field-color_preferences").val(); 737 const preferred_style = $("#form-field-preferred_style").val(); 738 const ai_model = $("#form-field-ai_model").val(); 739 740 if ( 741 ai_model === 742 "Premium AI (no spelling errors, advanced designs, faster speed, more creations, commercial rights granted)" 743 ) { 744 clearInterval(generationTimer); 745 setTimeout(function () { 746 window.location.href = "/pricing/"; 747 }, 100); 748 return; 749 } 750 751 if (!description) { 752 alert("Please enter a description."); 753 return; 754 } 755 756 isGenerating = true; 757 758 // Create or clear result container and show loader immediately 759 if ($("#logo-result").length === 0) { 760 $('<div id="logo-result"></div>').insertAfter(".album-cover-form"); 761 } 762 763 // Show loading UI 764 $("#logo-result").html(` 765 <div class="loading-overlay"> 766 <div class="loading-spinner"> 767 <div class="spinner"></div> 768 <p>Creating your unique album cover design...</p> 769 <div class="progress-container"> 770 <div class="progress-bar" style="width: 100%; background-color:rgba(130, 145, 195, 0.48); height: 20px; border-radius: 10px; overflow: hidden;"> 771 <div class="progress-bar-inner" style="width: 0%; height: 100%; background-color: #254edb; transition: width 1s linear;"></div> 772 </div> 773 <p id="progress-time" style="text-align: center; margin-top: 10px; font-weight: bold;">Processing...</p> 774 </div> 775 <div id="progress-message" style="text-align: center; margin-top: 15px; color: #666;"> 776 Processing your preferences and style... 777 </div> 778 </div> 779 </div> 780 `); 781 782 const progressMessages = [ 783 "Processing your preferences and style...", 784 "Exploring creative possibilities...", 785 "Crafting your unique album concept...", 786 "Perfecting the details...", 787 "Your album cover is almost ready...", 788 ]; 789 790 let timeElapsed = 0; 791 const totalTime = 20; // Same as logo generation time 792 const progressBar = $(".progress-bar-inner"); 793 794 // Start progress timer 795 generationTimer = setInterval(() => { 796 timeElapsed++; 797 const progress = Math.min((timeElapsed / totalTime) * 100, 90); 798 progressBar.css("width", progress + "%"); 799 800 const timeRemaining = totalTime - timeElapsed; 801 $("#progress-time").text(timeRemaining + " seconds remaining"); 802 803 const messageIndex = 804 Math.floor(timeElapsed / 6) % progressMessages.length; 805 $("#progress-message").text(progressMessages[messageIndex]); 806 807 if (timeElapsed >= totalTime) { 808 clearInterval(generationTimer); 809 } 810 }, 1000); 811 812 // Make AJAX request with updated field names 813 $.ajax({
814 type: "POST", 815 url: logoAIGeneratorSettings.ajaxUrl, 816 data: { 817 action: "generate_album_cover", 818 description: description, 819 main_text: main_text, 820 secondary_text: secondary_text, 821 color_preferences: color_preferences, 822 preferred_style: preferred_style, 823 userIp: userIp, 824 nonce: logoAIGeneratorSettings.nonce, 825 }, 826 }) 827 .then((response) => { 828 console.log(response); 829 if (response.success) { 830 isGenerating = false; 831 if (response.data.needs_login) { 832 $("#logo-result").css("display", "none"); 833 clearInterval(generationTimer); 834 setTimeout(function () { 835 window.location.href = "/pricing/"; 836 }, 100); 837 return; 838 } 839 840 setTimeout(() => { 841 if (response.data.percentage !== null) { 842 var progress = response.data.percentage; 843 844 jQuery(window).on("scroll", function () { 845 jQuery(".span.eael-progressbar-line-fill") 846 .css("width", progress + "%") 847 .attr("data-max", progress); 848 }); 849 850 jQuery(".span.eael-progressbar-line-fill") 851 .css("width", progress + "%") 852 .attr("data-max", progress); 853 } 854 if (response.data.credits_remaining !== null) { 855 jQuery(".eael-progressbar-title").text( 856 response.data.credits_remaining 857 ); 858 } 859 860 $("#logo-result").html(` 861 <div class="logo-generated"> 862 ${response.data.html} 863 </div> 864 `); 865 }, Math.max(0, (totalTime - timeElapsed) * 1000)); 866 } else { 867 console.log(response); 868 // if (response.data === "No credits left") { 869 // window.location.href = "/pricing/"; 870 // } 871 clearInterval(generationTimer); 872 $("#logo-result").html(` 873 <div class="error-message"> 874 <p>${response.data}</p> 875 </div> 876 `); 877 isGenerating = false; 878 $("#generate-album-cover") 879 .prop("disabled", false) 880 .text("Generate Album Cover"); 881 } 882 }) 883 .catch((error) => { 884 clearInterval(generationTimer); 885 $("#logo-result").html(` 886 <div class="error-message"> 887 <p>Error: Unable to generate album cover. Please try again later.</p> 888 <p>Details: ${error?.message || "Unknown error occurred"}</p> 889 </div> 890 `); 891 isGenerating = false; 892 $("#generate-album-cover") 893 .prop("disabled", false) 894 .text("Generate Album Cover"); 895 }) 896 .always(() => { 897 setTimeout(() => { 898 isGenerating = false; 899 $("#generate-album-cover") 900 .prop("disabled", false) 901 .text("Generate Album Cover"); 902 }, Math.max(0, (totalTime - timeElapsed) * 1000)); 903 }); 904 } 905 906 // Delete button 907 $(document).on("click", ".album-cover-delete-button", function () { 908 const button = $(this); 909 const coverId = button.data("cover-id"); 910 console.log(coverId); 911 912 // Select the existing modal content 913 const $modalContent = jQuery("#albumCoverModalContent"); 914 915 // Clear previous content and add confirmation message with dynamic yes/no buttons 916 $modalContent.html(` 917 <div class="album-cover-delete-confirmation"> 918 <p>Are you sure you want to delete this album cover?</p> 919 <div class="confirmation-buttons"> 920 <button class="album-cover-btn delete-yes-button btn btn-danger">Yes, Delete</button> 921 <button class="album-cover-btn delete-no-button btn btn-secondary">No, Cancel</button> 922 </div> 923 </div> 924 `); 925 926 // Show the modal 927 jQuery("#albumCoverModal").fadeIn(); 928 929 // Handle Yes button click 930 $modalContent.find(".delete-yes-button").on("click", function () { 931 $.ajax({
932 url: ajax_object.ajax_url, 933 method: "POST", 934 data: { 935 action: "delete_user_album_cover", 936 cover_id: coverId, 937 }, 938 success: function (response) { 939 if (response.success) { 940 // Remove the item from the dashboard 941 button.closest(".dashboard-album-cover-item").remove(); 942 943 // Update modal content with success message 944 $modalContent.html(` 945 <div class="album-cover-delete-success"> 946 <p>${response.data}</p> 947 </div> 948 `); 949 950 // Add close button event 951 $modalContent 952 .find(".album-cover-close-btn") 953 .on("click", function () { 954 jQuery("#albumCoverModal").fadeOut(); 955 window.location.reload(); 956 }); 957 } else { 958 // Show error message in the modal 959 $modalContent.html(` 960 <div class="album-cover-delete-error"> 961 <p>${response.data}</p> 962 </div> 963 `); 964 965 // Add close button event 966 $modalContent 967 .find(".album-cover-close-btn") 968 .on("click", function () { 969 jQuery("#albumCoverModal").fadeOut(); 970 }); 971 } 972 }, 973 error: function () { 974 // Show error message in the modal 975 $modalContent.html(` 976 <div class="album-cover-delete-error"> 977 <p>An error occurred while deleting the album cover.</p> 978 </div> 979 `); 980 981 // Add close button event 982 $modalContent.find(".album-cover-close-btn").on("click", function () { 983 jQuery("#albumCoverModal").fadeOut(); 984 }); 985 }, 986 }); 987 }); 988 989 // Handle No button click 990 $modalContent.find(".delete-no-button").on("click", function () { 991 // Simply hide the modal 992 jQuery("#albumCoverModal").fadeOut(); 993 }); 994 }); 995}); 996// album cover js code end
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.