1jQuery(function ($) { 2 3 // Make the code work after page load. 4 $(document).ready(function () { 5 QuantityChange(); 6 }); 7 8 // Make the code work after executing AJAX. 9 $(document).ajaxComplete(function () { 10 QuantityChange(); 11 }); 12 13 function QuantityChange() { 14 $(document).off("click", ".qib-button").on("click", ".qib-button", function () { 15 // Find quantity input field corresponding to increment button clicked. 16 var qty = $(this).siblings(".quantity").find(".input-text"); 17 // Read value and attributes min, max, step. 18 var val = parseFloat(qty.val()); 19 var max = parseFloat(qty.attr("max")); 20 var min = parseFloat(qty.attr("min")); 21 var step = parseFloat(qty.attr("step")); 22 // var static = 8; 23 24 var qtyObj = $(this).siblings(".quantity"); 25 var last_step = qtyObj.attr('data-last_step'); 26 last_step = parseFloat( last_step ); 27 var prev_step = qtyObj.attr('data-prev_step'); 28 prev_step = parseFloat( prev_step ); 29 // Change input field value if result is in min and max range. 30 // If the result is above max then change to max and alert user about exceeding max stock. 31 // If the field is empty, fill with min for "-" (0 possible) and step for "+". 32 if ($(this).is(".plus")) { 33 if (val === max){ 34 console.log(555); 35 return false; 36 } 37 38 if (isNaN(val)) { 39 console.log(666); 40 qty.val(step); 41 return false; 42 } 43 if (val + step > max) { 44 qtyObj.attr('data-last_step', ( max-val ) ); 45 qtyObj.attr('data-prev_step', ( step ) ); 46 qtyObj.find(".input-text").removeAttr('step' ); 47 qty.val(max); 48 } else { 49 console.log(888); 50 qty.val(val + step); 51 } 52 } else { 53 54 if (last_step) { 55 56 qty.val(max - last_step); 57 qtyObj.removeAttr('data-last_step'); 58 qtyObj.find(".input-text").attr('step', prev_step ); 59 qtyObj.removeAttr('data-prev_step'); 60 return false; 61 } 62 if (val === min){ 63 console.log(1111); 64 return false; 65 } 66 67 if (isNaN(val)) { 68 console.log(2222); 69 qty.val(min); 70 return false; 71 } 72 if (val - step < min) { 73 console.log(3333); 74 qty.val(min); 75 } else { 76 console.log(4444); 77 qty.val(val - step); 78 } 79 } 80 81 qty.val(Math.round(qty.val() * 100) / 100); 82 qty.trigger("change"); 83 $("body").removeClass("sf-input-focused"); 84 }); 85 } 86 87});
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.