1jQuery(document).ready(function($){ 2 // 'use strict'; 3 4 var wacUpdateTimeout = null; 5 6 wacChange = function(qtyInput) { 7 8 9 // ask user if they really want to remove this product 10 if ( ( wooajaxcart.confirm_zero_qty == 'yes' ) && !wacZeroQuantityCheck(qtyInput) ) { 11 return false; 12 } 13 14 // when qty is set to zero, then fires default woocommerce remove link 15 if ( qtyInput.val() == 0 ) { 16 var removeLink = qtyInput.closest('.cart_item').find('.product-remove a'); 17 removeLink.trigger('click'); 18 return false; 19 } 20 21 // clear previous timeout, if exists 22 if ( wacUpdateTimeout !== null ) { 23 clearTimeout(wacUpdateTimeout); 24 } 25 26 wacUpdateTimeout = setTimeout(function(){ 27 wacRefreshCart(qtyInput); 28 }, wooajaxcart.ajax_timeout); 29 30 return true; 31 }; 32 33 wacRefreshCart = function(qtyInput) { 34 35 // some themes creates multiple cart forms so it will try to find the correct update button 36 if ( qtyInput.closest('.woocommerce-cart-form').length ) { 37 var mainSelector = qtyInput.closest('.woocommerce-cart-form'); 38 } 39 else { 40 var mainSelector = $(document); 41 } 42 43 // deal with update cart button 44 var updateButton = mainSelector.find("button[name='update_cart']:not(.dgfw-add-gift-button),input[name='update_cart']:not(.dgfw-add-gift-button)"); 45 46 updateButton.removeAttr('disabled') 47 .trigger('click') 48 .val( wooajaxcart.updating_text ) 49 .prop('disabled', true); 50 51 // change the Update cart button 52 $("a.checkout-button.wc-forward").addClass('disabled') 53 .html( wooajaxcart.updating_text ); 54 }; 55 56 // overrided by wac-js-calls.php 57 var wacZeroQuantityCheck = function(qtyInput) { 58 // when changes quantity to zero 59 if ( parseInt(qtyInput.val()) == 0 && !confirm(wooajaxcart.warn_remove_text) ) { 60 var newQty = wacResetNewQty(qtyInput); 61 qtyInput.val( newQty); 62 63 return false; 64 } 65 66 // when empty the quantity input 67 if ( qtyInput.val().length === 0 && !confirm(wooajaxcart.warn_remove_text) ) { 68 var newQty = wacResetNewQty(qtyInput); 69 qtyInput.val( newQty ).trigger('change'); 70 71 return false; 72 } 73 74 return true; 75 }; 76 77 var wacResetNewQty = function(qtyInput) { 78 var min = qtyInput.attr('min'); 79 80 if ( min != 'undefined' ) { 81 var newQty = ( ( min > 0 ) ? min : 1 ); 82 } 83 else { 84 var newQty = 1; 85 }; 86 87 return newQty; 88 }; 89 90 var wacListenQtyChange = function() { 91 $(document).on('change', '.qty', function(e){ 92 // prevent troubles with WooCommerce Product Bundles plugin 93 if ( $('.bundle_add_to_cart_button').length ) { 94 return true; 95 } 96 97 // prevent to set invalid quantity on select 98 if ( $(this).is('select') && ( $(this).attr('max') > 0 ) && 99 ( parseInt($(this).val()) > parseInt($(this).attr('max')) ) ) { 100 $(this).val( $(this).attr('max') ); 101 102 e.preventDefault(); 103 return false; 104 } 105 106 return wacChange( $(this) ); 107 }); 108 }; 109 110 var wacFindInputQty = function(btn) { 111 var inputQty = btn.parent().parent().parent().find('.qty'); 112 113 if ( !inputQty.length ) { 114 inputQty = btn.closest('.cart').find('.qty'); 115 } 116 117 if ( !inputQty.length ) { 118 inputQty = btn.closest('.product-quantity').find('.qty'); 119 } 120 121 return inputQty; 122 }; 123 124 wacListenQtyButtons = function() { 125 var fnIncrement = function(e){ 126 if ( $(this).hasClass('disabled') ) { 127 e.preventDefault(); 128 return false; 129 } 130 131 var inputQty = wacFindInputQty( $(this) ); 132 133 if ( inputQty.attr('max') != 'undefined' && parseFloat(inputQty.val()) >= parseFloat(inputQty.attr('max')) ) { 134 return false;
135 } 136 137 inputQty.val( function(i, oldval) { return ++oldval; }); 138 inputQty.trigger('change'); 139 140 return false; 141 }; 142 143 var fnDecrement = function(e){ 144 if ( $(this).hasClass('disabled') ) { 145 e.preventDefault(); 146 return false; 147 } 148 149 var inputQty = wacFindInputQty( $(this) ); 150 var oldVal = inputQty.val(); 151 152 if ( inputQty.attr('min') != 'undefined' && parseInt(inputQty.attr('min')) >= oldVal ) { 153 return false; 154 } 155 156 inputQty.val( --oldVal ); 157 inputQty.trigger('change'); 158 159 return false; 160 }; 161 162 if ( $('.wac-btn-inc').length ) { 163 // fix common style problem in single product page 164 if ( !$('#wac-style-prod-qty').length ) { 165 $("<style type='text/css' id='wac-style-prod-qty'>.product .quantity { display: inline; float: none !important; margin-right: 0 !important; }</style>").appendTo('head'); 166 } 167 168 $('.wac-btn-inc').off('click.wac2910').on('click.wac2910', fnIncrement); 169 $('.wac-btn-sub').off('click.wac2911').on('click.wac2911', fnDecrement); 170 171 if ( $('.grid').length ) { 172 setTimeout(wacListenQtyButtons, 500); 173 } 174 } 175 176 $(document).off('click.wac3000').on('click.wac3000', '.wac-btn-inc', fnIncrement); 177 $(document).off('click.wac3001').on('click.wac3001', '.wac-btn-sub', fnDecrement); 178 }; 179 180 // onload calls 181 wacListenQtyChange(); 182 wacListenQtyButtons(); 183 184 $(document.body).on('wc_fragments_refreshed', function(){ 185 wacListenQtyButtons(); 186 }); 187 188 $( document.body ).on( 'added_to_cart', function( event, fragments, cart_hash ) { 189 // prevent woocommerce to reload the page after Add to cart in certain conditions (outside Cart page) 190 // the window.location.reload() was defined in woo cart.js script 191 if ( $( '.woocommerce-cart-form' ).length == 0 ) { 192 $('body').append('<div class="woocommerce-cart-form" style="display: none;"></div>'); 193 } 194 }); 195});
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.