PageSourceSearch

https://demo.restropress.com/grocery-store/wp-content/plugins/rest…/assets/js/frontend/rp-ajax.js?ver=3.4.6

js restropress.com collected 2026-09-25 09:00:46 UTC 15,343 bytes, 363 lines download raw bytes

1var rpress_scripts;
2jQuery(document)
3  .ready(function ($) {
4    // Hide un-necessary elements. These are things that are required in case JS breaks or isn't present
5    $('.rpress-no-js')
6      .hide();
7    //Hide delivery error when switch tabs
8    $('body')
9      .on('click', '.rpress-delivery-options li.nav-item', function (e) {
10        e.preventDefault();
11        $(this)
12          .parents('.rpress-delivery-wrap')
13          .find('.rpress-order-time-error')
14          .addClass('hide');
15      });
16    // Show the login form on the checkout page
17    $('#rpress_checkout_form_wrap')
18      .on('click', '.rpress_checkout_register_login', function () {
19        var $this = $(this);
20        $this.addClass('rp-loading')
21        $this.find('.rp-ajax-toggle-text')
22          .addClass('rp-text-visibility')
23        payment_form = $('#rpress_payment_mode_select_wrap,#rpress_purchase_form_wrap');
24        ajax_loader = '<span class="rpress-loading-ajax rpress-loading"></span>';
25        data = {
26          action: $this.data('action'),
27          security: rpress_scripts.checkout_nonce
28        };
29        payment_form.hide();
30        $.post(rpress_scripts.ajaxurl, data, function (checkout_response) {
31          $('#rpress_checkout_login_register')
32            .html(rpress_scripts.loading);
33          $('#rpress_checkout_login_register')
34            .html(checkout_response);
35          // Hide the ajax loader
36          $('.rpress-cart-ajax')
37            .hide();
38          $this.removeClass('rp-loading')
39          $this.find('.rp-ajax-toggle-text')
40            .removeClass('rp-text-visibility')
41          //Show the payment form
42          if (data.action == 'rpress_checkout_register')
43            payment_form.show();
44        });
45        return false;
46      });
47    // Process the login form via ajax
48    $(document)
49      .on('click', '#rpress_purchase_form #rpress_login_fields input[type=submit]', function (e) {
50        e.preventDefault();
51        var complete_purchase_val = $(this)
52          .val();
53        $(this)
54          .val(rpress_global_vars.purchase_loading);
55        $(this)
56          .after('<span class="rp-loading"></span>');
57        var data = {
58          action: 'rpress_process_checkout_login',
59          rpress_ajax: 1,
60          security: (typeof rpress_global_vars !== 'undefined' ? rpress_global_vars.checkout_nonce : rpress_scripts.checkout_nonce),
61          rpress_user_login: $('#rpress_login_fields #rpress_user_login')
62            .val(),
63          rpress_user_pass: $('#rpress_login_fields #rpress_user_pass')
64            .val()
65        };
66        $.post(rpress_global_vars.ajaxurl, data, function (data) {
67          if ($.trim(data) == 'success') {
68            $('.rpress_errors')
69              .remove();
70            window.location = rpress_scripts.checkout_page;
71          } else {
72            $('#rpress_login_fields input[type=submit]')
73              .val(complete_purchase_val);
74            $('.rp-loading')
75              .remove();
76            $('.rpress_errors')
77              .remove();
78            $('#rpress-user-login-submit')
79              .before(data);
80          }
81        });
82      });
83    // Load the fields for the $this payment method
84    $('select#rpress-gateway, input.rpress-gateway')
85      .change(function (e) {
86        var payment_mode = $('#rpress-gateway option:selected, input.rpress-gateway:checked')
87          .val();
88        if (payment_mode == '0') {
89          return false;
90        }
91        $('#rpress_purchase_form input[name="rpress-gateway"]')
92          .val(payment_mode);
93        rpress_load_gateway(payment_mode);
94        return false;
95      });
96    // Auto load first payment gateway
97    if (rpress_scripts.is_checkout == '1') {
98      var chosen_gateway = false;
99      var ajax_needed = false;
100      if ($('select#rpress-gateway, input.rpress-gateway')
101        .length) {
102        chosen_gateway = $("meta[name='rpress-chosen-gateway']")
103          .attr('content');
104        ajax_needed = true;
105      }
106      if (!chosen_gateway) {
107        chosen_gateway = rpress_scripts.default_gateway;
108      }
109      if (chosen_gateway) {
110        $('#rpress_purchase_form input[name="rpress-gateway"]')
111          .val(chosen_gateway);
112      }
113      if (ajax_needed) {
114        // If we need to ajax in a gateway form, send the requests for the POST.
115        setTimeout(function () {
116          rpress_load_gateway(chosen_gateway);
117        }, 200);
118      } else {
119        // The form is already on page, just trigger that the gateway is loaded so further action can be taken.
120        $('body')
121          .trigger('rpress_gateway_loaded', [chosen_gateway]);
122      }
123    }
124    // Process checkout
125    $(document)
126      .on('click', '#rpress_purchase_form #rpress_purchase_submit [type=submit]', function (e) {
127        var rpressPurchaseform = document.getElementById('rpress_purchase_form');
128        if (typeof rpressPurchaseform.checkValidity === "function" && false === rpressPurchaseform.checkValidity()) {
129          return;
130        }
131        e.preventDefault();
132        var selectedServiceType = '';
133        var selectedServiceTime = '';
134        var selectedServiceTimeText = '';
135        var selectedServiceDate = '';
136        var selectedServiceDateText = '';
137        var $activeServiceTab = $('.rp-checkout-service-option #rpressdeliveryTab .single-service-selected.active, #rpress_checkout_order_details #rpressdeliveryTab .single-service-selected.active')
138          .first();
139        if ($activeServiceTab.length) {
140          selectedServiceType = String($activeServiceTab.data('service-type') || '')
141            .toLowerCase();
142        }
143        if (!selectedServiceType) {
144          selectedServiceType = String(rp_getCookie('service_type') || '')
145            .toLowerCase();
146        }
147        var $checkoutScope = $('.rp-checkout-service-option')
148          .first();
149        if (!$checkoutScope.length) {
150          $checkoutScope = $('#rpress_checkout_order_details')
151            .first();
152        }
153        var $activePane = $();
154        if (selectedServiceType) {
155          $activePane = $checkoutScope.find('.delivery-settings-wrapper#nav-' + selectedServiceType)
156            .first();
157        }
158        if (!$activePane.length) {
159          $activePane = $checkoutScope.find('.delivery-settings-wrapper.active')
160            .first();
161        }
162        if ($activePane.length) {
163          var $serviceTimeSelect = $activePane.find('.rpress-hrs')
164            .first();
165          var $serviceDateSelect = $activePane.find('.rpress_get_delivery_dates')
166            .first();
167          selectedServiceTime = String($serviceTimeSelect.val() || '');
168          selectedServiceTimeText = String($serviceTimeSelect.find('option:selected').text() || selectedServiceTime)
169            .trim();
170          selectedServiceDate = String($serviceDateSelect.val() || '');
171          selectedServiceDateText = String($serviceDateSelect.find('option:selected').text() || selectedServiceDate)
172            .trim();
173        }
174        if (selectedServiceType) {
175          rp_setCookie('service_type', selectedServiceType, rp_scripts.expire_cookie_time);
176        }
177        if (selectedServiceTime) {
178          rp_setCookie('service_time', selectedServiceTime, rp_scripts.expire_cookie_time);
179          rp_setCookie('service_time_text', selectedServiceTimeText || selectedServiceTime, rp_scripts.expire_cookie_time);
180        }
181        if (selectedServiceDate) {
182          rp_setCookie('service_date', selectedServiceDate, rp_scripts.expire_cookie_time);
183          rp_setCookie('delivery_date', selectedServiceDateText || selectedServiceDate, rp_scripts.expire_cookie_time);
184          rp_setCookie('service_date_manual', selectedServiceDate, rp_scripts.expire_cookie_time);
185        }
186        var selectedGateway = $('#rpress-gateway option:selected, input.rpress-gateway:checked')
187          .val();
188        if (selectedGateway && selectedGateway !== '0') {
189          $('#rpress_purchase_form input[name="rpress-gateway"]')
190            .val(selectedGateway);
191        }
192        var $purchaseButton = $(this);
193        var complete_purchase_val = $purchaseButton
194          .val();
195        $purchaseButton
196          .val(rpress_global_vars.purchase_loading);
197        $purchaseButton
198          .prop('disabled', true);
199        $purchaseButton
200          .addClass('rp-purchase-button-loading');
201        $purchaseButton
202          .closest('#rpress_purchase_submit')
203          .addClass('rp-submit-loading')
204          .find('.rp-purchase-loading')
205          .remove();
206        $purchaseButton
207          .after('<span class="rp-loading rp-purchase-loading" aria-hidden="true"></span>');
208        $purchaseButton.parents('body').append('<div class="blur-content"><p class="blur-txt">'+rpress_scripts.blurtxt+'</p><span class="blur-loader"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgb(255, 255, 255); display: block; shape-rendering: auto;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><circle cx="50" cy="50" r="32" stroke-width="8" stroke="#fe718d" stroke-dasharray="50.26548245743669 50.26548245743669" fill="none" stroke-linecap="round"><animateTransform attributeName="transform" type="rotate" repeatCount="indef
208inite" dur="1s" keyTimes="0;1" values="0 50 50;360 50 50"></animateTransform></circle></svg></span></div>');
209        var requestData = $('#rpress_purchase_form')
210          .serialize() + '&action=rpress_process_checkout&rpress_ajax=true';
211        if (selectedGateway && selectedGateway !== '0') {
212          requestData += '&rpress-gateway=' + encodeURIComponent(selectedGateway);
213        }
214        if (selectedServiceType) {
215          requestData += '&rpress_service_type=' + encodeURIComponent(selectedServiceType);
216        }
217        if (selectedServiceTime) {
218          requestData += '&rpress_service_time=' + encodeURIComponent(selectedServiceTime);
219        }
220        if (selectedServiceDate) {
221          requestData += '&rpress_service_date=' + encodeURIComponent(selectedServiceDate);
222        }
223        $.post(rpress_global_vars.ajaxurl, requestData,
224          function (data) {
225            if ($.trim(data) == 'success') {
226              $('.rpress_errors')
227                .remove();
228              $('.rpress-error')
229                .hide();
230                $('#rpress_final_total_wrap .rp-loading').hide();
231              $('.blur-content').hide();
232              $(rpressPurchaseform)
233                .submit();
234            } else {
235              $('#rpress-purchase-button')
236                .val(complete_purchase_val);
237              $('#rpress-purchase-button')
238                .removeClass('rp-purchase-button-loading');
239              $('#rpress_purchase_submit')
240                .removeClass('rp-submit-loading');
241              $('.rp-loading')
242                .remove();
243              $('.rpress_errors')
244                .remove();
245              $('.blur-content').hide();
246              if ($("#rpress_final_total_wrap .rp-loading").length) {
247                  $("#rpress_final_total_wrap .rp-loading").hide();
248                }
249              $('.rpress-error')
250                .hide();
251              $(rpress_global_vars.checkout_error_anchor)
252                .before(data);
253              $('#rpress-purchase-button')
254                .prop('disabled', false);
255              $(document.body)
256                .trigger('rpress_checkout_error', [data]);
257              var $errors = $('.rpress_errors:visible, .rpress-errors-wrap:visible, .rpress-alert-error:visible, .rpress-error:visible').first();
258              if ($errors.length) {
259                var targetTop = Math.max(0, $errors.offset().top - 120);
260                $('html, body').stop().animate({ scrollTop: targetTop }, 400);
261              }
262            }
263          });
264      });
265    // Update state field
266    $(document.body)
267      .on('change', '#rpress_cc_address input.card_state, #rpress_cc_address select, #rpress_address_country', update_state_field);
268    function update_state_field() {
269      var $this = $(this);
270      var $form;
271      var is_checkout = typeof rpress_global_vars !== 'undefined';
272      var field_name = 'card_state';
273      if ($(this)
274        .attr('id') == 'rpress_address_country') {
275        field_name = 'rpress_address_state';
276      }
277      if ('card_state' != $this.attr('id')) {
278        // If the country field has changed, we need to update the state/province field
279        var postData = {
280          action: 'rpress_get_states',
281          country: $this.val(),
282          field_name: field_name,
283          security: (typeof rpress_global_vars !== 'undefined' ? rpress_global_vars.checkout_nonce : rpress_scripts.checkout_nonce),
284        };
285        $.ajax({
286          type: "POST",
287          data: postData,
288          url: rpress_scripts.ajaxurl,
289          xhrFields: {
290            withCredentials: true
291          },
292        })
293          .fail(function (data) {
294            if (window.console && window.console.log) {
295              console.log(data);
296            }
297          })
298          .done(function (data) {
299            if (is_checkout) {
300              var ns = "nostates";
301              if (data != ns) {
302                $("#card_state").parent().show();
303                $("#card_state").replaceWith (data);
304              }
305              else {
306                if (data === ns) {
307                  $("#card_state").parent().hide();
308                }
309              }
310              recalculate_taxes();
311            }
312          });
313      } else {
314        if (is_checkout) {
315          recalculate_taxes();
316        }
317      }
318      return false;
319    }
320    // If is_checkout, recalculate sales tax on postalCode change.
321    $(document.body)
322      .on('change', '#rpress_cc_address input[name=card_zip]', function () {
323        if (typeof rpress_global_vars !== 'undefined') {
324          recalculate_taxes();
325        }
326      });
327    $("#rpressModal")
328      .on('hide.bs.modal', function () {
329        $('.modal-backdrop.in')
330          .remove();
331      });
332  });
333// Load a payment gateway
334function rpress_load_gateway(payment_mode) {
335  // Show the ajax loader
336  jQuery('.rpress-cart-ajax')
337    .show();
338  jQuery('#rpress_purchase_form_wrap')
339    .html('<span class="rpress-loading-ajax rpress-loading"></span>');
340  var url = rpress_scripts.ajaxurl;
341  if (url.indexOf('?') > 0) {
342    url = url + '&';
343  } else {
344    url = url + '?';
345  }
346  url = url + 'payment-mode=' + payment_mode;
347  jQuery('#rpress_purchase_form input[name="rpress-gateway"]')
348    .val(payment_mode);
349  rp_setCookie('payment_mode', payment_mode, rp_scripts.expire_cookie_time);
350  jQuery.post(url, {
351    action: 'rpress_load_gateway',
352    rpress_payment_mode: payment_mode,
353    security: rpress_scripts.load_gateway_nonce
354  },
355    function (response) {
356      jQuery('#rpress_purchase_form_wrap')
357        .html(response);
358      jQuery('.rpress-no-js')
359        .hide();
360      jQuery('body')
361        .trigger('rpress_gateway_loaded', [payment_mode]);
362    });
363}

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.