1jQuery(document).ready(function ($) { 2 // --- HELPER FUNCTIONS --- 3 function getCookie(name) { 4 let value = `; ${document.cookie}`; 5 let parts = value.split(`; ${name}=`); 6 if (parts.length === 2) return parts.pop().split(";").shift(); 7 return null; 8 } 9 10 function setCookie(name, value, hours) { 11 let date = new Date(); 12 date.setTime(date.getTime() + hours * 60 * 60 * 1000); 13 let expires = `expires=${date.toUTCString()}`; 14 document.cookie = `${name}=${value}; ${expires}; path=/`; 15 } 16 17 // --- FINAL ARCHITECTURE w/ REVISED LOGGING --- 18 let ajaxCallMade = false; 19 20 function displayPopup(popupData) { 21 const template = document.getElementById( 22 `cr-popup-template-${popupData.id}` 23 ); 24 25 if (!template) { 26 console.error( 27 "HALT: Popup template could not be found for ID:", 28 popupData.id 29 ); 30 return; 31 } 32 33 34 const clone = template.content.cloneNode(true); 35 $("body").append(clone); 36 37 setCookie("cr_popup_cooldown", "true", 2); 38 39 const dialogElement = document.getElementById("cr-popup-dialog"); 40 const closeButton = document.getElementById("cr-popup-dialog-close"); 41 42 closeButton.addEventListener("click", () => dialogElement.close()); 43 dialogElement.addEventListener("click", (event) => { 44 var rect = dialogElement.getBoundingClientRect(); 45 var isInDialog = 46 rect.top <= event.clientY && 47 event.clientY <= rect.top + rect.height && 48 rect.left <= event.clientX && 49 event.clientX <= rect.left + rect.width; 50 if (!isInDialog) { 51 dialogElement.close(); 52 } 53 }); 54 55 try { 56 if (window.Invoca && window.Invoca.Client) { 57 window.Invoca.Client.start(); 58 console.log("Invoca rescan triggered successfully"); 59 } 60 } catch (e) { 61 console.error("Invoca re-scan failed:", e); 62 } 63 64 dialogElement.showModal(); 65 66 setTimeout(function () { 67 68 const formId = popupData.form_id; 69 // Scope to the dialog: themes may embed the same form elsewhere on the 70 // page (duplicate IDs), and a bare ID selector would match that copy. 71 const formWrapperSelector = `#cr-popup-dialog #gform_wrapper_${formId}`; 72 const $formWrapper = $(formWrapperSelector); 73 74 if ($formWrapper.length) { 75 $formWrapper.css({ 76 display: "block", 77 visibility: "visible", 78 opacity: "1", 79 }); 80 81 if (formId && typeof jQuery.fn.trigger === "function") { 82 jQuery(document).trigger("gform_post_render", [formId, 1]); 83 } 84 } else { 85 console.error( 86 "HALT: Form wrapper was NOT found in the live DOM after a delay. Please check the HTML from DEBUG 3 to see if it was stripped by the server." 87 ); 88 } 89 }, 150); 90 } 91 92 // --- The rest of the file remains the same --- 93 if ( 94 (document.querySelector('meta[name="robots"]') && 95 document 96 .querySelector('meta[name="robots"]') 97 .getAttribute("content") 98 .includes("noindex")) || 99 getCookie("cr_popup_cooldown") 100 ) { 101 ajaxCallMade = true; 102 } 103 104 window.addEventListener( 105 "scroll", 106 () => { 107 if (ajaxCallMade) return; 108 const scrollPosition = 109 window.scrollY || document.documentElement.scrollTop; 110 const pageHeight = 111 document.documentElement.scrollHeight - window.innerHeight; 112 113 if (scrollPosition >= pageHeight * 0.4) { 114 ajaxCallMade = true; 115 $.post( 116 crPopupData.ajax_url, 117 { 118 action: "get_cr_popup", 119 uri: window.location.pathname, 120 }, 121 function (response) { 122 if (response.success) { 123 displayPopup({ 124 id: response.data.popup_id, 125 form_id: response.data.form_id, 126 }); 127 } else { 128 // No popup configured for this page â expected, not an error. 129 } 130 } 131 ); 132 } 133 }, 134 { passive: true } 135 ); 136});
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.