PageSourceSearch

https://indacloud.co/wp-content/plugins/blotout-edgetag/public/js/tags/wcbe-address-tag.js

js indacloud.co collected 2026-10-01 14:00:12 UTC 4,183 bytes, 154 lines download raw bytes

1jQuery(document).ready(function ($) {
2  let lastSentFinalData = {}
3  const destination = currentAddressPage.siteData.url
4
5  if (currentAddressPage.page) {
6    $(document).on(
7      'blur change',
8      '.woocommerce-checkout input, .woocommerce-checkout select',
9      sendAddressValues
10    )
11  }
12
13  function sendAddressValues() {
14    const billingFieldData = {
15      firstName: {
16        field: $('#billing_first_name,#billing-first_name'),
17        required: isFieldRequired($('#billing_first_name,#billing-first_name')),
18      },
19      lastName: {
20        field: $('#billing_last_name,#billing-last_name'),
21        required: isFieldRequired($('#billing_last_name,#billing-last_name')),
22      },
23      email: {
24        field: $('#billing_email,#email'),
25        required: isFieldRequired($('#billing_email,#email')),
26      },
27      phone: {
28        field: $('#billing_phone,#billing-phone'),
29        required: isFieldRequired($('#billing_phone,#billing-phone')),
30      },
31      city: {
32        field: $('#billing_city,#billing-city'),
33        required: isFieldRequired($('#billing_city,#billing-city')),
34      },
35      state: {
36        field: $('#billing_state,#billing-state'),
37        required: isFieldRequired($('#billing_state,#billing-state')),
38      },
39      country: {
40        field: $('#billing_country,#billing-country'),
41        required: isFieldRequired($('#billing_country,#billing-country')),
42      },
43    }
44
45    const shippingFieldData = {
46      firstName: {
47        field: $('#shipping_first_name,#shipping-first_name'),
48        required: isFieldRequired(
49          $('#shipping_first_name,#shipping-first_name')
50        ),
51      },
52      lastName: {
53        field: $('#shipping_last_name,#shipping-last_name'),
54        required: isFieldRequired($('#shipping_last_name')),
55      },
56      phone: {
57        field: $('#shipping_phone,#shipping-phone'),
58        required: isFieldRequired($('#shipping_phone,#shipping-phone')),
59      },
60      city: {
61        field: $('#shipping_city,#shipping-city'),
62        required: isFieldRequired($('#shipping_city,#shipping-city')),
63      },
64      state: {
65        field: $('#shipping_state,#shipping-state'),
66        required: isFieldRequired($('#shipping_state,#shipping-state')),
67      },
68      country: {
69        field: $('#shipping_country,#shipping-country'),
70        required: isFieldRequired($('#shipping_country,#shipping-country')),
71      },
72    }
73
74    const billingData = extractValidData(billingFieldData)
75    const shippingData = extractValidData(shippingFieldData)
76    const finalData = merge(billingData, shippingData)
77
78    if (
79      Object.keys(finalData).length &&
80      !areEqual(finalData, lastSentFinalData) &&
81      (currentAddressPage.page === 'shipping' ||
82        currentAddressPage.page === 'billing' ||
83        currentAddressPage.page === 'checkout')
84    ) {
85      edgetag('data', finalData, {}, { destination })
86      lastSentFinalData = finalData
87      edgetag('tag', 'AddShippingInfo', {}, {}, { destination })
88    }
89  }
90
91  function extractValidData(fields) {
92    const data = {}
93    let anyRequired = false
94
95    for (const key in fields) {
96      const { field, required } = fields[key]
97
98      const val = field.val()?.trim()
99      data[key] = val
100
101      if (required) {
102        anyRequired = true
103        if (!val) {
104          return null
105        }
106      }
107    }
108
109    if (!anyRequired) {
110      return null
111    }
112
113    return data
114  }
115
116  function isFieldRequired(field) {
117    return (
118      field.is('[required],[aria-required]') ||
119      field.closest('p').hasClass('validate-required')
120    )
121  }
122
123  function areEqual(a, b) {
124    const aKeys = Object.keys(a)
125    const bKeys = new Set(Object.keys(b))
126    if (aKeys.length !== bKeys.size) {
127      return false
128    }
129
130    for (const key of aKeys) {
131      if (!bKeys.has(key) || a[key] !== b[key]) {
132        return false
133      }
134    }
135
136    return true
137  }
138
139  function merge(a, b) {
140    const result = {}
141
142    for (const obj of [a, b]) {
143      if (obj && typeof obj == 'object') {
144        for (const [key, value] of Object.entries(obj)) {
145          if (value) {
146            result[key] = value
147          }
148        }
149      }
150    }
151
152    return result
153  }
154})

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.