PageSourceSearch

https://wp.harpers.org/wp-content/themes/timber/static/js/constant-contact.42b2c06c.js

js harpers.org collected 2026-09-24 08:29:18 UTC 4,450 bytes, 143 lines download raw bytes

1"use strict";
2
3var ccValidateEmail = function ccValidateEmail(sEmail) {
4  var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
5  return filter.test(sEmail);
6};
7
8// Constant contact
9var ccSubmitEmail = function ccSubmitEmail(form) {
10  //debug;
11  var $form = $(form);
12  var email = $form.find('[name="input_1"]').val();
13  var list_id = $form.find('[name="input_2"]').val();
14  var reqData = {
15    input_1: email,
16    input_2: list_id,
17    field_values: '',
18    source_page: 1,
19    target_page: 0
20  };
21  var honeypotInput = form.querySelector('.gform_validation_container input');
22  if (honeypotInput) {
23    reqData[honeypotInput.name] = honeypotInput.value;
24  }
25
26  // console.log("reqData:", reqData);
27
28  // console.log('email is ' + nag);
29  if (!ccValidateEmail(email)) return false;
30  $.ajax({
31    type: 'POST',
32    url: '/wp-json/gf/v2/forms/3/submissions',
33    data: reqData,
34    success: function success(data) {
35      //alert("data: " + data[1]);
36      //destroy msgbox window
37      //e.preventDefault();
38      // console.log('success submit!');
39
40      // make nag lightbox disappear  (if this came from a nag)
41      $('#issuem-leaky-paywall-articles-remaining-text#p').val('Thank you!');
42      $('#issuem-leaky-paywall-articles-remaining-nag').animate({
43        left: '-110%'
44      }, 500);
45      $form.parent().find('.form-thank-you.d-none').removeClass('d-none');
46    },
47    error: function error(err) {
48      console.log('error: ' + err.toString());
49    }
50  });
51  return false;
52};
53var ccSubmitFreebie = function ccSubmitFreebie(form) {
54  var email = form.querySelector('[name="input_1"]').value;
55  if (!ccValidateEmail(email)) return false;
56  form.querySelectorAll('.form-group').forEach(function (formGroupEl, i) {
57    formGroupEl.classList.add('d-none');
58  });
59  var loadingSpinner = form.querySelector('figure.loading');
60  loadingSpinner.classList.remove('d-none'); //loading
61
62  var listIdCheckboxEls = form.querySelectorAll('[type="checkbox"]:checked'); //multiple
63  var reqData = {
64    input_1: email,
65    field_values: '',
66    source_page: 1,
67    target_page: 0
68  };
69  var honeypotInput = form.querySelector('.gform_validation_container input');
70  if (honeypotInput) {
71    reqData[honeypotInput.name] = honeypotInput.value;
72  }
73
74  //endOfMonth date
75  var endMonthDate = new Date();
76  endMonthDate.setDate(1); /* Avoids edge cases on the 31st day of some months */
77  endMonthDate.setMonth(endMonthDate.getMonth() + 1);
78  endMonthDate.setDate(0);
79  endMonthDate.setHours(23);
80  endMonthDate.setMinutes(59);
81  endMonthDate.setSeconds(59);
82  // Set up and fire the subscribe requests for each checked list
83  requests = [];
84  listIdCheckboxEls.forEach(function (checkboxEl, i) {
85    reqData.input_2 = checkboxEl.value;
86    requests.push($.ajax({
87      method: 'POST',
88      url: '/wp-json/gf/v2/forms/3/submissions',
89      data: reqData,
90      error: function error(err) {
91        console.log('error: ' + err.toString());
92      }
93    }));
94  });
95
96  // Once _all_ signup requests are finished, set cookies, show thanks
97  Promise.all(requests).then(function (values) {
98    Cookies.set('hr_subscribed_' + Date.now(), true, {
99      path: '/',
100      expires: endMonthDate
101    }); // cf pw cookie
102    Cookies.set('hr_freebie_offer', true, {
103      path: '/',
104      expires: 31 * 24 * 60 * 60
105    }); // next freebie offer eligible in a month
106    loadingSpinner.classList.add('d-none');
107
108    //hide form show thank you message
109    form.previousElementSibling.classList.add('d-none'); // the message blurb
110
111    form.nextElementSibling.classList.remove('d-none');
112  })["catch"](function (err) {
113    console.error(err);
114  });
115};
116
117// harper's constant contact email signup
118var ccEmailSignupHelper = function ccEmailSignupHelper() {
119  // simple signup
120  document.querySelectorAll('.form-newsletter-signup').forEach(function (form, i) {
121    //submit usage
122    form.addEventListener('submit', function (e) {
123      // console.log("submit! e: ", e);
124      e.preventDefault();
125      ccSubmitEmail(form);
126    });
127  });
128
129  //freebie article signup
130  document.querySelectorAll('.form-freebie-article-signup').forEach(function (form, i) {
131    form.addEventListener('submit', function (e) {
132      e.preventDefault();
133      ccSubmitFreebie(form);
134    });
135  });
136};
137
138// init within document.ready
139(function ($) {
140  window.addEventListener('load', function () {
141    ccEmailSignupHelper();
142  });
143})(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.