PageSourceSearch

https://www.dormilona.com.au/wp-content/plugins/mailchimp-for-wooc…p-woocommerce-sms-consent.min.js?ver=6.3.02

js dormilona.com.au collected 2026-10-07 15:28:42 UTC 6,130 bytes, 163 lines download raw bytes

1jQuery(document).ready(function($) {
2    var mailchimp,
3        mailchimpReady = function (a) { /in/.test(document.readyState) ? setTimeout(()=>{mailchimpReady(a)}, 9) : a(); };
4
5    function mailchimpHandleSmsConsent(selectors, checked)
6    {
7        console.log('change of sms consent block', {
8            ...selectors,
9            checked: checked
10        })
11        const phoneInput = document.querySelector(selectors.phone);
12
13        if (!phoneInput) {
14            console.log('SMS phone element not found:', selectors.phone);
15            return;
16        }
17
18        setRequired(checked, phoneInput, selectors);
19    }
20
21    function applyPhoneFormatting(phoneInput, selectors) {
22        if (window.libphonenumber) {
23            console.log('applying phone formatting', phoneInput);
24            const countrySelector = document.querySelector(selectors.country);
25            const selectedCounty = countrySelector?.value || "US";
26            const formatter = new window.libphonenumber.AsYouType(selectedCounty);
27
28            phoneInput.addEventListener("input", (e) => {
29                formatter.reset();
30                e.target.value = formatter.input(e.target.value);
31            });
32
33            phoneInput.addEventListener("blur", () => {
34                const phone = window.libphonenumber.parsePhoneNumberFromString(phoneInput.value, defaultRegion);
35                if (phone?.isValid()) {
36                    console.log("E164:", phone.number);
37                } else {
38                    console.log("Invalid phone number:", phoneInput.value);
39                }
40            });
41        } else {
42            console.log('libphonenumber not found');
43        }
44    }
45
46    function setRequired(required, phoneInput, selectors) {
47        if (!phoneInput) {
48            return;
49        }
50        const phoneRow  = phoneInput.closest(selectors.row);
51        const label     = phoneRow.querySelector(selectors.label);
52
53        phoneInput.required = required;
54        phoneInput.setAttribute('aria-required', required ? 'true' : 'false');
55
56        // Remove existing optional/required span
57        if (label) {
58            const existingSpan = label.querySelector('.optional, .required');
59            if (existingSpan) {
60                existingSpan.remove();
61            }
62        }
63
64        // Create correct span
65        const span = document.createElement('span');
66        span.className = required ? 'required' : 'optional';
67        span.textContent = required ? '*' : '(optional)';
68        if (label) {
69            label.textContent = label.textContent.replace('(optional)', '')
70            label.appendChild(span);
71        }
72
73        // WooCommerce validation class
74        phoneRow.classList.toggle('validate-required', required);
75        phoneRow.classList.remove('woocommerce-invalid', required);
76        phoneRow.classList.remove('woocommerce-invalid-required-field', required);
77
78        // Trigger WC checkout update
79        document.body.dispatchEvent(new Event('update_checkout'));
80
81        applyPhoneFormatting(phoneInput, selectors);
82    }
83
84    function validateSmsConsent(selectors)
85    {
86        const countrySelector = document.querySelector(selectors.country);
87
88        if (!countrySelector) {
89            console.error('Element not found:', selectors.country);
90            return;
91        }
92
93        validateCountry(countrySelector.value, selectors)
94
95        countrySelector.addEventListener('change', (e) => {
96            const value = e.target.value;
97
98            validateCountry(value, selectors)
99        });
100
101        $(selectors.country).on('change', function (e) {
102            const value = e.target.value;
103
104            validateCountry(value, selectors)
105        });
106    }
107
108    function validateCountry(country, selectors) {
109        const phoneInput = document.querySelector(selectors.phone)
110
111        if (mailchimp_public_data.sms_allowed_countries.includes(country)) {
112            setRequired($(selectors.checkbox).is(':checked'), phoneInput, selectors)
113            $(selectors.checkbox).closest('.form-row').show()
114            console.log('country', selectors.checkbox, $(selectors.checkbox).is(':checked'))
115        } else {
116            setRequired(false, phoneInput, selectors)
117            $(selectors.checkbox).prop('checked', false);
118            $(selectors.checkbox).closest('.form-row').hide()
119        }
120    }
121
122    mailchimpReady(function () {
123        // if they've told us we can't do this - we have to honor it.
124        if (!mailchimp_public_data.allowed_to_set_cookies) return;
125
126        // if we're not using carts - don't bother setting any of this.
127        if (mailchimp_public_data.disable_carts) return;
128
129        var smsConsent = document.querySelector('#mailchimp_woocommerce_sms_consent');
130        var blockSmsConsent = document.querySelector("#subscribe-to-sms");
131
132        if (smsConsent) {
133            let selectors = {
134                country: '#billing_country',
135                checkbox: '#mailchimp_woocommerce_sms_consent',
136                phone: '#billing_phone',
137                row: '.form-row',
138                label: 'label'
139            }
140            validateSmsConsent(selectors)
141            smsConsent.onchange = function(e) {
142                mailchimpHandleSmsConsent(selectors, e.target.checked);
143            }
144        } else if (blockSmsConsent) {
145            //let phoneSelector = document.querySelector('#billing_phone') ? '#billing-phone' : '#shipping-phone'
146            // let phoneSelector = '#mailchimp-sms-phone';
147            // let countrySelector = document.querySelector('#billing_country') ? '#billing-country' : '#shipping-country'
148            //
149            // let selectors = {
150            //     country: countrySelector,
151            //     checkbox: '#subscribe-to-sms',
152            //     phone: phoneSelector,
153            //     row: '.wc-block-components-text-input',
154            //     label: 'label'
155            // }
156            // validateSmsConsent(selectors)
157            //
158            // blockSmsConsent.onchange = function(e) {
159            //     mailchimpHandleSmsConsent(selectors,  e.target.checked);
160            // }
161        }
162    })
163})

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.