1$(function () { 2 3 function updateCart(data) 4 { 5 $(".cart-total").html(data.total); 6 $('.js-cart-preview-count').html(data.count); 7 $('.js-cart-preview-total').html(data.total); 8 9 if (data.discount_numeric) { 10 $(".cart-discount").closest('div.row').show(); 11 } 12 $(".cart-discount").html('− ' + data.discount); 13 14 if (data.add_affiliate_bonus) { 15 $(".affiliate").show().html(data.add_affiliate_bonus); 16 } else { 17 $(".affiliate").hide(); 18 } 19 20 if (data.affiliate_discount) { 21 $('.affiliate-discount-available').html(data.affiliate_discount); 22 if ($('.affiliate-discount').data('use')) { 23 $('.affiliate-discount').html('− ' + data.affiliate_discount); 24 } 25 } 26 27 updateTotalsaved(data); 28 } 29 30 function updateTotalsaved(data){ 31 var totalSavedWrap = $('.js-cart-saved-total'), 32 totalSavedWrapOuter = $('.js-cart-saved-total-outer'), 33 cartItems = $(".js-cart-item, .js-cart-product"); 34 35 if(totalSavedWrap.length){ 36 var totalSaved = 0; 37 38 totalSavedWrapOuter.addClass("display-none"); 39 40 if(cartItems.length){ 41 cartItems.each(function (){ 42 var item = $(this), 43 quantity = parseInt(item.find(".js-qty .qty").val()), 44 itemPriceWrap = item.find(".js-item-total"), 45 itemComparePriceWrap = item.find(".js-item-compare-price"); 46 47 if(itemPriceWrap.length && itemComparePriceWrap.length){ 48 var price = parseFloat(itemPriceWrap.data("price-item")), 49 priceCompare = parseFloat(itemComparePriceWrap.data("compare-price")); 50 51 if(price > 0 && priceCompare > price){ 52 totalSaved += ((priceCompare - price)*quantity); 53 } 54 } 55 }); 56 } 57 58 59 if(data.discount_numeric){ 60 totalSaved += parseFloat(data.discount_numeric); 61 } 62 63 if(data.affiliate_discount){ 64 var affiliateWrap = $('.js-affiliate-discount'), 65 affiliateDiscount = affiliateWrap.data("affiliate"); 66 67 if(affiliateDiscount){ 68 totalSaved += parseFloat(affiliateDiscount); 69 } 70 71 } 72 73 if(totalSaved > 0){ 74 totalSavedWrap.html(currencyFormat(totalSaved)); 75 totalSavedWrapOuter.removeClass("display-none"); 76 } 77 } 78 } 79 80 function changeQty(productWrap, quantityInput, url){ 81 var quantity = quantityInput.val(), 82 id = productWrap.data('id'); 83 84 if (parseInt(quantity) > 0) { 85 $.post(url, {html: 1, id: id, quantity: quantity}, function (response) { 86 var itemTotalWrap = productWrap.find('.js-item-total'), 87 itemCompareTotalWrap = productWrap.find('.js-item-compare-price'), 88 itemSavedTotalWrap = productWrap.find('.js-item-saved-price'); 89 90 if(response.data.item_total.charAt(0) == '0' && itemTotalWrap.data('text')){ 91 itemTotalWrap.html(itemTotalWrap.data('text')); 92 }else{ 93 itemTotalWrap.html(response.data.item_total); 94 } 95 if (response.data.q) { 96 quantityInput.val(response.data.q); 97 quantity = response.data.q; 98 } 99 if(itemCompareTotalWrap.length && quantity){ 100 var itemComparePrice = itemCompareTotalWrap.data("compare-price"), 101 itemTotalComparePrice = parseFloat(itemComparePrice)*parseFloat(quantity); 102 103 itemCompareTotalWrap.html(currencyFormat(itemTotalComparePrice)); 104 105 if(itemSavedTotalWrap.length){ 106 var itemPrice = itemTotalWrap.data("price-item"), 107 itemTotalPrice = parseFloat(itemPrice)*parseFloat(quantity), 108 itemSavedTotal = itemTotalComparePrice - itemTotalPrice; 109 110 itemSavedTotalWrap.html("-" + currencyFormat(itemSavedTotal)); 111 } 112 } 113 114 if (response.data.error) { 115 alert(response.data.error); 116 } else { 117 quantityInput.removeClass('error'); 118 } 119 updateCart(response.data); 120 }, "json"); 121 122 } else { 123 quantityInput.val(1); 124 } 125 } 126 127 $(".cart .delete").click(function () { 128 var row = $(this).closest('div.row'); 129 $.post('delete/', {html: 1, id: row.data('id')}, function (response) { 130 if (response.data.count == 0) { 131 location.reload(); 132 } 133 row.remove(); 134 updateCart(response.data); 135 sidebarCart.clearItem(row.data('product-id'), row.data('data-id')); 136 $('input[name="product_id"][value="'+ row.data('product-id') +'"]').closest(".
136js-add-to-cart").find(".js-submit-form, .js-product-card-dialog").removeClass("added"); 137 }, "json"); 138 }); 139 140 $(".js-cart-preview-product-delete").on("click", function(){ 141 var row = $(this).closest('.js-cart-product'), 142 cartWrap = $(this).closest('.js-cart-ajax'), 143 url = cartWrap.data("url"); 144 145 $.post(url+'delete/', {html: 1, id: row.data('id')}, function (response) { 146 sidebarCart.clearItem(row.data('product-id'), row.data('data-id')); 147 $('input[name="product_id"][value="'+ row.data('product-id') +'"]').closest(".js-add-to-cart").find(".js-submit-form, .js-product-card-dialog").removeClass("added"); 148 row.fadeOut("500", function() { 149 row.remove(); 150 updateCart(response.data); 151 152 $('.js-cart-preview-count').html(response.data.count); 153 $('.js-cart-preview-total').html(response.data.total); 154 155 if (response.data.count == 0) { 156 $('.js-cart-popup').html(""); 157 setTimeout(function (){ 158 $('.js-fixed-cart-outer').html(""); 159 }, 300); 160 161 $('.js-cart-preview').addClass('empty'); 162 } 163 }); 164 }, "json"); 165 }); 166 167 $(".cart input.qty").change(function () { 168 var quantityInput = $(this), 169 productWrap = quantityInput.closest('div.row'); 170 171 changeQty(productWrap, quantityInput, 'save/'); 172 }); 173 174 $(".js-cart-ajax input.qty").change(function () { 175 var quantityInput = $(this), 176 productWrap = quantityInput.closest('.js-cart-product'); 177 178 changeQty(productWrap, quantityInput, $('.js-fixed-cart-outer').data("cart-url") + 'save/'); 179 }); 180 181 $(".js-cart-services input:checkbox").change(function () { 182 var obj = $('select[name="service_variant[' + $(this).closest('div.row').data('id') + '][' + $(this).val() + ']"]'); 183 if (obj.length) { 184 if ($(this).is(':checked')) { 185 obj.removeAttr('disabled').trigger('refresh');; 186 187 } else { 188 obj.attr('disabled', 'disabled').trigger('refresh');; 189 } 190 } 191 192 var div = $(this).closest('.js-cart-service'); 193 var row = $(this).closest('div.row'); 194 if ($(this).is(':checked')) { 195 var parent_id = row.data('id') 196 var data = {html: 1, parent_id: parent_id, service_id: $(this).val()}; 197 var $variants = $('[name="service_variant[' + parent_id + '][' + $(this).val() + ']"]'); 198 if ($variants.length) { 199 data['service_variant_id'] = $variants.val(); 200 } 201 $.post('add/', data, function(response) { 202 div.data('id', response.data.id); 203 row.find('.js-item-total').html(response.data.item_total); 204 updateCart(response.data); 205 }, "json"); 206 } else { 207 $.post('delete/', {html: 1, id: div.data('id')}, function (response) { 208 div.data('id', null); 209 row.find('.js-item-total').html(response.data.item_total); 210 updateCart(response.data); 211 }, "json"); 212 } 213 }); 214 215 $(".js-cart-services select").change(function () { 216 var row = $(this).closest('div.row'); 217 $.post('save/', {html: 1, id: $(this).closest('.js-cart-service').data('id'), 'service_variant_id': $(this).val()}, function (response) { 218 row.find('.js-item-total').html(response.data.item_total); 219 updateCart(response.data); 220 }, "json"); 221 }); 222 223 $("#cancel-affiliate").click(function () { 224 $(this).closest('form').append('<input type="hidden" name="use_affiliate" value="0">').submit(); 225 return false; 226 }); 227 228 229 $("#use-affiliate").click(function () { 230 $(this).closest('form').append('<input type="hidden" name="use_affiliate" value="1">').submit(); 231 }); 232 233 $("#use-coupon").click(function () { 234 $('#discount-row:hidden').slideToggle(200); 235 $('#apply-coupon-code:hidden').show(); 236 $('#apply-coupon-code input[type="text"]').focus(); 237 $(this).hide(); 238 return false;
239 }); 240 241 // listen coupon input value for change and hide its error message if changing have been happened 242 243 var onInputChange = function ($input, onChange) { 244 var prev_input_val = $input.val() || ''; 245 var timer_id, timeout = 500; 246 $input.keydown(function () { 247 if (timer_id) { 248 clearTimeout(timer_id); 249 } 250 timer_id = setTimeout(function () { 251 if (prev_input_val !== $input.val()) { 252 onChange.apply($input, arguments); 253 } 254 prev_input_val = $input.val(); 255 }, timeout); 256 }).change(onChange); 257 }; 258 259 onInputChange($('#apply-coupon-code input[type="text"]'), function () { 260 $('#apply-coupon-code .errormsg').hide(); 261 }); 262 263 $("div.addtocart input:button").click(function () { 264 var f = $(this).closest('div.addtocart'); 265 if (f.data('url')) { 266 var d = $('#dialog'); 267 var c = d.find('.cart'); 268 c.load(f.data('url'), function () { 269 c.prepend('<a href="#" class="dialog-close">×</a>'); 270 c.find('form').data('cart', 1); 271 d.show(); 272 if ((c.height() > c.find('form').height())) { 273 c.css('bottom', 'auto'); 274 } else { 275 c.css('bottom', '15%'); 276 } 277 }); 278 return false; 279 } 280 $.post($(this).data('url'), {html: 1, product_id: $(this).data('product_id')}, function (response) { 281 if (response.status == 'ok') { 282 var cart_total = $(".cart-total"); 283 $("#page-content").load(location.href, function () { 284 cart_total.closest('#cart').removeClass('empty'); 285 cart_total.html(response.data.total); 286 $('#cart').addClass('fixed'); 287 288 var $addedText = $('<div class="cart-just-added"></div>').html(f.find('span.added2cart').text()); 289 $('#cart-content').append($addedText); 290 setTimeout( function() { 291 $addedText.remove(); 292 }, 2000); 293 294 $('.cart-to-checkout').slideDown(200); 295 }); 296 } 297 }, 'json'); 298 return false; 299 }); 300 301});
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.