PageSourceSearch

https://www.calderaspas.com/wp-content/plugins/gravityforms-gaddress/js/script-full.js?ver=1790287497

js calderaspas.com collected 2026-09-24 22:17:12 UTC 6,475 bytes, 185 lines download raw bytes

1(function($) {
2  
3  function fillInAddress_f(autoComplete,id,element) {
4    var place = autoComplete.getPlace();
5    clearAddressIfno_f(id,element);
6    var componentForm = {
7      street_number: 'short_name',
8      route: 'long_name',
9      locality: 'long_name',
10      administrative_area_level_1: 'short_name',
11      country: 'long_name',
12      postal_code: 'short_name'
13    };
14
15    // Get each component of the address from the place details
16    // and fill the corresponding field on the form.
17    for (var i = 0; i < place.address_components.length; i++) {
18      var addressType = place.address_components[i].types[0];
19
20      switch(addressType) {
21        case 'locality':
22          $(element).parent().parent().parent().find('#input_' + id + '_3').val(place.address_components[i][componentForm[addressType]]);
23          break;
24        case 'administrative_area_level_1':
25          $(element).parent().parent().parent().find('#input_' + id + '_4').val(place.address_components[i][componentForm[addressType]]);
26          break;
27        case 'country':
28          $(element).parent().parent().parent().find('#input_' + id + '_6').val(place.address_components[i][componentForm[addressType]]);
29          break;
30        case 'postal_code':
31          $(element).parent().parent().parent().find('#input_' + id + '_5').val(place.address_components[i][componentForm[addressType]]);
32          break;
33        case 'street_number':
34          $(element).parent().parent().parent().find('#input_' + id + '_1').val(place.address_components[i][componentForm[addressType]]);
35          break;
36        case 'route':
37          var fullAddress = $(element).parent().parent().parent().find('#input_' + id + '_1').val() + ' ' + place.address_components[i][componentForm[addressType]];
38          $(element).parent().parent().parent().find('#input_' + id + '_1').val(fullAddress);
39          break;
40
41        default:
42          break;
43      }
44
45    }
46  }
47
48  function initialize_f(id) {
49    // var autoCompleteFields = document.getElementById('gca_field_' + id);
50    var autoCompleteFields = {};
51    autoCompleteFields.value = '';
52
53    var options = {
54      componentRestrictions: {'country':['us','ca']},
55      types: ['geocode'] // (cities)
56    };
57
58    let form_id = 'form #gca_field_' + id;
59    if (gaddress_settings[0] && gaddress_settings[0].custom_address) {
60      form_id = `form .address_line_1 #input_${id}_1`;
61    }
62
63    $( form_id ).each(function( index ) {
64      var $this = this;
65      if ( gaddress_settings[0] && ! gaddress_settings[0].custom_address ) {
66        clearAddressIfno_f(id,$this);
67      }
68      autoCompleteFields = new google.maps.places.Autocomplete(this, options);
69      google.maps.event.addListener(autoCompleteFields, 'place_changed', function () {fillInAddress_f(this,id,$this);});
70    });
71  }
72
73  function clearAddressIfno_f(id,element) {
74    for (var i = 1; i < 6; i++) {
75      try {
76        $(element).parent().parent().parent().find('#input_' + id + '_' + i).val('');
77        $(element).parent().parent().parent().find('#input_' + id + '_' + i).prop( "disabled", false );
78      } catch(e) {
79        console.log('Error: ' + e.name + ":" + e.message + "\n" + e.stack); // (3) <--
80      }
81    }
82  }
83
84  jQuery(document).on('gform_post_render', function(event, formId) {
85    let error_field = jQuery(this).find('.custom_address_fields.gfield_error')
86    console.log(error_field);
87    const get_errors = getErrorMessages();
88    if ( error_field.length > 0 ) {
89      window.dataLayer = window.dataLayer || [];
90      let data = {
91        'event': 'GF_validation_error',
92        'formId': formId,
93        'field_value': get_errors.field_value,
94        'error_message': get_errors.error_message
95      };
96      window.dataLayer.push(data);
97    }
98  });
99
100  $(document).ready(function () {
101    if( typeof(gaddress_settings) === 'undefined' ){
102      return;
103    }
104    $.each(gaddress_settings, function( i, gaddress_setting ) {
105      $.each(gaddress_setting.fields, function( k, v ) {
106        $('form #field_'+v.id).each(function() {
107          $( this );
108          if ( gaddress_setting.custom_address ) {
109            $(this).find('.ginput_address_country option').each(function() {
110                if ($(this).val() !== 'United States' && $(this).val() !== 'Canada') {
111                    $(this).remove();
112                }
113            });
114            // $(this).find('.validation_message').not(":eq(0)").hide();
115          } else {
116            $(this).find('.ginput_container').hide();
117          }
118          if ( ! gaddress_setting.custom_address ) {
119            var div = document.createElement('div');
120            div.innerHTML = '<div class="ginput_container ginput_container_text"><input name="google_customer_address_input" tabindex="4" id="gca_field_'+v.id+'" type="text" value="" placeholder="'+gaddress_setting.placeholder+'" class="medium google_customer_address_input" ></div>';
121            $(this).prepend(div);
122          }
123          initialize_f(v.id);
124        });
125      });
126    });
127  });
128})(jQuery);
129
130
131function getErrorMessages() {
132  const errorClasses = [
133    'address_line_1',
134    'address_route',
135    'address_city',
136    'address_state',
137    'address_zip',
138    'postal_code_suffix',
139    'address_country'
140    ];
141
142  const inputClasses = [
143    'address_line_1',
144    'address_city',
145    'address_state',
146    'address_zip',
147    ];
148
149  const errorMessages = {};
150  const getInputValues = [];
151
152  errorClasses.forEach((errorClass) => {
153    const elements = jQuery(`.gfield_validation_message .custom-address-error`).first().find(`.${errorClass}`);
154    elements.each(function(index) {
155      const text = jQuery(this).text().trim();
156      if (errorMessages[errorClass]) {
157        errorMessages[`${errorClass}_${index + 1}`] = text;
158      } else {
159        errorMessages[errorClass] = text;
160      }
161    });
162
163  });
164
165  const parentElement = jQuery(`.custom_address_fields.gfield--type-address.gfield_error`).first();
166  inputClasses.forEach((errorClass) => {
167    getInputValues.push(jQuery(parentElement).find(`span.${errorClass} input`).val());
168  });
169
170  const custom_errors = jQuery('.custom-address-error').first().find('.js-copy-error').map(function() {
171    return jQuery(this).text().trim();
172  }).get().join(', ');
173
174  let error_message = '';
175  if ( custom_errors ) {
176    error_message = custom_errors
177  } else {
178    error_message = Object.keys(errorMessages).join(', ');
179  }
180
181  return {
182    error_message: error_message,
183    field_value: getInputValues.join(', ')
184  };
185}

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.