1jQuery(document).ready(function($) { 2 'use strict'; 3 // Woocommerce Cart Quantity 4 if ( ! String.prototype.rhgetDecimalNumber ) { 5 String.prototype.rhgetDecimalNumber = function () { 6 var num = this, 7 match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 8 if ( ! match ) { 9 return 0; 10 } 11 12 return Math.max( 0, ( match[1] ? match[1].length : 0 ) - ( match[2] ? + match[2] : 0 ) ); 13 } 14 } 15 16 $(document).on('click', '.rh-custom-quantity .plus-quantity, .rh-custom-quantity .minus-quantity', function () { 17 // Get values 18 var $qty = $(this).closest('.quantity').find('.qty'), 19 currentVal = parseFloat( $qty.val() ), 20 max = parseFloat($qty.attr('max')), 21 min = parseFloat($qty.attr('min')), 22 step = $qty.attr('step'); 23 24 // Format values 25 if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) { 26 currentVal = 0; 27 } 28 29 if ( max === '' || max === 'NaN' ) { 30 max = ''; 31 } 32 33 if ( min === '' || min === 'NaN' ) { 34 min = 0; 35 } 36 37 if ( step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN' ) { 38 step = '1'; 39 } 40 41 if ( $(this).is('.plus-quantity') ) { 42 if ( max && ( currentVal >= max ) ) { 43 $qty.val(max); 44 } else { 45 $qty.val( ( currentVal + parseFloat( step ) ).toFixed( step.rhgetDecimalNumber() ) ); 46 } 47 } else { 48 if ( min && ( currentVal <= min ) ) { 49 $qty.val(min); 50 } else if ( currentVal > 0 ) { 51 $qty.val( ( currentVal - parseFloat( step ) ).toFixed( step.rhgetDecimalNumber() ) ); 52 } 53 } 54 55 $(this).closest('.rh-loop-quantity').find('.ajax_add_to_cart').attr('data-quantity', parseInt($(this).closest('.rh-loop-quantity').find('.qty').val())); 56 57 $qty.trigger('change'); 58 }); 59 60 var Carttimeout; 61 $(document).on('change input', '.woocommerce-mini-cart .rh-custom-quantity .qty', function() { 62 if ( typeof wc_cart_fragments_params === 'undefined' ) { 63 return false; 64 } 65 66 var productQty = $(this).val(); 67 var productID = $(this).parents('.woocommerce-mini-cart-item').prop('class').match(/cartkey-([a-z0-9]+)/)[1];; 68 var cart_hash_key = wc_cart_fragments_params.cart_hash_key; 69 var fragment_name = wc_cart_fragments_params.fragment_name; 70 71 console.log(productID); 72 73 clearTimeout(Carttimeout); 74 75 Carttimeout = setTimeout( function () { 76 77 $.ajax({
78 url: rhscriptvars.ajax_url, 79 data: { 80 action: 'rh_update_sidebar_cart_item', 81 item_id: productID, 82 qty: productQty 83 }, 84 success: function (data) { 85 if ( data && data.fragments ) { 86 $.each( data.fragments, function( key, value ) { 87 if ($(key).hasClass('widget_shopping_cart_content')) { 88 var dataNewValue = $(value).find('.woocommerce-mini-cart-item.cartkey-' + productID + ''); 89 var FooterValue = $(value).find('.woocommerce-mini-cart__total') 90 var $selector = $( key ).find('.woocommerce-mini-cart-item.cartkey-' + productID + ''); 91 92 if ( ! data.cart_hash ) { 93 $( key ).replaceWith( value ); 94 } else { 95 $selector.replaceWith(dataNewValue); 96 $('.woocommerce-mini-cart__total').replaceWith( FooterValue ); 97 } 98 } else { 99 $( key ).replaceWith( value ); 100 } 101 }); 102 103 sessionStorage.setItem( fragment_name, JSON.stringify( data.fragments ) ); 104 localStorage.setItem( cart_hash_key, data.cart_hash ); 105 sessionStorage.setItem( cart_hash_key, data.cart_hash ); 106 107 if ( data.cart_hash ) { 108 sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() ); 109 } 110 } 111 }, 112 dataType: 'json', 113 method: 'GET', 114 }); 115 }, 500 ); 116 }); 117 118 if ( $('.rh-loop-quantity form.cart').length ) { 119 $('.rh-loop-quantity .qty').on('input', function() { 120 $(this).closest('.rh-loop-quantity').find('.ajax_add_to_cart').attr('data-quantity', $(this).val()); 121 }); 122 } 123});
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.