1window.naFlyoutCookies = window.naFlyoutCookies || ( function () { 2 function setCookie( name, value, days ) { 3 let expires = ''; 4 if ( days ) { 5 const date = new Date(); 6 date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) ); 7 expires = '; expires=' + date.toUTCString(); 8 } 9 document.cookie = name + '=' + encodeURIComponent( value ) + expires + '; path=/'; 10 } 11 12 function getCookie( name ) { 13 const parts = document.cookie.split( '; ' ); 14 for ( let i = 0; i < parts.length; i++ ) { 15 const pair = parts[i].split( '=' ); 16 if ( pair[0] === name ) { 17 return decodeURIComponent( pair[1] || '' ); 18 } 19 } 20 return ''; 21 } 22 23 function hasCookie( name ) { 24 return getCookie( name ) !== ''; 25 } 26 27 function subscribedKey( flyout_id ) { 28 return 'na_flyout_subscribed_' + ( flyout_id || 'global' ); 29 } 30 31 function dismissedKey( flyout_id ) { 32 return 'na_flyout_dismissed_' + ( flyout_id || 'global' ); 33 } 34 35 function setSubscribed( flyout_id ) { 36 setCookie( subscribedKey( flyout_id ), '1', 3650 ); 37 } 38 39 function setDismissed( flyout_id ) { 40 setCookie( dismissedKey( flyout_id ), '1', 30 ); 41 } 42 43 return { 44 setCookie: setCookie, 45 getCookie: getCookie, 46 hasCookie: hasCookie, 47 subscribedKey: subscribedKey, 48 dismissedKey: dismissedKey, 49 setSubscribed: setSubscribed, 50 setDismissed: setDismissed, 51 }; 52} )(); 53 54document.addEventListener( 'DOMContentLoaded', function () { 55 56 const forms = document.querySelectorAll( '[data-mailchimp-form]' ); 57 58 if ( ! forms.length ) { 59 return; 60 } 61 62 function setFlyoutSubscribedCookie( form ) { 63 const flyout = form.closest( '[data-flyout-id]' ); 64 if ( ! flyout ) { 65 return; 66 } 67 const flyout_id = flyout.dataset.flyoutId || 'global'; 68 window.naFlyoutCookies.setSubscribed( flyout_id ); 69 } 70 71 forms.forEach( function ( form ) { 72 form.addEventListener( 'submit', function ( e ) { 73 74 e.preventDefault(); 75 76 const submit_button = form.querySelector( 'button[type="submit"]' ); 77 const success_div = form.querySelector( '[data-success-message]' ) || document.querySelector( '#success_message' ); 78 const error_div = form.querySelector( '[data-error-message]' ) || document.querySelector( '#error_message' ); 79 const message_div = form.querySelector( '[data-form-message]' ); 80 const has_external_feedback = Boolean( success_div || error_div ); 81 82 if ( submit_button ) { 83 submit_button.disabled = true; 84 } 85 86 const form_data = new FormData( form ); 87 const selected = form.querySelectorAll( 'input[name="tags[]"]:checked' ); 88 89 if ( ! form_data.has( 'tags[]' ) ) { 90 if ( selected.length ) { 91 selected.forEach( function ( input ) { 92 form_data.append( 'tags[]', input.value ); 93 } ); 94 } else { 95 const tag_input = form.querySelector( 'input[name="tag"]' ); 96 if ( tag_input && tag_input.value ) { 97 form_data.append( 'tags[]', tag_input.value ); 98 } 99 } 100 } 101 102 if ( ! form_data.get( 'name' ) ) { 103 const email_value = form_data.get( 'email' ); 104 if ( email_value ) { 105 form_data.append( 'name', String( email_value ).split( '@' )[0] ); 106 } 107 } 108 109 form_data.append( 'action', 'mailchimp_subscribe' ); 110 form_data.append( 'nonce', na_mailchimp.nonce ); 111 112 if ( message_div ) { 113 message_div.style.display = 'none'; 114 message_div.textContent = ''; 115 } 116 117 fetch( na_mailchimp.ajax_url, { 118 method: 'POST', 119 body: form_data, 120 credentials: 'same-origin' 121 } ) 122 .then( function ( response ) { 123 return response.json(); 124 } ) 125 .then( function ( result ) { 126 127 if ( result.success ) { 128 129 if ( message_div ) { 130 message_div.textContent = result.data && result.data.message ? result.data.message : 'Success! If this is your first time subscribing, check your email to confirm your address.'; 131 message_div.style.display = 'block'; 132 } 133 134 setFlyoutSubscribedCookie( form ); 135 136 if ( has_external_feedback ) { 137 form.style.display = 'none'; 138 } 139 if ( success_div ) { 140 success_div.style.display = 'block'; 141 } 142 143 return; 144 } 145 146 if ( message_div ) { 147 message_div.textContent = result.data && result.data.message ? result.data.message : 'Something went wrong. Please try again.'; 148 message_div.style.display = 'block'; 149 } 150 151 if ( submit_button ) { 152 submit_button.disabled = false;
153 } 154 155 if ( has_external_feedback ) { 156 form.style.display = 'none'; 157 } 158 if ( error_div ) { 159 error_div.style.display = 'block'; 160 } 161 162 } ) 163 .catch( function () { 164 165 if ( message_div ) { 166 message_div.textContent = 'Something went wrong. Please try again.'; 167 message_div.style.display = 'block'; 168 } 169 170 if ( submit_button ) { 171 submit_button.disabled = false; 172 } 173 174 if ( has_external_feedback ) { 175 form.style.display = 'none'; 176 } 177 178 if ( error_div ) { 179 error_div.style.display = 'block'; 180 } 181 182 } ); 183 184 } ); 185 } ); 186 187} );
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.