PageSourceSearch

https://leadbites.com/wp-content/plugins/woo-mailerlite/public/js/woo-mailerlite-public.js?ver=3.1.26

js leadbites.com collected 2026-10-09 21:37:43 UTC 7,600 bytes, 212 lines download raw bytes

1jQuery(document).ready(function(a) {
2    const allowedInputs = [
3        'billing_email',
4        'billing_first_name',
5        'email',
6        'billing_last_name',
7        'woo_ml_subscribe',
8        'billing-first_name',
9        'billing-last_name',
10        'shipping-first_name',
11        'shipping-last_name'
12    ];
13    let email = null;
14    let firstName = null;
15    let lastName = null;
16    let foundEmail = false;
17    let checkboxAdded = false;
18    let mailerLiteCheckoutBlockActive = null;
19    let listeningEvents = false;
20    let iteratorInterrupt = 0;
21
22    // temporarily forcefully picking this js not blocks one
23    window.mailerlitePublicJsCaptured = true;
24
25    if (wooMailerLitePublicData.checkboxSettings.enabled && document.body.classList.contains('woocommerce-checkout')) {
26        triggerAddEvents();
27    }
28
29    var execute;
30
31    if (wooMailerLitePublicData.checkboxSettings.preselect) {
32        jQuery('#woo_ml_subscribe').prop('checked', true);
33    }
34
35    if (wooMailerLitePublicData?.checkboxSettings?.enabled) {
36        let retryCount = 0;
37        const maxRetries = 20;
38
39        const interval = setInterval(() => {
40            const inputFound = allowedInputs.some(id => document.getElementById(id));
41
42            if (inputFound) {
43                triggerAddEvents();
44                clearInterval(interval);
45            } else if (++retryCount >= maxRetries) {
46                clearInterval(interval);
47            }
48        }, 500);
49    }
50
51    function triggerAddEvents() {
52        iteratorInterrupt++;
53        if (iteratorInterrupt >= 5) {
54            return false;
55        }
56        const mailerLiteCheckoutBlockWrapper = document.querySelector('[data-block-name="mailerlite-block/woo-mailerlite"]');
57
58        if (mailerLiteCheckoutBlockWrapper && mailerLiteCheckoutBlockWrapper.querySelector('#woo_ml_subscribe')) {
59            mailerLiteCheckoutBlockActive = true;
60        }
61
62        if (listeningEvents && (checkboxAdded || (mailerLiteCheckoutBlockActive !== null && mailerLiteCheckoutBlockActive))) {
63            return false;
64        }
65
66        allowedInputs.forEach((val) => {
67            if (!foundEmail && val.match('email')) {
68                email = document.querySelector('#' + val)
69                if (email) {
70                    foundEmail = true;
71                }
72            }
73
74            if (val.match('first_name')) {
75                if (document.querySelector('#' + val)) {
76                    firstName = document.querySelector('#' + val);
77                }
78            }
79            if (val.match('last_name')) {
80                if (document.querySelector('#' + val)) {
81                    lastName = document.querySelector('#' + val);
82                }
83            }
84        });
85
86        let signup = document.getElementById('woo_ml_subscribe');
87
88        if (email !== null && !signup) {
89            const checkboxWrapper = document.createElement('div');
90            checkboxWrapper.className = 'woo-ml-subscribe-wrapper';
91            checkboxWrapper.style.marginTop = '1rem';
92            const wooMlCheckoutCheckbox = document.createElement('input');
93            wooMlCheckoutCheckbox.setAttribute('id', 'woo_ml_subscribe');
94            wooMlCheckoutCheckbox.setAttribute('type', 'checkbox');
95            wooMlCheckoutCheckbox.setAttribute('name', 'woo_ml_subscribe');
96            wooMlCheckoutCheckbox.setAttribute('value', wooMailerLitePublicData.checkboxSettings.preselect ? 1 : 0);
97            if (wooMailerLitePublicData.checkboxSettings.preselect) {
98                wooMlCheckoutCheckbox.setAttribute('checked', 'checked');
99            }
100
101            const label = document.createElement('label');
102            label.style.cursor = 'pointer';
103            label.style.display = 'inline-flex';
104            label.style.alignItems = 'center';
105            label.style.gap = '0.5rem';
106            label.htmlFor = 'woo_ml_subscribe';
107            if (wooMailerLitePublicData.checkboxSettings.hidden) {
108                label.style.display = 'none';
109            }
110
111            const labelText = document.createElement('span');
112            labelText.textContent = wooMailerLitePublicData.checkboxSettings.label ?? 'Yes, I want to re
112ceive your newsletter.';
113
114            label.appendChild(wooMlCheckoutCheckbox);
115            label.appendChild(labelText);
116            checkboxWrapper.appendChild(label);
117            if (wooMailerLitePublicData.checkboxSettings.hidden) {
118                wooMlCheckoutCheckbox.setAttribute('type', 'hidden');
119            }
120
121            const wrapper = email.closest('div') ?? email;
122            wrapper.parentNode.insertBefore(checkboxWrapper, wrapper.nextSibling);
123            signup = document.getElementById('woo_ml_subscribe');
124            checkboxAdded = true;
125        }
126
127        if (email !== null && !listeningEvents) {
128            listeningEvents = true;
129
130            document.addEventListener('change', (event) => {
131                if (event.target && event.target.matches('input[name="billing_email"]')) {
132                    validateMLSub(event);
133                }
134            });
135
136            email.addEventListener('change', (event) => {
137                validateMLSub(event);
138            });
139
140            if (firstName !== null) {
141                firstName.addEventListener('change', (event) => {
142                    if (firstName.value.length > 0) {
143                        validateMLSub(event);
144                    }
145                });
146            }
147
148            if (lastName !== null) {
149                lastName.addEventListener('change', (event) => {
150                    if (lastName.value.length > 0) {
151                        validateMLSub(event);
152                    }
153                });
154            }
155
156            if (signup !== null) {
157                a(document).on('change', signup, function(event) {
158                    if (event.target.id === 'woo_ml_subscribe') {
159                        validateMLSub(event);
160                    }
161                });
162            }
163        }
164    }
165
166    function validateMLSub(e) {
167        if (email !== null && email.value.length > 0) {
168            checkoutMLSub(e);
169        }
170    }
171
172    function checkoutMLSub(e) {
173        clearTimeout(execute);
174        execute = setTimeout(() => {
175            if (!allowedInputs.includes(e.target.id)) {
176                return false;
177            }
178
179            if (!getCookie('mailerlite_checkout_token')) {
180                var now = new Date();
181                now.setTime(now.getTime() + 48 * 3600 * 1000);
182                document.cookie = `mailerlite_checkout_token=${(+new Date).toString()}; expires=${now.toUTCString()}; path=/`;
183            }
184
185            const accept_marketing = document.querySelector('#woo_ml_subscribe').checked;
186
187            jQuery.ajax({
188                url: wooMailerLitePublicData.ajaxUrl,
189                type: "post",
190                data: {
191                    action: "woo_mailerlite_set_cart_email",
192                    nonce: wooMailerLitePublicData.nonce,
193                    email: email.value ?? null,
194                    signup: accept_marketing,
195                    language: wooMailerLitePublicData.language,
196                    name: firstName?.value ?? '',
197                    last_name: lastName?.value ?? '',
198                    cookie_mailerlite_checkout_token: getCookie('mailerlite_checkout_token')
199                }
200            });
201        }, 2);
202    }
203});
204
205function getCookie(name) {
206    const value = `; ${document.cookie}`;
207    const parts = value.split(`; ${name}=`);
208    if (parts.length === 2) {
209        return parts.pop().split(';').shift()
210    }
211    return null;
212}

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.