PageSourceSearch

https://www.isip.foundation/wp-content/plugins/memberpress/js/signup.js?ver=1.11.17

js isip.foundation collected 2026-10-02 00:02:34 UTC 19,775 bytes, 539 lines download raw bytes

1(function($) {
2  $(document).ready(function() {
3    $('body').on('click', '.mepr-signup-form .have-coupon-link', function(e) {
4      e.preventDefault();
5      $(this).hide();
6      $('div.mepr_coupon_'+$(this).data("prdid")).show();
7    });
8
9    $('body').on('keydown', '.mepr-signup-form .mepr-coupon-code', function(e) {
10      if(e.which === 13) {
11        e.preventDefault();
12        $(this).trigger('blur');
13      }
14    });
15
16    // Store the default price string
17    $('.mepr_price_cell').each(function () {
18      $(this).data('default-price-string', $(this).text());
19    });
20
21    let updateCheckoutStateTimeout,
22        lastRequestData,
23        updatingCheckoutState = false,
24        updateCheckoutStateAgain = false,
25        updateCheckoutState = function ($form) {
26          clearTimeout(updateCheckoutStateTimeout);
27
28          updateCheckoutStateTimeout = setTimeout(function () {
29            debouncedUpdateCheckoutState($form);
30          }, 50);
31        },
32        getRequestData = function ($form) {
33          let payment_methods = [];
34
35          $form.find('input[name="mepr_payment_method"]').each(function () {
36            payment_methods.push($(this).val());
37          });
38
39          const data = {
40            action: 'mepr_get_checkout_state',
41            mepr_product_id: $form.find('input[name="mepr_product_id"]').val(),
42            'mepr-address-one': $form.find('input[name="mepr-address-one"]').val(),
43            'mepr-address-two': $form.find('input[name="mepr-address-two"]').val(),
44            'mepr-address-city': $form.find('input[name="mepr-address-city"]').val(),
45            'mepr-address-state': $form.find('select[name="mepr-address-state"]').is(':visible') ? $form.find('select[name="mepr-address-state"]').val() : $form.find('input[name="mepr-address-state"]').val(),
46            'mepr-address-country': $form.find('select[name="mepr-address-country"]').val(),
47            'mepr-address-zip': $form.find('input[name="mepr-address-zip"]').val(),
48            mepr_vat_number: $form.find('input[name="mepr_vat_number"]').val(),
49            mepr_vat_customer_type: $form.find('input[name="mepr_vat_customer_type"]:checked').val(),
50            mepr_coupon_code: $form.find('input[name="mepr_coupon_code"]').val(),
51            mepr_coupon_nonce: MeprSignup.coupon_nonce,
52            mpca_corporate_account_id: $form.find('input[name="mpca_corporate_account_id"]').val(),
53            mpgft_gift_checkbox: $form.find('input[name="mpgft-signup-gift-checkbox"]').is(':checked'),
54            mepr_payment_methods: payment_methods
55          };
56
57          if (!data.mpgft_gift_checkbox) {
58            let order_bumps = [];
59
60            $form.find('input[name="mepr_order_bumps[]"]:checked').each(function () {
61              order_bumps.push($(this).val());
62            });
63
64            data.mepr_order_bumps = order_bumps;
65          }
66
67          return data;
68        };
69
70    const debouncedUpdateCheckoutState = function ($form) {
71      if (updatingCheckoutState) {
72        updateCheckoutStateAgain = true;
73        return;
74      }
75
76      const data = getRequestData($form);
77
78      if (JSON.stringify(data) === JSON.stringify(lastRequestData)) {
79        return;
80      }
81
82      updatingCheckoutState = true;
83      lastRequestData = data;
84
85      if (MeprSignup.spc_enabled === '1' && MeprSignup.spc_invoice === '1') {
86        $form.find('.mepr-invoice-loader').fadeIn();
87      }
88
89      const onComplete = function () {
90        if (MeprSignup.spc_enabled === '1' && MeprSignup.spc_invoice === '1') {
91          $form.find('.mepr-invoice-loader').hide();
92        }
93
94        updatingCheckoutState = false;
95      };
96
97      $.ajax({
98        type: 'POST',
99        url: MeprI18n.ajaxurl,
100        dataType: 'json',
101        data: getRequestData($form)
102      })
103      .done(function (response) {
104        if (response && typeof response.success === 'boolean' && response.success) {
105          $form.trigger('meprPriceStringUpdated', [response.data]);
106          $form.find('div.mepr_price_cell').html(response.data.price_string);
107
108          if (response.data.payment_required) {
109            $form.find('.mepr-payment-methods-wrapper').show();
110            $form.find('input[name="mepr_payment_methods_hidden"]').remove();
111          } else {
112            $form.find('.mepr-payment-methods-wrapper').hide();
113            $form.append('<input type="hidden" name="mepr_payment_methods_hidden" value="1">');
114
115            // Clear validation errors on fields now hidden
116            $form.find('.mepr-payment-methods-wrapper .mepr-form-input').each(function () {
117              meprValidateInput(this);
118            });
119          }
120
121          $form.trigger('meprAfterPriceStringUpdated', [response.data]);
122
123          if (MeprSignup.spc_enabled === '1' && MeprSignup.spc_invoice === '1') {
124            $form.find('.mepr-transaction-invoice-wrapper > div').replaceWith(response.data.invoice_html);
125            $form.find(".mepr-transaction-invoice-wrapper .mp_invoice").css({ opacity: 1 });
126          }
127
128          $form.trigger('meprAfterCheckoutStateUpdated', [response.data]);
129
130          onComplete();
131
132          if (updateCheckoutStateAgain) {
133            updateCheckoutStateAgain = false;
134            updateCheckoutState($form);
135          }
136        } else {
137          onComplete();
138        }
139      })
140      .fail(onComplete);
141    };
142
143    $('.mepr-signup-form').on('meprUpdateCheckoutState', function () {
144      updateCheckoutState($(this));
145    });
146
147    var meprValidateInput = function (obj, submitting) {
148      $(obj).removeClass('invalid');
149
150      var form = $(obj).closest('.mepr-signup-form');
151
152      if ($(obj).attr('required') !== undefined) {
153        var notBlank = mpValidateFieldNotBlank($(obj));
154        mpToggleFieldValidation($(obj), notBlank);
155      }
156
157      // Validate actual email only if it's not empty otherwise let the required/un-required logic hold
158      if ($(obj).attr('type')==='email' && $(obj).val().length > 0) {
159        var validEmail = mpValidateEmail($(obj).val());
160        mpToggleFieldValidation($(obj), validEmail);
161      }
162
163      // Validate the URL by using the browser validation functions
164      if ($(obj).attr('type')==='url' && $(obj).val().length > 0) {
165        var validURL = mpValidateUrl($(obj).val());
166        mpToggleFieldValidation($(obj), validURL);
167      }
168
169      if ($(obj).hasClass('mepr-password-confirm')) {
170        var confirmMatch = $(obj).val() === form.find('.mepr-password').val();
171        mpToggleFieldValidation($(obj), confirmMatch);
172      }
173
174      if($(obj).hasClass('mepr-coupon-code') && !submitting) {
175        var price_string = form.find('div.mepr_price_cell');
176
177        if($(obj).val().match(/(\s|\S)/)) {
178          $(obj).prev('.mp-form-label').find('.mepr-coupon-loader').fadeIn();
179          $(obj).data('validating', true);
180
181          var data = {
182            action: 'mepr_validate_coupon',
183            code: $(obj).val(),
184            prd_id: $(obj).data("prdid"),
185            coupon_nonce: MeprSignup.coupon_nonce
186          };
187
188          $.post(MeprI18n.ajaxurl, data, function(res) {
189            $(obj).prev('.mp-form-label').find('.mepr-coupon-loader').hide();
190            res = res.trim();
191            mpToggleFieldValidation($(obj), (res.toString() == 'true'));
192
193            if(res.toString() == 'true') {
194              if($(obj).data('submit-when-valid')) {
195                form.one('meprAfterPriceStringUpdated', function () {
196                  form.find('.mepr-submit').trigger('click');
197                });
198              }
199
200              // Let's update price string and invoice
201              updateCheckoutState(form);
202            }
203            else {
204              form.find('.mepr-payment-methods-wrapper:hidden').show();
205              form.find('input[name="mepr_payment_methods_hidden"]').remove();
206              price_string.text(price_string.data('default-price-string'));
207
208              // Invalid Coupon - update SPC Invoice
209              updateCheckoutState(form);
210            }
211          })
212          .always(function () {
213            $(obj).removeData('validating');
214            $(obj).removeData('submit-when-valid');
215          });
216        }
217        else if($(obj).val().trim() === '') {
218          if (form.find('.mepr-payment-methods-wrapper').is(':hidden')) {
219            // Looks like we need to restore the payment methods
220            form.find('.mepr-payment-methods-wrapper').show();
221            form.find('input[name="mepr_payment_methods_hidden"]').remove();
222          }
223
224          price_string.text(price_string.data('default-price-string'));
225          // Enpty Coupon - update SPC Invoice
226          updateCheckoutState(form);
227        }
228      }
229
230      $(obj).trigger('mepr-validate-input');
231    };
232
233    $('body').on('focus', '.mepr-form .mepr-form-input', function (e) {
234      $(this).prev('.mp-form-label').find('.cc-error').hide();
235      $(this).removeClass('invalid');
236    });
237
238    $('body').on('blur', '.mepr-form .mepr-form-input', function (e) {
239      //Don't validate date fields here, wait til the push the submit button
240      if(!$(this).hasClass('mepr-date-picker')) {
241        meprValidateInput(this);
242      }
243    });
244
245    // Specific to validating with the datepicker ui text field
246    $('body').on('mepr-date-picker-closed', '.mepr-form .mepr-form-input.mepr-date-picker', function (e, date, inst) {
247      meprValidateInput(this);
248    });
249
250    $('body').on('click', '.mepr-signup-form .mepr-submit', function (e) {
251      // We want to control if/when the form is submitted
252      e.preventDefault();
253
254      var form = $(this).closest('.mepr-signup-form');
255      var coupon = form.find('.mepr-coupon-code');
256
257      if(coupon.data('validating')) {
258        coupon.data('submit-when-valid', true);
259        return;
260      }
261
262      $.each(form.find('.mepr-form-input:visible'), function(i,obj) {
263        meprValidateInput(obj, true);
264      });
265
266      if (0 < form.find('.invalid:visible').length) {
267        form.find('.validation').addClass('failed');
268      }
269      else {
270        var submittedTelInputs = document.querySelectorAll(".mepr-tel-input");
271        for (var i = 0; i < submittedTelInputs.length; i++) {
272          var iti = window.intlTelInputGlobals.getInstance(submittedTelInputs[i]);
273          submittedTelInputs[i].value = iti.getNumber();
274        }
275        form.find('.validation').addClass('passed');
276        this.disabled = true;
277        form.find('.mepr-loading-gif').show();
278        $(this).trigger('mepr-register-submit');
279        form.submit();
280      }
281    });
282
283    $('body').on('click', '.mepr-signup-form div[class^=mepr-payment-method] input.mepr-form-radio', function () {
284      var form = $(this).closest('.mepr-signup-form');
285
286      // Reset the transaction ID to prevent any issues after switching payment methods
287      form.find('input[name="mepr_transaction_id"]').val('');
288
289      var pmid = '.mp-pm-desc-' + $(this).val();
290      var pmid_exists = (form.find(pmid).length > 0);
291
292      form.find('.mepr-payment-method-desc-text').addClass('mepr-close');
293
294      if(pmid_exists) {
295        form.find(pmid).removeClass('mepr-close');
296      }
297
298      //If nothing has the mepr-close class, we still need to show this one's description
299      var mepr_close_exists = (form.find('.mepr-payment-method-desc-text.mepr-close').length > 0);
300
301      if(mepr_close_exists) {
302        form.find('.mepr-payment-method-desc-text.mepr-close').slideUp({
303          duration: 200,
304          complete: function() {
305            // Clear validation errors on fields now hidden
306            form.find('.mepr-payment-methods-wrapper .mepr-form-input').each(function () {
307              $('.mepr-form-input.invalid').removeClass('.invalid');
308              $('.cc-error').hide();
309              $('.mepr-form-has-errors').hide();
310            });
311
312            if(pmid_exists) {
313              form.find(pmid).slideDown(200);
314            }
315          }
316        });
317      } else {
318        // Clear validation errors on fields now hidden
319        form.find('.mepr-payment-methods-wrapper .mepr-form-input').each(function () {
320          $('.mepr-form-input.invalid').removeClass('.invalid');
321          $('.cc-error').hide();
322          $('.mepr-form-has-errors').hide();
323        });
324
325        if(pmid_exists) {
326          form.find(pmid).slideDown(200);
327        }
328      }
329    });
330
331    // Update price string & invoice when certain inputs change value
332    $("body").on("change mepr-geolocated",
333      ".mepr-form .mepr-form-input, .mepr-form .mepr-form-radios-input, .mepr-form .mepr-select-field",
334      function () {
335        if($(this).attr('name') == 'mepr-address-zip' ||
336          $(this).attr('name') == 'mepr-address-city' ||
337          $(this).attr('name') == 'mepr-address-country' ||
338          $(this).attr('name') == 'mepr-address-one' ||
339          $(this).attr('name') == 'mepr-address-state' ||
340          $(this).attr('name') == 'mepr_vat_customer_type' ||
341          $(this).attr('name') == 'mepr_vat_number' ||
342          $(this).attr('name') == 'mpgft-signup-gift-checkbox'
343        ) {
344          updateCheckoutState($(this).closest(".mepr-signup-form"));
345        }
346      }
347    );
348
349    $(".mepr-replace-file").each(function(){
350      $(this).closest('div').find('.mepr-file-uploader').hide();
351    });
352    $('body').on('click', '.mepr-replace-file', function (e) {
353      $(this).closest('div').find('.mepr-file-uploader').toggle();
354    });
355
356    // Set the visibility of payment methods based on order bumps
357    var handleOrderBumpToggle = function () {
358      var $input = $(this),
359          $order_bump = $input.closest('.mepr-order-bump'),
360          $order_bumps = $order_bump.closest('.mepr-order-bumps'),
361          $form = $order_bumps.closest('.mepr-signup-form'),
362          has_order_bump = false,
363          has_sub = false,
364          $to_hide = $(),
365          $to_show = $(),
366          $compatible_pm,
367          $incompatible_pm;
368
369      $order_bumps.find('input[name="mepr_order_bumps[]"]:checked').each(function () {
370        has_order_bump = true;
371
372        if($(this).closest('.mepr-order-bump').hasClass('mepr-sub')) {
373          has_sub = true;
374        }
375      });
376
377      $form.find('div[class^=mepr-payment-method] input.mepr-form-radio, input[type="hidden"][name="mepr_payment_method"]').each(function () {
378        var $pm = $(this);
379
380        if(has_order_bump) {
381          if($pm.hasClass('mepr-can-order-bumps')) {
382            if(has_sub) {
383              if($pm.hasClass('mepr-can-multiple-subscriptions')) {
384                $to_show = $to_show.add($pm);
385
386                if(!$compatible_pm) {
387                  $compatible_pm = $pm;
388                }
389              } else {
390                $to_hide = $to_hide.add($pm);
391
392                if($pm.prop('checked')) {
393                  $incompatible_pm = $pm;
394                }
395              }
396            } else {
397              $to_show = $to_show.add($pm);
398
399              if(!$compatible_pm) {
400                $compatible_pm = $pm;
401              }
402            }
403          } else {
404            $to_hide = $to_hide.add($pm);
405
406            if($pm.prop('checked')) {
407              $incompatible_pm = $pm;
408            }
409          }
410        } else {
411          $to_show = $to_show.add($pm);
412        }
413      });
414
415      if(!$to_show.length) {
416        alert(MeprSignup.no_compatible_pms);
417        return false;
418      }
419
420      if($incompatible_pm) {
421        if($compatible_pm) {
422          var compatible_pm_label = $compatible_pm.data('payment-method-type'),
423              prompt = MeprSignup.switch_pm_prompt.replace('%s', compatible_pm_label);
424
425          if($.magnificPopup) {
426            var $switch_button = $('<div class="mepr-btn">').text(MeprSignup.switch_pm.replace('%s', compatible_pm_label)).on('click', function () {
427              $compatible_pm.trigger('click');
428              $input.trigger('click');
429              $.magnificPopup.close();
430            });
431
432            var $cancel_button = $('<div class="mepr-btn mepr-btn-secondary">').text(MeprSignup.cancel).on('click', function () {
433              $.magnificPopup.close();
434            });
435
436            var $popup_content = $('<div class="mepr-switch-pm-popup">').append(
437              $('<img class="mepr-switch-pm-popup-icon">').attr('src', MeprSignup.warning_icon_url),
438              $('<p>').text(prompt),
439              $('<div class="mepr-switch-pm-popup-buttons">').append($switch_button, $cancel_button)
440            );
441
442            $.magnificPopup.open({
443              mainClass: 'mepr-switch-pm-mfp',
444              items: {
445                src: $popup_content,
446                type: 'inline'
447              }
448            });
449          } else if(confirm(prompt)) {
450            $compatible_pm.trigger('click');
451            $input.trigger('click');
452            return;
453          }
454        } else {
455          alert(MeprSignup.no_compatible_pms);
456        }
457
458        return false;
459      }
460
461      $to_hide.closest('.mepr_payment_method, .mepr-payment-option-label').hide();
462      $to_show.closest('.mepr_payment_method, .mepr-payment-option-label').show();
463
464      $order_bump.toggleClass('mepr-order-bump-selected', this.checked);
465    };
466
467    $('body').on('click', '.mepr-signup-form input[name="mepr_order_bumps[]"]', handleOrderBumpToggle);
468
469    // Hide subscription order bumps if no payment method supports multiple subscriptions
470    $('.mepr-signup-form').each(function () {
471      var $form = $(this),
472          $order_bumps = $form.find('.mepr-order-bumps'),
473          pm_supports_multiple_subs = false;
474
475      if(!$order_bumps.length) {
476        return;
477      }
478
479      $form.find('div[class^=mepr-payment-method] input.mepr-form-radio, input[type="hidden"][name="mepr_payment_method"]').each(function (index) {
480        var $pm = $(this);
481
482        if($pm.hasClass('mepr-can-multiple-subscriptions') && pm_supports_multiple_subs === false) {
483          pm_supports_multiple_subs = index;
484        }
485      });
486
487      if(pm_supports_multiple_subs === false) {
488        $order_bumps.find('.mepr-order-bump.mepr-sub').hide();
489
490        if(!$order_bumps.find('.mepr-order-bump:visible').length) {
491          $order_bumps.hide();
492        }
493      } else if(pm_supports_multiple_subs > 0) {
494        var $new_first_pm = $form.find('div[class^=mepr-payment-method] input.mepr-form-radio').eq(pm_supports_multiple_subs);
495
496        $new_first_pm
497          .closest('.mepr_payment_method, .mepr-payment-option-label')
498          .insertBefore(
499            $form.find('div[class^=mepr-payment-method] input.mepr-form-radio')
500              .eq(0)
501              .closest('.mepr_payment_method, .mepr-payment-option-label')
502          );
503
504        $new_first_pm.trigger('click');
505      }
506
507      // If gift checkbox is checked, hide and disable order bumps
508      if($form.find('input[name="mpgft-signup-gift-checkbox"]').is(':checked')) {
509        $order_bumps.hide().find('input[name="mepr_order_bumps[]"]').prop('checked', false);
510      }
511    });
512
513    $("body").on("change",
514      '.mepr-form input[name="mepr_order_bumps[]"]',
515      function (e) {
516        let form = $(this).closest(".mepr-signup-form");
517        if( $('input[type="hidden"][name="mepr_process_signup_form"]').length ) {
518          if( $('input[type="hidden"][name="mepr_process_signup_form"]').val() == 'Y' ) {
519            return;
520          }
521        }
522        updateCheckoutState(form);
523      }
524    );
525
526    $("body").on('change', '.mepr-signup-form input[name="mpgft-signup-gift-checkbox"]', function () {
527      let $is_gift = $(this),
528          $form = $is_gift.closest('.mepr-signup-form');
529
530      if ($is_gift.is(':checked')) {
531        $form.find('.mepr-order-bumps').hide().find('input[name="mepr_order_bumps[]"]:checked').prop('checked', false).each(function () {
532          handleOrderBumpToggle.call(this);
533        });
534      } else {
535        $form.find('.mepr-order-bumps').show();
536      }
537    });
538  });
539})(jQuery);

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.