{"version":3,"file":"turnstile-DLTK-7hL.js","sources":["../../../app/frontend/entrypoints/turnstile.js"],"sourcesContent":["// Function to dynamically load the Turnstile script and ensure it's ready\nfunction loadTurnstileScript(callback) {\n if (!document.querySelector(\"script[src*='challenges.cloudflare.com']\")) {\n const script = document.createElement(\"script\")\n script.src = `${window.captcha_api_server_url}?render=explicit`\n script.async = true\n script.onload = callback\n document.body.appendChild(script)\n } else {\n callback() // Call the callback directly if the script is already loaded\n }\n}\n\n// Callback function when Turnstile is ready\nfunction initializeTurnstile() {\n document\n .querySelectorAll(\"form:has(.cf-turnstile)\")\n .forEach((formElement) => {\n formElement.addEventListener(\"submit\", function (event) {\n event.preventDefault()\n\n // Check if the Turnstile challenge has already been solved\n if (formElement.querySelector(\"input[name='cf-turnstile-response']\")) {\n formElement.submit()\n return\n }\n\n // Prevent multiple Turnstile widgets from being rendered in the same form\n if (!formElement.dataset.turnstileInitialized) {\n formElement.dataset.turnstileInitialized = \"true\" // Mark the form as initialized\n const turnstileDiv = formElement.querySelector(\".cf-turnstile\")\n if (turnstileDiv) {\n // Ensure the div has an ID for the Turnstile render function\n const turnstileId =\n turnstileDiv.id ||\n `turnstile-${Math.random().toString(36).substring(2, 9)}`\n turnstileDiv.id = turnstileId\n // Render the Turnstile widget explicitly using the ID\n turnstile.render(`#${turnstileId}`, {\n sitekey: window.captcha_site_key, // Use the site key from a global variable or directly\n callback: (token) => {\n // Insert the token into a hidden input within the form\n const tokenInput = document.createElement(\"input\")\n tokenInput.type = \"hidden\"\n tokenInput.name = \"cf-turnstile-response\"\n tokenInput.value = token\n formElement.appendChild(tokenInput)\n\n formElement.submit()\n },\n })\n }\n } else {\n // If the widget is already initialized, submit the form directly\n formElement.submit()\n }\n })\n })\n}\n\nloadTurnstileScript(initializeTurnstile)\n"],"names":["loadTurnstileScript","callback","script","initializeTurnstile","formElement","event","turnstileDiv","turnstileId","token","tokenInput"],"mappings":"AACA,SAASA,EAAoBC,EAAU,CACrC,GAAK,SAAS,cAAc,0CAA0C,EAOpEA,EAAU,MAP6D,CACvE,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAM,GAAG,OAAO,sBAAsB,mBAC7CA,EAAO,MAAQ,GACfA,EAAO,OAASD,EAChB,SAAS,KAAK,YAAYC,CAAM,CACpC,CAGA,CAGA,SAASC,GAAsB,CAC7B,SACG,iBAAiB,yBAAyB,EAC1C,QAASC,GAAgB,CACxBA,EAAY,iBAAiB,SAAU,SAAUC,EAAO,CAItD,GAHAA,EAAM,eAAgB,EAGlBD,EAAY,cAAc,qCAAqC,EAAG,CACpEA,EAAY,OAAQ,EACpB,MACD,CAGD,GAAKA,EAAY,QAAQ,qBA0BvBA,EAAY,OAAQ,MA1ByB,CAC7CA,EAAY,QAAQ,qBAAuB,OAC3C,MAAME,EAAeF,EAAY,cAAc,eAAe,EAC9D,GAAIE,EAAc,CAEhB,MAAMC,EACJD,EAAa,IACb,aAAa,KAAK,OAAM,EAAG,SAAS,EAAE,EAAE,UAAU,EAAG,CAAC,CAAC,GACzDA,EAAa,GAAKC,EAElB,UAAU,OAAO,IAAIA,CAAW,GAAI,CAClC,QAAS,OAAO,iBAChB,SAAWC,GAAU,CAEnB,MAAMC,EAAa,SAAS,cAAc,OAAO,EACjDA,EAAW,KAAO,SAClBA,EAAW,KAAO,wBAClBA,EAAW,MAAQD,EACnBJ,EAAY,YAAYK,CAAU,EAElCL,EAAY,OAAQ,CACrB,CACf,CAAa,CACF,CACX,CAIA,CAAO,CACP,CAAK,CACL,CAEAJ,EAAoBG,CAAmB"}