1(function ($, Drupal) { 2 3 Drupal.behaviors.bt_leads_antibot_workaround = { 4 attach: function (context, settings) { 5 // Add a function that reacts on bt_leads form popups 6 $('body').once(function () { 7 // Select the node that will be observed for mutations 8 const targetNode = document.getElementsByTagName("body")[0]; 9 10 // Options for the observer (which mutations to observe) 11 const config = { attributes: false, childList: true, subtree: false }; 12 13 // Callback function to execute when mutations are observed 14 const callback = (mutationList, observer) => { 15 for (const mutation of mutationList) { 16 if (mutation.type === "childList") { 17 // Search for a bt_leads form. 18 let $form = $('body > div.reveal-modal form[id^=bt-leads]'); 19 20 if (!$form.length) { 21 return; 22 } 23 24 // Form found, process the real antibot workaround. 25 $.get('/bt-leads-antibot-workaround') 26 .done(function (data) { 27 // Control flag used to tell if antibot behavior must be init. 28 let initBehavior = false; 29 30 // In case antibot normal file is not loaded, do it. 31 if (typeof Drupal.antibot === 'undefined') { 32 // Load the antibot.js script. 33 let antibotScript = document.createElement('script'); 34 antibotScript.src = '/sites/all/modules/contrib/antibot/js/antibot.js'; 35 document.head.appendChild(antibotScript); 36 37 // Tell antibot behaviors to be init'd. 38 initBehavior = true; 39 } 40 41 setTimeout(function () { 42 // Workaround to overcome limitations of advagg when it transforms js code. 43 // If this is not done, "data" usage later will fail as data no longer is called 44 // "data" when advagg optimizes it but usage later (in settings.antibot.forms) is 45 // never updated with the new name. That's why it's forced to use a new variable 46 // and the use it. That never fails. :shrug: 47 let data2 = data; 48 49 // Init antibot behavior if requested. 50 if (initBehavior) { 51 // Ensure antibot behaviors are loaded. 52 Drupal.behaviors.antibot.attach(document); 53 } 54 55 // In case no antibot settings, init it. 56 settings.antibot = settings.antibot ?? {}; 57 58 // Add the forms info to antibot. 59 settings.antibot.forms = { ...(settings.antibot.forms ?? {}), ...data2 }; 60 61 // Reset the human flag. 62 settings.antibot.human = false; 63 64 // Call the antibot unlock to ensure all protected forms are enabled. 65 Drupal.antibot.unlockForms(); 66 }, 0); 67 }); 68 } 69 } 70 }; 71 72 // Create an observer instance linked to the callback function 73 const observer = new MutationObserver(callback); 74 75 // Start observing the target node for configured mutations 76 observer.observe(targetNode, config); 77 78 // // Later, you can stop observing 79 // observer.disconnect(); 80 }); 81 } 82 } 83})(jQuery, Drupal);
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.