1(function($) { 2 $(document).ready(function() { 3 $('#have-coupon-link').on('click', function(e) { 4 e.preventDefault(); 5 $(this).hide(); 6 $('div.mepr_coupon').show(); 7 }); 8 var meprValidateInput = function (obj) { 9 $(obj).removeClass('invalid'); 10 11 var form = $(obj).closest('.mepr-signup-form'); 12 13 if ($(obj).attr('required') !== undefined) { 14 var notBlank = true; 15 if ($(obj).is('input') || $(obj).is('select') || $(obj).is('textarea')) { 16 notBlank = mpValidateNotBlank($(obj).val()); 17 } 18 else if ($(obj).hasClass('mepr-checkbox-field')) { 19 notBlank = $(obj).find('input').is(':checked'); 20 } 21 else if ($(obj).hasClass('mepr-radios-field') || $(obj).hasClass('mepr-checkboxes-field')) { 22 var input_vals = []; 23 $.each($(obj).find('input'), function (i, obj) { 24 if($(obj).is(':checked')) { 25 input_vals.push(true); 26 } 27 }); 28 29 notBlank = mpValidateNotBlank(input_vals); 30 } 31 32 mpToggleFieldValidation($(obj), notBlank); 33 } 34 35 // Validate actual email only if it's not empty otherwise let the required/un-required logic hold 36 if ($(obj).attr('type')==='email' && $(obj).val().length > 0) { 37 var validEmail = mpValidateEmail($(obj).val()); 38 mpToggleFieldValidation($(obj), validEmail); 39 } 40 41 // Validate the URL by using the browser validation functions 42 if ($(obj).attr('type')==='url' && $(obj).val().length > 0) { 43 var validURL = $(obj).is(':valid'); 44 mpToggleFieldValidation($(obj), validURL); 45 } 46 47 if ($(obj).hasClass('mepr-password-confirm')) { 48 var confirmMatch = $(obj).val() === form.find('.mepr-password').val(); 49 mpToggleFieldValidation($(obj), confirmMatch); 50 } 51 52 if ($(obj).hasClass('mepr-coupon-code') && $(obj).val().match(/(\s|\S)/)) { 53 $(obj).prev('.mp-form-label').find('.mepr-coupon-loader').fadeIn(); 54 55 var data = { 56 action: 'mepr_validate_coupon', 57 code: $(obj).val(), 58 prd_id: $(obj).attr("data-prd-id"), 59 coupon_nonce: MeprSignup.coupon_nonce 60 }; 61 62 $.post(MeprI18n.ajaxurl, data, function(res) { 63 $(obj).prev('.mp-form-label').find('.mepr-coupon-loader').hide(); 64 res = res.trim(); 65 mpToggleFieldValidation($(obj), (res.toString() == 'true')); 66 67 if(res.toString() == 'true') { 68 var data_two = { 69 action: 'mepr_update_price_string_with_coupon', 70 code: $(obj).val(), 71 prd_id: $(obj).attr("data-prd-id"), 72 coupon_nonce: MeprSignup.coupon_nonce 73 }; 74 75 $.post(MeprI18n.ajaxurl, data_two, function(res_two) { 76 res_two = res_two.trim(); 77 if(res_two.toString() != 'false') { 78 form.find('div.mepr_price_cell').text(res_two); 79 $('body').animate( { 80 scrollTop: form.find('div.mepr_price_cell').offset().top 81 }, 200, function() { 82 form.find('div.mepr_price_cell').parent().hide(); 83 form.find('div.mepr_price_cell').parent().fadeIn(1000); 84 }); 85 } 86 }); 87 } 88 }); 89 } 90 91 $(obj).trigger('mepr-validate-input'); 92 }; 93 94 $('body').on('focus', '.mepr-form .mepr-form-input', function (e) { 95 $(this).prev('.mp-form-label').find('.cc-error').hide(); 96 $(this).removeClass('invalid'); 97 }); 98 99 $('body').on('blur', '.mepr-form .mepr-form-input', function (e) { 100 //Don't validate date fields here, wait til the push the submit button 101 if(!$(this).hasClass('mepr-date-picker')) { 102 meprValidateInput(this); 103 } 104 }); 105 106 // Specific to validating with the datepicker ui text field 107 $('body').on('mepr-date-picker-closed', '.mepr-form .mepr-form-input.mepr-date-picker', function (e, date, inst) { 108 meprValidateInput(this); 109 });
110 111 $('body').on('click', '.mepr-signup-form .mepr-submit', function (e) { 112 // We want to control if/when the form is submitted 113 e.preventDefault(); 114 115 var form = $(this).closest('.mepr-signup-form'); 116 var button = $(this); 117 118 $.each(form.find('.mepr-form-input'), function(i,obj) { 119 meprValidateInput(obj); 120 }); 121 122 if (0 < form.find('.invalid').length) { 123 form.find('.validation').addClass('failed'); 124 } 125 else { 126 form.find('.validation').addClass('passed'); 127 this.disabled = true; 128 $('.mepr-loading-gif').show(); 129 $(this).trigger('mepr-register-submit'); 130 form.submit(); 131 } 132 }); 133 134 $('body').on('click', '.mepr-signup-form .mepr_payment_method input.mepr-form-radio', function (e) { 135 var form = $(this).closest('.mepr-signup-form'); 136 137 var pmid = '#mp-pm-desc-' + $(this).val(); 138 var pmid_exists = (form.find(pmid).length > 0); 139 140 form.find('.mepr-payment-method-desc-text').addClass('mepr-close'); 141 142 if(pmid_exists) { 143 form.find(pmid).removeClass('mepr-close'); 144 } 145 146 //If nothing has the mepr-close class, we still need to show this one's description 147 var mepr_close_exists = (form.find('.mepr-payment-method-desc-text.mepr-close').length > 0); 148 149 if(mepr_close_exists) { 150 form.find('.mepr-payment-method-desc-text.mepr-close').slideUp({ 151 duration: 200, 152 complete: function() { 153 if(pmid_exists) { 154 form.find(pmid).slideDown(200); 155 } 156 } 157 }); 158 } else { 159 if(pmid_exists) { 160 form.find(pmid).slideDown(200); 161 } 162 } 163 }); 164 }); 165})(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.