1/* global document, fetch, FormData, window */ 2;(function initHomeSubscribe() { 3 'use strict' 4 5 var form = document.querySelector('[data-home-subscribe]') 6 if (!form) return 7 8 var content = form.closest('.idx-hero-content') 9 var status = content && content.querySelector('.home-hero-signup-status') 10 var confirmation = form.parentElement.querySelector('[data-home-subscribe-confirmation]') 11 var button = form.querySelector('button[type="submit"]') 12 var defaultButtonText = button.textContent 13 14 form.addEventListener('submit', function (event) { 15 event.preventDefault() 16 if (!form.reportValidity()) return 17 18 button.disabled = true 19 button.textContent = 'Subscribingâ¦' 20 form.classList.add('is-loading') 21 if (status) { 22 status.className = 'home-hero-signup-status' 23 status.textContent = 'Adding youâ¦' 24 } 25 26 fetch(form.action, { 27 method: 'POST', 28 body: new FormData(form), 29 headers: { Accept: 'application/json' }, 30 }) 31 .then(function (response) { 32 return response.json().then(function (payload) { 33 if (!response.ok) throw new Error(payload.error || 'Subscription failed') 34 return payload 35 }) 36 }) 37 .then(function (payload) { 38 form.hidden = true 39 form.setAttribute('inert', '') 40 if (confirmation) { 41 var confirmationCopy = confirmation.querySelector('span') 42 if (confirmationCopy) { 43 confirmationCopy.textContent = payload.message || 'Youâre subscribed. See you Friday.' 44 } 45 confirmation.hidden = false 46 confirmation.focus({ preventScroll: true }) 47 } 48 if (status) { 49 status.textContent = 'Free every Friday · Unsubscribe anytime' 50 status.classList.add('is-success') 51 } 52 if (typeof window.gtag === 'function') { 53 window.gtag('event', 'newsletter_optin_started', { 54 signup_source: 'homepage-hero', 55 }) 56 } 57 }) 58 .catch(function (error) { 59 button.disabled = false 60 button.textContent = defaultButtonText 61 if (status) { 62 status.textContent = error.message || 'Something went wrong. Please try again.' 63 status.classList.add('is-error') 64 } 65 }) 66 .finally(function () { 67 form.classList.remove('is-loading') 68 }) 69 }) 70})()
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.