1(function($) { 2 "use strict"; 3 4 if ( ! String.prototype.getDecimals ) { 5 String.prototype.getDecimals = function() { 6 var num = this, 7 match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 8 if ( ! match ) { 9 return 0; 10 } 11 return Math.max( 0, ( match[1] ? match[1].length : 0 ) - ( match[2] ? +match[2] : 0 ) ); 12 } 13 } 14 15 $.extend($.goalThemeCore, { 16 /** 17 * Initialize scripts 18 */ 19 qty_init: function() { 20 var self = this; 21 22 $( document ).on( 'updated_wc_div', function() { 23 self.refresh_quantity_increments(); 24 } ); 25 26 $( document.body ).on( 'cart_page_refreshed', function() { 27 self.refresh_quantity_increments(); 28 }); 29 30 self.refresh_quantity_increments(); 31 32 self.qty_action(); 33 }, 34 qty_action: function() { 35 $( document ).on( 'click', '.plus, .minus', function() { 36 // Get values 37 var $qty = $( this ).closest( '.quantity' ).find( '.qty'), 38 currentVal = parseFloat( $qty.val() ), 39 max = parseFloat( $qty.attr( 'max' ) ), 40 min = parseFloat( $qty.attr( 'min' ) ), 41 step = $qty.attr( 'step' ); 42 43 // Format values 44 if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0; 45 if ( max === '' || max === 'NaN' ) max = ''; 46 if ( min === '' || min === 'NaN' ) min = 0; 47 if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) === 'NaN' ) step = 1; 48 49 // Change the value 50 if ( $( this ).is( '.plus' ) ) { 51 if ( max && ( currentVal >= max ) ) { 52 $qty.val( max ); 53 } else { 54 $qty.val( ( currentVal + parseFloat( step )).toFixed( step.getDecimals() ) ); 55 } 56 } else { 57 if ( min && ( currentVal <= min ) ) { 58 $qty.val( min ); 59 } else if ( currentVal > 0 ) { 60 $qty.val( ( currentVal - parseFloat( step )).toFixed( step.getDecimals() ) ); 61 } 62 } 63 64 // Trigger change event 65 $qty.trigger( 'change' ); 66 }); 67 }, 68 refresh_quantity_increments: function () { 69 $( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<input type="button" value="+" class="plus" />' ).prepend( '<input type="button" value="-" class="minus" />' ); 70 } 71 }); 72 73 $.goalThemeExtensions.quantity_increment = $.goalThemeCore.qty_init; 74})(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.