1(function ($, Drupal, drupalSettings) { 2 3 var _modalStatus = '#NewsletterModalStatus'; 4 var _loader = '#NewsletterSignupModalLoader'; 5 var _modal = '#NewsletterSignupModal'; 6 var _cookieN = 'noShowNewsletterModal'; 7 var _cookieV = 'visitCount'; 8 var _formId = '#NewsletterSignupModalForm'; 9 10 /** 11 * Get the value of a cookie by name. 12 */ 13 function getCookieValue(cookieName) { 14 // Get all cookies as a single string 15 const cookies = document.cookie; 16 17 // Split cookies into individual "name=value" pairs 18 const cookieArray = cookies.split(';'); 19 20 // Look for the requested cookie 21 for (let i = 0; i < cookieArray.length; i++) { 22 const cookie = cookieArray[i].trim(); 23 24 // Check if this cookie starts with the name we're looking for 25 if (cookie.indexOf(cookieName + '=') === 0) { 26 // Return the value portion of the cookie 27 return cookie.substring(cookieName.length + 1); 28 } 29 } 30 31 // Return null if cookie not found 32 return null; 33 } 34 35 /** 36 * Set a cookie with a specified name, value, and expiration in days. 37 */ 38 function setCookieValue(name, value, days) { 39 // Create a date object for the expiration 40 const date = new Date(); 41 42 // Set the expiration date (current time + specified days) 43 // If days parameter is not provided, cookie will expire when browser is closed 44 if (days) { 45 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 46 var expires = "; expires=" + date.toUTCString(); 47 } else { 48 var expires = ""; 49 } 50 51 // Set the cookie with name, value, expiration, and path 52 document.cookie = name + "=" + value + expires + "; path=/"; 53 } 54 55 Drupal.behaviors.urbanizeNewsletterSignupModal = { 56 attach: function (context, settings) { 57 if (context == document) { 58 var modal_shown = false; 59 // Use cookies to determine whether to show the newsletter signup 60 var visits = getCookieValue(_cookieV) || 0; visits++; 61 setCookieValue(_cookieV, visits, 1); 62 63 var $document = $(document); 64 65 // Check for URL parameter to force modal display (for testing) 66 var urlParams = new URLSearchParams(window.location.search); 67 if (urlParams.get('showmodal') === '1') { 68 $(_modal).modal('show'); 69 modal_shown = true; 70 } 71 72 $document.scroll(function () { 73 if ($document.scrollTop() > 1024 && modal_shown == false) { 74 if (!getCookieValue(_cookieN)) { 75 if (getCookieValue(_cookieV) <= 1) { 76 $(_modal).modal('show'); 77 modal_shown = true; 78 } 79 } 80 } 81 }); 82 83 $(_formId).on('submit', function (e) { 84 e.preventDefault(); 85 86 var form = $(this); 87 88 form.hide(); 89 $(_loader).show(); 90 $.ajax({ 91 url: '/api/v1/newsletter', 92 method: 'GET', 93 data: form.serialize(), 94 success: function (response) { 95 // Process new subscriber 96 $(_loader).hide(); 97 if (response.type == 'info') { 98 $(_modalStatus).addClass('info').append('Success!<br/>Thanks for subscribing.'); 99 } 100 else { 101 $(_modalStatus).addClass('error').append('Something went wrong...please try again later.<br/>Or you already subscribed.'); 102 } 103 }, 104 error: function (response) { 105 $(_loader).hide(); 106 $(_modalStatus).addClass('error').append('Something went wrong...please try again later.'); 107 } 108 }); 109 110 }); 111 112 $(_formId).find('.noShowWelcome').click(function (e) { 113 $(_modal).modal('hide'); 114 setCookieValue(_cookieN, 1, 365); 115 }); 116 } 117 } 118 }; 119 120})(jQuery, Drupal, drupalSettings);
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.