1var decimal_sep, thousand_sep; 2decimal_sep = wdgk_obj.options.decimal_sep; // woo commerce decimal separator 3thousand_sep = wdgk_obj.options.thousand_sep; // woo commerce thousand separator 4 5jQuery(document).ready(function ($) { 6 /** Not allow alphabats on keypress */ 7 jQuery('.wdgk_donation').on('keydown', function (e) { 8 if (e.which == 13) { 9 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_add_donation").trigger("click"); 10 } 11 12 // No letters 13 if (e.which >= 65 && e.which <= 90) { 14 e.preventDefault(); 15 return false; 16 } 17 }); 18 19 /** Prevent redirection on donation form for variable product */ 20 jQuery('body').on("keypress", '.wdgk_donation_content input[name="donation-price"]', function (e) { 21 if (e.which === 13) { // 13 is the Enter key 22 jQuery('.wdgk_add_donation').click(); 23 return false; 24 } 25 }); 26 jQuery('#wdgk_variation_submit').on('submit', function(e){ 27 // validation code here 28 e.preventDefault(); 29 }); 30 31 jQuery('body').on("click", ".wdgk_add_donation", function () { 32 var note = ""; 33 var price = ""; 34 var variation_id = ""; 35 var variation_obj = {}; 36 var decimal_price = ""; 37 38 var variation_id = jQuery(this).closest('.wdgk_donation_content').find('#variation_id').val(); 39 40 var price_elem = jQuery(this).closest('.wdgk_donation_content').find("input[name='donation-price']"); 41 if (price_elem) { 42 updated_price = wdgk_updatedInputprice(price_elem.val()); 43 price_elem.val(updated_price); 44 price = updated_price; 45 var replace_decimal_regex = new RegExp('\\' + decimal_sep, "g"); 46 decimal_price = price.replace(replace_decimal_regex, '.'); // replace decimal sparator to dot 47 } 48 49 if (jQuery(this).closest('.wdgk_donation_content').find('.donation_note').val()) { 50 var note = jQuery(this).closest('.wdgk_donation_content').find('.donation_note').val(); 51 var lines = []; 52 $.each(note.split(/\n/), function (i, line) { 53 if (line) { 54 lines.push(jQuery.trim(line)); 55 } else { 56 lines.push(""); 57 } 58 }); 59 var note_text = JSON.stringify(lines); 60 } 61 var ajaxurl = jQuery('.wdgk_ajax_url').val(); 62 var product_id = jQuery(this).attr('data-product-id'); 63 var redirect_url = jQuery(this).attr('data-product-url'); 64 var single_dp_id = jQuery(this).attr('data-single-dp'); 65 66 67 if (decimal_price == "") { 68 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter a value!!"); 69 return false; 70 } else { 71 var pattern = new RegExp(/^[0-9.*]/); 72 if (!pattern.test(decimal_price) || decimal_price < 0.01) { 73 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter valid value!!"); 74 return false; 75 } 76 } 77 78 // update function for allow comma in donation price 79 if (wdgk_isNumber(decimal_price)) { 80 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter numeric value!!"); 81 return false; 82 } 83 if(variation_id != undefined && variation_id == '') { 84 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please fill required fields!!"); 85 return false; 86 }else{ 87 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text(""); 88 } 89 90 jQuery(this).closest('.wdgk_donation_content').find('.wdgk_loader').removeClass("wdgk_loader_img"); 91 92 // set new cookie for display price with comma 93 if(single_dp_id == 'true') { 94 if(variation_id != undefined) { 95 product_id = variation_id; 96 jQuery('.wdgk_variation.wdgk-row').each(function() { 97 var attr_name = jQuery(this).find("select").attr("data-attribute_name"); 98 var attr_value = jQuery(this).find("select").find(":selected").val(); 99 variation_obj[attr_name] = attr_value; 100 });
101 setCookie('wdgk_variation_product:'+variation_id, JSON.stringify(variation_obj), 1); 102 } 103 setCookie('wdgk_product_display_price:'+product_id, price, 1); 104 setCookie('wdgk_product_price:'+product_id, decimal_price, 1); 105 setCookie('wdgk_donation_note:'+product_id, note_text, 1); 106 }else{ 107 setCookie('wdgk_product_display_price', price, 1); 108 setCookie('wdgk_product_price', decimal_price, 1); 109 setCookie('wdgk_donation_note', note_text, 1); 110 } 111 112 var $data = { 113 action: 'wdgk_donation_form', 114 product_id: product_id, 115 price: decimal_price, 116 note: note, 117 redirect_url: redirect_url 118 } 119 if(variation_id != undefined) { 120 $data.product_type = 'variation'; 121 $data.variation_id = variation_id; 122 } 123 124 jQuery.ajax({ 125 url: ajaxurl, 126 data: $data, 127 type: 'POST', 128 success: function (data) { 129 var redirect = jQuery.parseJSON(data); 130 if (redirect.error == "true") { 131 jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter valid value!!"); 132 jQuery(this).closest('.wdgk_donation_content').find('.wdgk_loader').addClass("wdgk_loader_img"); 133 return false; 134 } else { 135 document.location.href = redirect.url; 136 } 137 } 138 }); 139 }); 140 141}); 142 143function setCookie(cname, cvalue, exdays) { 144 var d = new Date(); 145 d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); 146 var expires = "expires=" + d.toUTCString(); 147 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 148} 149 150function getCookie(cname) { 151 var name = cname + "="; 152 var ca = document.cookie.split(";"); 153 for (var i = 0; i < ca.length; i++) { 154 var c = ca[i]; 155 while (c.charAt(0) == " ") { 156 c = c.substring(1); 157 } 158 if (c.indexOf(name) == 0) { 159 return c.substring(name.length, c.length); 160 } 161 } 162 return ""; 163} 164// 165function wdgk_isNumber(price) { 166 var regex = /^[0-9.,\b]+$/; 167 if (!regex.test(price)) return false; 168} 169 170/* Returns filtered product price */ 171function wdgk_updatedInputprice(input_val) { 172 let allow_number = new RegExp('[^0-9\\' + decimal_sep + ']', 'g'); // allow only number and decimal "/[^\d.]/g" 173 let remove_ml_sep = new RegExp('\\' + decimal_sep + '+$'); // remove multiple decimal from last of string "/\.+$/" 174 let remove_from_start_end = new RegExp('^\\' + decimal_sep + '+|\\' + decimal_sep + '+$', 'g'); // remove decimal from start and end of string "/^,+|,+$/g" 175 var updated_price = input_val.replace(allow_number, "").replace(remove_ml_sep, "").replace(remove_from_start_end, ""); 176 177 if (updated_price != '' && updated_price.includes(decimal_sep)) { 178 let new_val = updated_price.split(decimal_sep); 179 updated_price = new_val.shift() + decimal_sep + new_val.join(''); 180 } 181 return updated_price; 182}
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.