PageSourceSearch

https://cdn.blueironip.com/wp-content/themes/blueironip-steel/assets/js/newsletter.js?ver=1779825203

js blueironip.com collected 2026-09-25 20:30:11 UTC 3,098 bytes, 93 lines download raw bytes

1/**
2 * BlueIron Newsletter — AJAX signup form handler.
3 *
4 * Listens for submit events on any <form class="bi-newsletter-form">,
5 * POSTs the email to /wp-json/blueiron/v1/newsletter-subscribe, and
6 * surfaces the response in a sibling .bi-newsletter-status element.
7 *
8 * Required markup:
9 *   <form class="bi-newsletter-form" data-endpoint="...">
10 *     <input type="email" name="email" required />
11 *     <button type="submit">Subscribe</button>
12 *     <p class="bi-newsletter-status" role="status" aria-live="polite"></p>
13 *   </form>
14 *
15 * The data-endpoint attribute is set by PHP via wp_localize_script so the
16 * REST URL is correct on multisite/staging environments.
17 */
18
19(function () {
20	'use strict';
21
22	function bind(form) {
23		if (form.dataset.biBound === '1') return;
24		form.dataset.biBound = '1';
25
26		var status = form.querySelector('.bi-newsletter-status');
27		var button = form.querySelector('button[type="submit"]');
28		var input  = form.querySelector('input[type="email"]');
29		var endpoint = form.dataset.endpoint
30			|| (window.BlueIronNewsletter && window.BlueIronNewsletter.endpoint)
31			|| '/wp-json/blueiron/v1/newsletter-subscribe';
32
33		function setStatus(text, kind) {
34			if (!status) return;
35			status.textContent = text || '';
36			status.classList.remove('is-error', 'is-success', 'is-pending');
37			if (kind) status.classList.add('is-' + kind);
38		}
39
40		form.addEventListener('submit', function (e) {
41			e.preventDefault();
42			var email = (input && input.value || '').trim();
43			if (!email) {
44				setStatus('Please enter an email address.', 'error');
45				return;
46			}
47
48			if (button) {
49				button.disabled = true;
50				button.dataset.originalLabel = button.dataset.originalLabel || button.textContent;
51				button.textContent = 'Sending…';
52			}
53			setStatus('', 'pending');
54
55			fetch(endpoint, {
56				method: 'POST',
57				credentials: 'same-origin',
58				headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
59				body: JSON.stringify({ email: email })
60			})
61				.then(function (r) { return r.json().then(function (b) { return { status: r.status, body: b }; }); })
62				.then(function (res) {
63					var body = res.body || {};
64					if (res.status >= 200 && res.status < 300 && body.success) {
65						setStatus(body.message || 'Check your email to confirm.', 'success');
66						if (input) input.value = '';
67					} else {
68						setStatus(body.message || 'Subscription failed. Please try again.', 'error');
69					}
70				})
71				.catch(function () {
72					setStatus("Couldn't reach the server. Please try again in a moment.", 'error');
73				})
74				.then(function () {
75					if (button) {
76						button.disabled = false;
77						button.textContent = button.dataset.originalLabel || 'Subscribe →';
78					}
79				});
80		});
81	}
82
83	function init() {
84		var forms = document.querySelectorAll('form.bi-newsletter-form');
85		Array.prototype.forEach.call(forms, bind);
86	}
87
88	if (document.readyState === 'loading') {
89		document.addEventListener('DOMContentLoaded', init);
90	} else {
91		init();
92	}
93})();

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.