1(function ($) { 2 // Function to check for specific consent 3 function checkForSpecificConsent() { 4 // Assuming OnetrustActiveGroups is a global variable set by OneTrust 5 return window.OnetrustActiveGroups && window.OnetrustActiveGroups.includes(',7,'); 6 } 7 8 // Function to initialize the newsletter modal logic 9 function initializeNewsletterModal(settings) { 10 // Default setting for Modal to NOT show. 11 var showModal = false; 12 13 // Check for newsletter setting ON. 14 if (settings.newsletter_modal.modal === '' || 15 typeof settings.newsletter_modal.modal === 'undefined' || 16 typeof settings.newsletter_modal.nid === 'undefined') { 17 return; 18 } 19 20 // Get newsletter NID from settings. 21 var NewsletterWebformNid = settings.newsletter_modal.nid; 22 23 // Count page visits with custom cookie. 24 var cookieCounter = $.cookie('newsletter_modal_counter'); 25 if (typeof cookieCounter === 'undefined' || cookieCounter === 'NaN') { 26 $.cookie('newsletter_modal_counter', 1, {path: '/'}); 27 } else { 28 // Increment newsletter_modal_counter cookie val if under 3 page loads. 29 cookieCounter = parseInt(cookieCounter, 10); 30 if (cookieCounter < 2) { 31 $.cookie('newsletter_modal_counter', cookieCounter + 1, {path: '/'}); 32 } 33 } 34 35 // Re-fetch the cookie after potential update 36 cookieCounter = parseInt($.cookie('newsletter_modal_counter'), 10); 37 38 if (cookieCounter >= 2 && // Cookie value on page visits. 39 settings.newsletter_modal.modal === 1 && // Modal settings is true. 40 !$.cookie('newsletter_modal_closed') && // Close cookie isn't valid.
41 !$.cookie('newsletter_modal_submitted')) { // Submit cookie isn't valid. 42 $.cookie('newsletter_modal_show', true, {path: '/'}); 43 showModal = true; 44 } 45 46 // Show modal if conditions are met. 47 if(showModal) { 48 var modalClassesArray = ['ctools-use-modal', 'ctools-use-modal-processed', 'ctools-modal-modal-popup-newsletter']; 49 var url = '/modal_forms/nojs/webform/' + NewsletterWebformNid; 50 var link = $("<a></a>").attr('href', url).addClass(modalClassesArray.join(' ')).click(Drupal.CTools.Modal.clickAjaxLink); 51 Drupal.ajax[url] = new Drupal.ajax(url, link.get(0), { url: url, event: 'click', progress: {type: 'throbber'} }); 52 link.click(); 53 54 // Init modal actions. 55 $('.popups-close').once().click(function(){ 56 $.cookie('newsletter_modal_closed', true, { 57 expires : 2, //expires in 2 days 58 path: '/' 59 }); 60 }); 61 } 62 } 63 64 // Listen for OneTrust consent changes 65 function setupConsentListeners() { 66 console.log("Setting up OneTrust consent change listeners"); 67 if (window.OneTrust && OneTrust.OnConsentChanged) { 68 OneTrust.OnConsentChanged(function () { 69 if (checkForSpecificConsent()) { 70 console.log("Consent for group 7 granted. Initializing newsletter modal."); 71 // Ensure Drupal.settings is accessible 72 if (typeof Drupal.settings !== 'undefined') { 73 initializeNewsletterModal(Drupal.settings); 74 } 75 } else { 76 console.log("Consent for group 7 not granted. Newsletter modal will not initialize."); 77 } 78 }); 79 } 80 } 81 82 $(document).ready(function() { 83 setupConsentListeners(); 84 // Immediate check to handle already given consent before script execution 85 if (checkForSpecificConsent() && typeof Drupal.settings !== 'undefined') { 86 initializeNewsletterModal(Drupal.settings); 87 } 88 }); 89 90})(jQuery);
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.