1(function ($) { 2 'use strict'; 3 4 $(function () { 5 if (typeof wcspcVars !== 'undefined' && wcspcVars.reload === 'yes') { 6 wcspc_get_cart(); 7 } 8 9 wcspc_perfect_scrollbar(); 10 11 // Qty minus 12 $('body').on('click', '#wcspc-area .wcspc-item-qty-minus', function () { 13 var $input = $(this).parent().find('.wcspc-item-qty-input'); 14 var qtyMin = parseFloat($input.attr('min')) || 1; 15 var step = parseFloat($input.attr('step')) || 1; 16 var qty = parseFloat($input.val()) || qtyMin; 17 if (qty - step >= qtyMin) { 18 $input.val(qty - step).trigger('change'); 19 } 20 }); 21 22 // Qty plus 23 $('body').on('click', '#wcspc-area .wcspc-item-qty-plus', function () { 24 var $input = $(this).parent().find('.wcspc-item-qty-input'); 25 var qtyMax = parseFloat($input.attr('max')) || 9999; 26 var step = parseFloat($input.attr('step')) || 1; 27 var qty = parseFloat($input.val()) || 1; 28 if (qty + step <= qtyMax) { 29 $input.val(qty + step).trigger('change'); 30 } 31 }); 32 33 // Qty change 34 $('body').on('change', '#wcspc-area .wcspc-item-qty-input', function () { 35 var item_key = $(this).attr('data-key'); 36 var item_qty = $(this).val(); 37 wcspc_update_qty(item_key, item_qty); 38 }); 39 40 // Qty focus validate 41 var qtyInterval = false; 42 $('body').on('focus', '#wcspc-area .wcspc-item-qty-input', function () { 43 var $thisQty = $(this); 44 var min = parseFloat($thisQty.attr('min')) || 1; 45 var max = parseFloat($thisQty.attr('max')) || 9999; 46 qtyInterval = setInterval(function () { 47 var v = parseFloat($thisQty.val()); 48 if (isNaN(v) || v < min) { 49 $thisQty.val(min); 50 } 51 if (v > max) { 52 $thisQty.val(max); 53 } 54 }, 50); 55 }); 56 $('body').on('blur', '#wcspc-area .wcspc-item-qty-input', function () { 57 if (qtyInterval) { 58 clearInterval(qtyInterval); 59 qtyInterval = false; 60 } 61 var item_key = $(this).attr('data-key'); 62 var item_qty = $(this).val(); 63 wcspc_update_qty(item_key, item_qty); 64 }); 65 66 // Remove item 67 $('body').on('click', '#wcspc-area .wcspc-item-remove', function () { 68 var $item = $(this).closest('.wcspc-item'); 69 $item.addClass('wcspc-item-removing'); 70 var item_key = $(this).attr('data-key'); 71 wcspc_remove_item(item_key); 72 $item.slideUp(); 73 }); 74 75 $('body').on('click tap', '.wcspc-overlay, .wcspc-close, #wcspc-continue', function () { 76 wcspc_hide_cart(); 77 }); 78 79 $('body').on('click', '#wcspc-count, .single_add_to_cart_flyer', function () { 80 wcspc_show_cart(); 81 }); 82 83 // Auto show after add to cart 84 if (typeof wcspcVars !== 'undefined' && wcspcVars.auto_show === 'yes') { 85 $('body').on('added_to_cart', function () { 86 wcspc_get_cart(); 87 wcspc_show_cart(); 88 }); 89 } else { 90 $('body').on('added_to_cart', function () { 91 wcspc_get_cart(); 92 }); 93 } 94 95 // Manual show 96 if (typeof wcspcVars !== 'undefined' && wcspcVars.manual_show) { 97 $('body').on('click', wcspcVars.manual_show, function (e) { 98 e.preventDefault(); 99 wcspc_show_cart(); 100 }); 101 } 102 }); 103})(jQuery); 104 105function wcspc_handle_response(response, onSuccess) { 106 if (response && response.success && response.data) { 107 if (typeof onSuccess === 'function') { 108 onSuccess(response.data); 109 } 110 return; 111 } 112 var msg = (wcspcVars && wcspcVars.i18n && wcspcVars.i18n.error) 113 ? wcspcVars.i18n.error 114 : 'Something went wrong. Please try again.'; 115 if (response && response.data && response.data.message) { 116 msg = response.data.message; 117 } 118 console.warn('ATA WCSPC:', msg); 119} 120 121function wcspc_update_qty(cart_item_key, cart_item_qty) { 122 jQuery('#wcspc-count').addClass('wcspc-count-loading').removeClass('wcspc-count-shake'); 123 jQuery.post( 124 wcspcVars.ajaxurl, 125 { 126 action: 'wcspc_update_qty', 127 cart_item_key: cart_item_key, 128 cart_item_qty: cart_item_qty, 129 security: wcspcVars.nonce 130 }, 131 function (response) { 132 wcspc_handle_response(response, function (data) { 133 if (data.html) { 134 jQuery('#wcspc-area').html(data.html); 135 wcspc_perfect_scrollbar(); 136 } 137 if (data.subtotal) { 138 jQuery('#wcspc-subtotal').html(data.subtotal); 139 } 140 jQuery('#wcspc-count-number').html(data.count); 141 jQuery('.fly_counter_load').html(data.count); 142 jQuery('#wcspc-count').addClass('wcspc-count-shake').removeClass('wcspc-count-loading'); 143 if (wcspcVars.hide_count_empty === 'yes' && parseInt(data.count, 10) === 0) { 144 jQuery('#wcspc-count').addClass('wcspc-count-hide'); 145 } else { 146 jQuery('#wcspc-count').removeClass('wcspc-count-hide'); 147 } 148 }); 149 } 150 ).fail(function () { 151 jQuery('#wcspc-count').removeClass('wcspc-count-loading'); 152 }); 153} 154 155function wcspc_remove_item(cart_item_key) { 156 jQuery('#wcspc-count').addClass('wcspc-count-loading').removeClass('wcspc-count-shake'); 157 jQuery.post( 158 wcspcVars.ajaxurl, 159 { 160 action: 'wcspc_remove_item', 161 cart_item_key: cart_item_key, 162 security: wcspcVars.nonce 163 }, 164 function (response) { 165 wcspc_handle_response(response, function (data) { 166 if (data.html) { 167 jQuery('#wcspc-area').html(data.html); 168 wcspc_perfect_scrollbar(); 169 } 170 if (data.subtotal) { 171 jQuery('#wcspc-subtotal').html(data.subtotal); 172 } 173 jQuery('#wcspc-count-number').html(data.count); 174 jQuery('.fly_counter_load').html(data.count); 175 jQuery('#wcspc-count').addClass('wcspc-count-shake').removeClass('wcspc-count-loading'); 176 if (wcspcVars.hide_count_empty === 'yes' && parseInt(data.count, 10) === 0) { 177 jQuery('#wcspc-count').addClass('wcspc-count-hide'); 178 } else { 179 jQuery('#wcspc-count').removeClass('wcspc-count-hide'); 180 } 181 }); 182 } 183 ).fail(function () { 184 jQuery('#wcspc-count').removeClass('wcspc-count-loading'); 185 }); 186} 187 188function wcspc_get_cart() { 189 jQuery('#wcspc-area').addClass('wcspc-area-loading'); 190 jQuery('#wcspc-count').addClass('wcspc-count-loading').removeClass('wcspc-count-shake'); 191 jQuery.post( 192 wcspcVars.ajaxurl, 193 { 194 action: 'wcspc_get_cart', 195 security: wcspcVars.nonce 196 }, 197 function (response) { 198 wcspc_handle_response(response, function (data) { 199 jQuery('#wcspc-area').html(data.html); 200 jQuery('.fly_counter_load').html(data.count); 201 wcspc_perfect_scrollbar(); 202 jQuery('#wcspc-count-number').html(data.count); 203 jQuery('#wcspc-area').removeClass('wcspc-area-loading'); 204 jQuery('#wcspc-count').addClass('wcspc-count-shake').removeClass('wcspc-count-loading'); 205 var hideEmpty = wcspcVars.hide_count_empty === 'yes' && parseInt(data.count, 10) === 0; 206 var hideCheckout = wcspcVars.hide_count_checkout === 'yes' && 207 (jQuery('body').hasClass('woocommerce-cart') || jQuery('body').hasClass('woocommerce-checkout')); 208 if (hideEmpty || hideCheckout) { 209 jQuery('#wcspc-count').addClass('wcspc-count-hide'); 210 } else { 211 jQuery('#wcspc-count').removeClass('wcspc-count-hide'); 212 } 213 }); 214 } 215 ).fail(function () { 216 jQuery('#wcspc-area').removeClass('wcspc-area-loading'); 217 jQuery('#wcspc-count').removeClass('wcspc-count-loading'); 218 }); 219} 220 221function wcspc_perfect_scrollbar() { 222 if (jQuery.fn.perfectScrollbar) { 223 jQuery('#wcspc-area .wcspc-area-top').perfectScrollbar({ suppressScrollX: true, theme: 'wcspc' }); 224 } 225} 226 227function wcspc_show_cart() { 228 jQuery('body').addClass('wcspc-body-show'); 229 jQuery('#wcspc-area').addClass('wcspc-area-show'); 230} 231 232function wcspc_hide_cart() { 233 jQuery('#wcspc-area').removeClass('wcspc-area-show'); 234 jQuery('body').removeClass('wcspc-body-show'); 235}
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.