1(function($) { 2 'use strict'; 3 function addCustomInputBox(){ 4 var decimal_separator = WCMMQ_DATA.decimal_separator; 5 if( decimal_separator != '.' ){ 6 $('input.input-text.qty.text').not('.wcmmq-second-input-box,.wcmmq-main-input-box').each(function(){ 7 8 $(this).addClass('wcmmq-main-input-box'); 9 var input_val = $(this).val(); 10 var val_with_coma = input_val.replace(/\./g, decimal_separator); 11 var parentQuantity = $(this).parents('.quantity'); 12 parentQuantity.addClass('wcmmq-coma-separator-activated'); 13 $(this).after('<input type="text" value="' + val_with_coma + '" class="wcmmq-second-input-box input-text qty text" id="wcmmq-second-input-id">'); 14 }); 15 } 16 } 17 $(document).ajaxComplete(function () { 18 setTimeout(addCustomInputBox,320); 19 }); 20 $(document).ready(function () { 21 var decimal_separator = WCMMQ_DATA.decimal_separator; 22 var decimal_count = WCMMQ_DATA.decimal_count; 23 24 if(typeof decimal_count !== 'undefined'){ 25 decimal_count = parseInt(decimal_count); 26 }else{ 27 decimal_count = 2; 28 } 29 30 addCustomInputBox(); 31 32 33 $(document.body).on('wpt_changed_variations',function(e, targetAttributeObject){ 34 35 if(targetAttributeObject.status == false){ 36 return false; 37 } 38 var product_id = targetAttributeObject.product_id; 39 var variation_id = targetAttributeObject.variation_id; 40 var variation_data = $('#wcmmq_variation_data_' + product_id).data('variation_data'); 41 var qty_boxWPT = $('.product_id_' + product_id + ' input.input-text.qty.text'); 42 distributeMinMax(variation_id,variation_data,qty_boxWPT); 43 }); 44 45 /** 46 * Custom work 47 */ 48 $('input.input-text.qty.text.wcmmq-qty-custom-validation').on('keyup', validatinMessageCustomize); 49 $('input.input-text.qty.text.wcmmq-qty-custom-validation').on('invalid', validatinMessageCustomize); 50 $('input.input-text.qty.text.wcmmq-qty-custom-validation').on('change', validatinMessageCustomize); 51 function validatinMessageCustomize() { 52 53 var DataObject = $('.wcmmq-json-options-data'); 54 var json_data = DataObject.data('wcmmq_json_data'); 55 // console.log(json_data); 56 var step_validation_msg = DataObject.data('step_error_valiation'); 57 var full_message = ""; 58 var msg_min_limit = DataObject.data('msg_min_limit') + " "; 59 var msg_max_limit = DataObject.data('msg_max_limit') + " "; 60 61 var product_name = "ð Product"; 62 63 // var step_validation_msg = 'Please enter a valid value. The two nearest valid values are [should_min] and [should_next]'; 64 // Parse input value as a float 65 var inputValue = parseFloat($(this).val()); 66 67 // Get the min, max, and step attributes 68 var min = parseFloat($(this).attr('min')); 69 var max = parseFloat($(this).attr('max')); 70 var step = parseFloat($(this).attr('step')); 71 72 // Calculate the nearest valid values 73 var lowerNearest = Math.floor((inputValue - min) / step) * step + min; 74 var upperNearest = lowerNearest + step; 75 76 if( inputValue < min){ 77 full_message += msg_min_limit.replace("[min_quantity]", min); 78 lowerNearest = min; 79 upperNearest = lowerNearest + step; 80 }else if(inputValue > max && max > min){ 81 full_message += msg_max_limit.replace("[max_quantity]", max); 82 lowerNearest = max - step; 83 upperNearest = max; 84 } 85 86 step_validation_msg = step_validation_msg.replace("[should_min]", lowerNearest); 87 step_validation_msg = step_validation_msg.replace("[should_next]", upperNearest); 88 full_message += step_validation_msg; 89 90 var final_full_message = full_message.replace('"[product_name]"', product_name); 91 final_full_message = final_full_message.replace("[product_name]", product_name); 92 93 94 95 // Check if the input is within the valid range 96 if (inputValue < min || inputValue > max || (inputValue - min) % step !== 0) { 97 // var step_validation_msg = 'Nearest valid values are ' + lowerNearest + ' and ' + upperNearest; 98 this.setCustomValidity(final_full_message); 99 } else { 100 // Clear custom validity message if input is valid 101 this.setCustomValidity(''); 102 } 103 } 104 105 /** 106 * New added 107 * First time, It was handle from Min_Max_Controller::single_variation_handle() 108 * currently that method is not need. 109 * 110 * We will handle it from javascript actually. 111 */ 112 $(document.body).on('change','form.variations_form.cart input.variation_id',function(){ 113 var min,max,step,basic; 114 var in_stock, stock_msg; 115 var form = $(this).closest('form.variations_form.cart'); 116 form.find('.wcmmq-custom-stock-msg').remove(); 117 var qty_box = form.find('input.input-text.qty.text'); 118 var variation_id = $(this).val(); 119 variation_id = parseInt(variation_id); 120 var variation_pass = variation_id > 0; 121 if( ! variation_pass ){ 122 return; 123 } 124 var product_variations = form.data('product_variations'); 125 if( ! product_variations ){ 126 //kept an another div using hook 'woocommerce_single_variation' at inc/min-max-controller.php file. if found empty at product variatins data 127 product_variations = form.find('.wcmmq-available-variaions').data('product_variations'); 128 } 129 130 var gen_product_variations = new Array(); 131 $.each(product_variations, function(index, eachVariation){ 132 133 var this_variation_id = eachVariation['variation_id']; 134 if( this_variation_id == variation_id){ 135 in_stock = eachVariation['is_in_stock']; 136 stock_msg = eachVariation['availability_html']; 137 138 min = eachVariation['min_value']; 139 max = eachVariation['max_value']; 140 step = eachVariation['step']; 141 basic = min; 142 143 if( ! in_stock){ 144 form.find('.single_variation_wrap').prepend('<div class="wcmmq-custom-stock-msg">' + stock_msg + '</div>'); 145 min = 0; 146 max = 0; 147 basic = 0; 148 step = 0; 149 } 150 } 151 if(min || ! in_stock){ 152 153 var lateSome = setInterval(function(){ 154 qty_box.attr({ 155 min:min, 156 max:max, 157 step:step, 158 value:min 159 }); 160 161 qty_box.val(basic).trigger('change'); 162 clearInterval(lateSome); 163 },500); 164 } 165 166 }); 167 }); 168 169 170 //End of Custom Worl *******************/ 171 172 function distributeMinMax(variation_id,variation_data,qty_boxWPT){ 173 if(typeof variation_id !== 'undefined' && variation_id !== '' && variation_id !== ' '){ 174 var min,max,step,basic; 175 176 min = variation_data[variation_id]['min_quantity']; 177 if(typeof min === 'undefined'){ 178 return false; 179 } 180 181 max = variation_data[variation_id]['max_quantity']; 182 step = variation_data[variation_id]['step_quantity']; 183 184 basic = min; 185 var lateSome = setInterval(function(){ 186 187 qty_boxWPT.attr({ 188 min:min, 189 max:max, 190 step:step, 191 value:min 192 }); 193 qty_boxWPT.val(basic).trigger('change'); 194 clearInterval(lateSome); 195 },500); 196 197 } 198 } 199 /** 200 * It's our custom input box with text type 201 * and we will transfer this text to main input(number) with convert comma to dot 202 * 203 * @since 3.5.2 204 */ 205 $(document.body).on('keyup','.wcmmq-second-input-box',function(Event){ 206 207 /** 208 * First, I will findout, If any user click on 209 * up or down arrow. 210 * So that, we can set behavier like number input box. 211 */ 212 var arrowPress = false; 213 if(typeof Event === 'object' && typeof Event.originalEvent === 'object'){ 214 var originalEvent = Event.originalEvent; 215 if(originalEvent.keyCode === 38 || originalEvent.code === 'ArrowUp'){ 216 arrowPress = 'ArrowUp'; 217 }else if(originalEvent.keyCode === 40 || originalEvent.code === 'ArrowDown'){ 218 arrowPress = 'ArrowDown'; 219 } 220 221 } 222 223 /** 224 * Checking Down/Up arrow button 225 * If not click on up or down arrow button 226 * and if click on any number, then this bellow code will write in our 227 * main input(number) box with . or , 228 * 229 * @since3.5.2 230 */ 231 if( !arrowPress ){ 232 var parentQuantity = $(this).parents('.quantity'); 233 var secondInputVal = $(this).val(); 234 var secondValWithDot = secondInputVal.replace(/,/g, '.');
235 parentQuantity.find('.wcmmq-main-input-box').val(secondValWithDot); 236 }else{ 237 var secondInboxObject = $(this); 238 Event.preventDefault(); 239 plusMinusOnArrowCalculate(arrowPress,secondInboxObject); 240 } 241 }); 242 /** 243 * ONLY for coman decimal separator, Not for else 244 * 245 * First requirement: 246 * It will work ONLY a User enable comma as Decimal 247 * Otherwise, this is not will impact any more. 248 * 249 * @since 3.5.2 250 * 251 */ 252 function plusMinusOnArrowCalculate(type,secondInboxObject){ 253 254 var qty = secondInboxObject.closest('.wcmmq-coma-separator-activated').find('input.input-text.qty.text.wcmmq-main-input-box'); 255 // Read value and attributes min, max, step. 256 var val = parseFloat(qty.val()); 257 var max = parseFloat(qty.attr("max")); 258 var min = parseFloat(qty.attr("min")); 259 var step = parseFloat(qty.attr("step")); 260 console.log(min,val,max,step); 261 262 if( type === 'ArrowUp'){ 263 if (val === max){ 264 return false; 265 } 266 267 if (isNaN(val)) { 268 qty.val(step).trgger('change'); 269 return false; 270 } 271 272 qty.val(val + step); 273 }else if( type === 'ArrowDown'){ 274 if (val === min){ 275 return false; 276 } 277 if (isNaN(val)) { 278 qty.val(min).trgger('change'); 279 return false; 280 } 281 if (val - step < min) { 282 qty.val(min); 283 } else { 284 qty.val(val - step); 285 } 286 } 287 288 qty.val(Math.round(qty.val() * 100000) / 100000); 289 qty.trigger("change"); 290 } 291 292 /** 293 * this will only output 2 digit 294 * Especially solved for OceanWP theme 295 */ 296 297 function CheckDecimal(inputtxt) { 298 if(!/^[-+]?[0-9]+\.[0-9]+$/.test(inputtxt)) { 299 return true; 300 } else { 301 return false; 302 } 303 } 304 var qty_box,qty_box_selector, qty_value, formatted_value; 305 qty_box_selector = '.qib-button-wrapper .quantity input.input-text.qty.text, .single-product div.product form.cart .quantity input[type=number], .single-product div.product form.cart .quantity input[type=number]'; 306 $(document.body).on('change',qty_box_selector,function(){ 307 qty_value = $(this).val(); 308 309 if( decimal_separator != '.' ){ 310 console.log(decimal_separator); 311 qty_value = qty_value.replace(/\./g, decimal_separator); 312 } 313 314 $(this).parents('.quantity').find('.wcmmq-second-input-box').val(qty_value); 315 }); 316 317 // this may not work. we need to check the classs 318 // qty_box = $('.qib-button-wrapper .quantity input.input-text.qty.text, .single-product div.product form.cart .quantity input[type=number], .single-product div.product form.cart .quantity input[type=number]'); 319 320 // qty_box.on('change', function(){ 321 // qty_value = $(this).val(); 322 323 // if( decimal_separator === ',' ){ 324 // qty_value = qty_value.replace(/\./g, ','); 325 // // $(this).parents('.quantity').find('.wcmmq-second-input-box').val(qty_value); 326 // } 327 328 // $(this).parents('.quantity').find('.wcmmq-second-input-box').val(qty_value); 329 // }); 330 331 }); 332 333 334})(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.