1var communityStore = { 2 3 openModal: function(content, animatecart) { 4 var whiteout = $(".store-whiteout"); 5 6 if (whiteout.length) { 7 whiteout.empty().html(content); 8 } else { 9 $(".ccm-page").append("<div class='store-whiteout'>" + content + "</div>"); 10 11 setTimeout(function() { 12 $('.store-cart-modal').addClass('store-cart-modal-active'); 13 }, 10); 14 15 whiteout.click(function(e) { 16 if (e.target != this) return; // only allow the actual whiteout background to close the dialog 17 communityStore.exitModal(); 18 }); 19 20 $(document).keyup("keyup.communitywhiteout", function(e) { 21 if (e.keyCode === 27) { 22 communityStore.exitModal(); 23 $(document).unbind("keyup.communitywhiteout"); 24 } 25 }); 26 } 27 28 if (animatecart) { 29 setTimeout(function() { 30 $('.store-cart-modal').addClass('store-cart-modal-active'); 31 }, 10); 32 } else { 33 $('.store-cart-modal').addClass('store-cart-modal-active'); 34 } 35 }, 36 37 waiting: function() { 38 communityStore.openModal("<div class='store-spinner-container'><div class='store-spinner'></div></div>"); 39 }, 40 41 exitModal: function() { 42 $(".store-whiteout").remove(); 43 }, 44 45 productModal: function(pID, locale) { 46 communityStore.waiting(); 47 $.ajax({
48 url: PRODUCTMODAL, 49 data: { pID: pID, locale: locale }, 50 type: 'get', 51 cache: false, 52 dataType: 'text', 53 success: function(modalContent) { 54 communityStore.openModal(modalContent); 55 } 56 }); 57 }, 58 59 displayCart: function(res, animatecart) { 60 $.ajax({ 61 type: "POST", 62 cache: false, 63 dataType: 'text', 64 data: res, 65 url: CARTURL + '/getmodal' + TRAILINGSLASH, 66 success: function(data) { 67 communityStore.openModal(data, animatecart); 68 } 69 }); 70 }, 71 72 addToCart: function(pID, type) { 73 var form; 74 if (type == 'modal') { 75 form = $('#store-form-add-to-cart-modal-' + pID); 76 } else if (type == 'list') { 77 form = $('#store-form-add-to-cart-list-' + pID); 78 } else { 79 form = $('#store-form-add-to-cart-' + pID); 80 } 81 82 var valid = true; 83 84 85 var priceinput = $(form).find('.store-product-customer-price-entry-field'); 86 87 if (priceinput.length > 0) { 88 var max = parseFloat(priceinput.attr('max')); 89 var min = parseFloat(priceinput.attr('min')); 90 var customerprice = parseFloat(priceinput.val()); 91 92 if (customerprice < min || customerprice > max || !isFinite(customerprice)) { 93 priceinput.focus(); 94 valid = false; 95 } 96 97 } 98 99 $(form).find('input,textarea,select').filter('[required]').each(function(i, requiredField) { 100 if ($(requiredField).val() == '') { 101 $(requiredField).focus(); 102 valid = false; 103 } 104 }); 105 106 if (!valid) { 107 return false; 108 } 109 110 var qtyfield = $(form).find('.store-product-qty'); 111 var qty = qtyfield.val(); 112 if (qty > 0) { 113 var serial = $(form).serialize(); 114 communityStore.waiting(); 115 $.ajax({
116 url: CARTURL + "/add" + TRAILINGSLASH, 117 data: serial, 118 type: 'post', 119 cache: false, 120 dataType: 'text', 121 success: function(data) { 122 var res = jQuery.parseJSON(data); 123 124 if (res.product.pAutoCheckout == '1') { 125 window.location.href = CHECKOUTURL; 126 return false; 127 } 128 129 communityStore.displayCart(res, true); 130 communityStore.refreshCartTotals(); 131 } 132 }); 133 } else { 134 alert(QTYMESSAGE); 135 qtyfield.focus(); 136 } 137 }, 138 139 //Update a single item in cart 140 updateItem: function(instanceID, modal) { 141 var qty = $("*[data-instance-id='" + instanceID + "']").find(".store-cart-list-product-qty .form-control").val(); 142 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 143 //communityStore.waiting(); 144 $.ajax({
145 url: CARTURL + "/update" + TRAILINGSLASH, 146 data: { instance: instanceID, pQty: qty, ccm_token: ccm_token }, 147 type: 'post', 148 cache: false, 149 dataType: 'text', 150 success: function(data) { 151 if (modal) { 152 var res = jQuery.parseJSON(data); 153 communityStore.displayCart(res); 154 communityStore.refreshCartTotals(); 155 } 156 } 157 }); 158 }, 159 160 161 //Update multiple item quantities 162 updateMultiple: function(instances, quantities, modal) { 163 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 164 165 $.ajax({ 166 url: CARTURL + "/update" + TRAILINGSLASH, 167 data: { instance: instances, pQty: quantities, ccm_token: ccm_token }, 168 type: 'post', 169 cache: false, 170 dataType: 'text', 171 success: function(data) { 172 if (modal) { 173 var res = jQuery.parseJSON(data); 174 communityStore.displayCart(res); 175 communityStore.refreshCartTotals(); 176 } 177 } 178 }); 179 }, 180 181 removeItem: function(instanceID, modal) { 182 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 183 $.ajax({
184 url: CARTURL + "/remove" + TRAILINGSLASH, 185 data: { instance: instanceID, ccm_token: ccm_token }, 186 type: 'post', 187 cache: false, 188 dataType: 'text', 189 success: function(data) { 190 if (modal) { 191 var res = jQuery.parseJSON(data); 192 communityStore.displayCart(res); 193 communityStore.refreshCartTotals(); 194 } 195 } 196 }); 197 }, 198 199 clearCart: function(modal) { 200 var ccm_token = $('#store-modal-cart').find('[name=ccm_token]').val(); 201 $.ajax({ 202 url: CARTURL + "/clear" + TRAILINGSLASH, 203 type: 'post', 204 cache: false, 205 dataType: 'text', 206 data: { clear: 1, ccm_token: ccm_token }, 207 success: function(data) { 208 if (modal) { 209 var res = jQuery.parseJSON(data); 210 communityStore.displayCart(res); 211 } 212 213 $(".store-utility-links .store-items-counter").text(0); 214 $(".store-utility-links .store-total-cart-amount").text(""); 215 $(".store-utility-links").addClass('store-cart-empty'); 216 } 217 }); 218 }, 219 220 refreshCartTotals: function(callback) { 221 $.ajax({
222 url: CARTURL + '/getCartSummary' + TRAILINGSLASH, 223 cache: false, 224 dataType: 'text', 225 success: function(response) { 226 var values = $.parseJSON(response); 227 var itemCount = values.itemCount; 228 var subTotal = values.subTotal; 229 var total = values.total; 230 var totalCents = values.totalCents; 231 var taxes = values.taxes; 232 var shippingTotal = values.shippingTotal; 233 var shippingTotalRaw = values.shippingTotalRaw; 234 235 if (itemCount == 0) { 236 $(".store-utility-links .store-items-counter").text(0); 237 $(".store-utility-links .store-total-cart-amount").text(""); 238 $(".store-utility-links").addClass('store-cart-empty'); 239 } else { 240 $(".store-utility-links .store-items-counter").text(itemCount); 241 $(".store-cart-grand-total-value").text(total); 242 $(".store-utility-links .store-total-cart-amount").text(total); 243 $(".store-utility-links").removeClass('store-cart-empty'); 244 } 245 246 if (shippingTotalRaw === false) { 247 $("#shipping-total").text($("#shipping-total").data('unknown-label')); 248 } else if (shippingTotalRaw <= 0) { 249 $("#shipping-total").text($("#shipping-total").data('no-charge-label')); 250 } else { 251 $("#shipping-total").text(shippingTotal); 252 } 253 254 $("#store-taxes").html(""); 255 for (var i = 0; i < taxes.length; i++) { 256 if (taxes[i].taxed === true) { 257 $("#store-taxes").append('<li class="store-line-item store-tax-item list-group-item"><strong>' + taxes[i].name + ":</strong> <span class=\"store-tax-amount\">" + taxes[i].taxamount + "</span></li>"); 258 } 259 } 260 261 $(".store-sub-total-amount").text(subTotal); 262 $(".store-total-amount").text(total); 263 $(".store-total-amount").data('total-cents', totalCents); 264 265 if (callback) { 266 callback(); 267 } 268 } 269 }); 270 }, 271 272 // checkout 273 loadViaHash: function() { 274 var hash = window.location.hash; 275 hash = hash.replace('#', ''); 276 if (hash != "") { 277 $(".store-active-form-group").removeClass('store-active-form-group'); 278 var pane = $("#store-checkout-form-group-" + hash); 279 pane.addClass('store-active-form-group'); 280 281 $('html, body').animate({ 282 scrollTop: pane.offset().top - CHECKOUTSCROLLOFFSET 283 }); 284 } 285 }, 286 287 updateBillingStates: function(load, callback) { 288 var countryCode = $("#store-checkout-billing-country").val(); 289 var selectedState; 290 var classList = $("#store-checkout-billing-state").attr('class').toString(); 291 var dataList = JSON.stringify($("#store-checkout-billing-state").data()); 292 if (load) { 293 selectedState = $("#store-checkout-saved-billing-state").val(); 294 } else { 295 selectedState = ''; 296 } 297 298 $.ajax({
299 url: HELPERSURL + "/stateprovince/getstates" + TRAILINGSLASH, 300 type: 'post', 301 cache: false, 302 dataType: 'text', 303 data: { country: countryCode, selectedState: selectedState, type: "billing", class: classList, data: dataList }, 304 success: function(states) { 305 $("#store-checkout-billing-state").replaceWith(states); 306 if (callback) { 307 callback(); 308 } 309 } 310 }); 311 }, 312 313 updateShippingStates: function(load, callback) { 314 var countryCode = $("#store-checkout-shipping-country").val(); 315 var selectedState; 316 var classList = $("#store-checkout-shipping-state").attr('class').toString(); 317 var dataList = JSON.stringify($("#store-checkout-shipping-state").data()); 318 319 if (load) { 320 selectedState = $("#store-checkout-saved-shipping-state").val(); 321 } else { 322 selectedState = ''; 323 } 324 325 $.ajax({ 326 url: HELPERSURL + "/stateprovince/getstates" + TRAILINGSLASH, 327 type: 'post', 328 cache: false, 329 dataType: 'text', 330 data: { country: countryCode, selectedState: selectedState, type: "shipping", class: classList, data: dataList }, 331 success: function(states) { 332 $("#store-checkout-shipping-state").replaceWith(states); 333 if (callback) { 334 callback(); 335 } 336 } 337 }); 338 }, 339 340 nextPane: function(obj) { 341 if (typeof $(obj)[0].checkValidity === "undefined" || $(obj)[0].checkValidity()) { 342 var pane = $(obj).closest(".store-checkout-form-group").find('.store-checkout-form-group-body').parent().next(); 343 $('.store-active-form-group').removeClass('store-active-form-group'); 344 pane.addClass('store-active-form-group'); 345 $(obj).closest(".store-checkout-form-group").addClass('store-checkout-form-group-complete'); 346 347 $('html, body').animate({ 348 scrollTop: pane.offset().top - CHECKOUTSCROLLOFFSET 349 }); 350 351 pane.find('input').first().focus(); 352 } 353 }, 354 355 showShippingMethods: function(callback) { 356 $.ajax({
357 url: HELPERSURL + "/shipping/getshippingmethods" + TRAILINGSLASH, 358 cache: false, 359 dataType: 'text', 360 success: function(html) { 361 $("#store-checkout-shipping-method-options").html(html); 362 $('.store-whiteout').remove(); 363 364 if (callback) { 365 callback(); 366 } 367 }, 368 failure: function() { 369 $('.store-whiteout').remove(); 370 371 if (callback) { 372 callback(); 373 } 374 } 375 }); 376 }, 377 378 showPaymentForm: function() { 379 var pmID = $("#store-checkout-payment-method-options input[type='radio']:checked").attr('data-payment-method-id'); 380 $('.store-payment-method-container').addClass('d-none'); 381 $(".store-payment-method-container[data-payment-method-id='" + pmID + "']").removeClass('d-none'); 382 }, 383 384 copyBillingToShipping: function() { 385 $("#store-checkout-shipping-first-name").val($("#store-checkout-billing-first-name").val()); 386 $("#store-checkout-shipping-last-name").val($("#store-checkout-billing-last-name").val()); 387 $("#store-checkout-shipping-email").val($("#store-checkout-billing-email").val()); 388 $("#store-checkout-shipping-phone").val($("#store-checkout-billing-phone").val()); 389 390 if ($("#store-checkout-billing-company")) { 391 $("#store-checkout-shipping-company").val($("#store-checkout-billing-company").val()); 392 } 393 394 $("#store-checkout-shipping-address-1").val($("#store-checkout-billing-address-1").val()); 395 $("#store-checkout-shipping-address-2").val($("#store-checkout-billing-address-2").val()); 396 $("#store-checkout-shipping-country").val($("#store-checkout-billing-country").val()); 397 $("#store-checkout-shipping-city").val($("#store-checkout-billing-city").val()); 398 var billingstate = $("#store-checkout-billing-state").clone().val($("#store-checkout-billing-state").val()).attr("name", "store-checkout-shipping-state").attr("id", "store-checkout-shipping-state"); 399 $("#store-checkout-shipping-state").replaceWith(billingstate); 400 $("#store-checkout-shipping-zip").val($("#store-checkout-billing-zip").val()); 401 }, 402 403 sortNumber: function(a, b) { 404 return a - b; 405 }, 406 hasFormValidation: function() { 407 return (typeof document.createElement('input').checkValidity == 'function'); 408 }, 409 submitProductFilter: function(element) { 410 var filterform = element.closest('form'); 411 var checkboxes = filterform.find(':checked'); 412 var search = {}; 413 var matchtypes = {}; 414 415 checkboxes.each(function(index, field) { 416 var name = field.name.replace('[]', ''); 417 var value = encodeURIComponent(field.value); 418 var matchtype = field.getAttribute('data-matching'); 419 420 if (name in search) { 421 search[name].push(value); 422 } else { 423 search[name] = [value]; 424 matchtypes[name] = [matchtype === 'or' ? '|' : ';']; 425 } 426 }); 427 428 var strings = []; 429 430 $.each(search, function(key, value) { 431 strings.push(key + '=' + value.join(matchtypes[key])); 432 }); 433 434 var price = filterform.find("[name='price']"); 435 436 if (price.length) { 437 var min = parseFloat(price.data('min'), 2); 438 var max = parseFloat(price.data('max'), 2); 439 440 var pricerange = price.val(); 441 442 if (min + '-' + max !== pricerange) { 443 strings.push('price=' + price.val()); 444 } 445 } 446 447 var searchstring = strings.join('&'); 448 449 var params = {}; 450 var hasparams = false; 451 452 location.search.substr(1).split("&").forEach(function(item) { 453 var key = item.split("=")[0]; 454 if (key.indexOf('sort') === 0) { 455 params[key] = item.split("=")[1]; 456 hasparams = true; 457 } 458 }); 459 460 if (hasparams) { 461 searchstring = searchstring + '&' + $.param(params); 462 } 463 464 var id = filterform.attr('id'); 465 466 if (id) { 467 searchstring += '#' + filterform.attr('id'); 468 } 469 470 window.location = '?' + searchstring; 471 }, 472 clearProductFilter: function(element) { 473 var filterform = element.closest('form'); 474 var checkboxes = filterform.find(':checked'); 475 var search = {}; 476 477 checkboxes.each(function(index, field) { 478 checkboxes.prop('checked', false); 479 }); 480 481 filterform.find('[name="price"]').val(''); 482 483 communityStore.submitProductFilter(element); 484 }, 485 processOtherAttributes: function() { 486 487 var extrafields = $('#store-checkout-form-group-payment #store-extrafields'); 488 489 if (extrafields.length) { 490 extrafields.remove(); 491 } 492 493 $('#store-checkout-form-group-payment').append('<div id="store-extrafields" style="display: none"></div>'); 494 495 $("#store-checkout-form-group-other-attributes .row").each(function(index, el) { 496 497 var novalue = $("#store-checkout-form-group-other-attributes").data('no-value'); 498 499 if (!novalue) { 500 novalue = ''; 501 } 502 503 var yesvalue = $("#store-checkout-form-group-other-attributes").data('yes-value'); 504 505 if (!yesvalue) { 506 yesvalue = 'Yes'; 507 } 508 509 var akID = $(el).data("akid"); 510 var field = $(el).find(".form-control"); 511 512 var value = '0'; 513 var displayvalue = ''; 514 var isselect = false; 515 516 // look for checkbox or radio 517 if (!field.length) { 518 field = $(el).find("[type=checkbox]").first(); 519 var label = $(el).find(".checkbox label").first(); 520 521 if (!label.text()) { 522 label = $(field).next(); 523 } 524 525 if (field.length) { 526 if (field.is(':checked')) { 527 value = '1'; 528 displayvalue = yesvalue; 529 } else { 530 displayvalue = novalue; 531 } 532 } else { 533 field = $(el).find('input[type=radio]:checked'); 534 if (field) { 535 displayvalue = field.closest('label').text().trim(); 536 } 537 } 538 } else { 539 value = field.val(); 540 541 if (field.is('select')) { 542 displayvalue = field.children(':selected').text(); 543 var isselect = true; 544 } else { 545 displayvalue = value; 546 } 547 } 548 549 550 if (field.length) { 551 displayvalue = displayvalue.replace(/[\n\r]/g, '<br>').trim(); 552 553 if (!displayvalue) { 554 displayvalue = '-'; 555 } 556 557 $('.store-summary-order-choices-' + akID).html(displayvalue); 558 $('#akIDinput' + akID).remove(); 559 560 var newfield = field.clone(); 561 562 if (isselect) { 563 newfield.val(field.val()); 564 } 565 566 newfield.appendTo($('#store-checkout-form-group-payment #store-extrafields')); 567 568 569 } 570 }); 571 572 }, 573 number_format: function (number, decimals, dec_point, thousands_sep) { 574 number = number*1;//makes sure `number` is numeric value 575 var str = number.toFixed(decimals?decimals:0).toString().split('.'); 576 var parts = []; 577 for ( var i=str[0].length; i>0; i-=3 ) { 578 parts.unshift(str[0].substring(Math.max(0,i-3),i)); 579 }
580 str[0] = parts.join(thousands_sep?thousands_sep:','); 581 return str.join(dec_point?dec_point:'.'); 582 } 583 584}; 585 586$(document).ready(function() { 587 if ($('.store-checkout-form-shell form').length > 0) { 588 communityStore.updateBillingStates(true); 589 if ($('#store-checkout-form-group-shipping').length > 0) { 590 communityStore.updateShippingStates(true); 591 communityStore.showShippingMethods(); 592 } 593 communityStore.showPaymentForm(); 594 } 595 596 $("#store-checkout-form-group-billing").submit(function(e) { 597 e.preventDefault(); 598 var email = $("#store-email").val(); 599 var bfName = $("#store-checkout-billing-first-name").val(); 600 var blName = $("#store-checkout-billing-last-name").val(); 601 var bPhone = $("#store-checkout-billing-phone").val(); 602 603 var bCompany = ''; 604 605 if ($("#store-checkout-billing-company")) { 606 bCompany = $("#store-checkout-billing-company").val(); 607 } 608 609 var bAddress1 = $("#store-checkout-billing-address-1").val(); 610 var bAddress2 = $("#store-checkout-billing-address-2").val(); 611 var bCountry = $("#store-checkout-billing-country").val(); 612 var bCity = $("#store-checkout-billing-city").val(); 613 var bState = $("#store-checkout-billing-state").val(); 614 var bPostal = $("#store-checkout-billing-zip").val(); 615 $("#store-checkout-form-group-billing .store-checkout-form-group-body .store-checkout-errors").remove(); 616 617 var ccm_token = $(this).find('[name=ccm_token]').val(); 618 619 if ($('#store-checkout-form-group-billing #store-checkout-form-group-other-attributes').length) { 620 communityStore.processOtherAttributes(); 621 } 622 623 communityStore.waiting(); 624 var obj = $(this); 625 $.ajax({
626 url: CHECKOUTURL + "/updater" + TRAILINGSLASH, 627 type: 'post', 628 cache: false, 629 dataType: 'text', 630 data: { 631 ccm_token: ccm_token, 632 adrType: 'billing', 633 email: email, 634 fName: bfName, 635 lName: blName, 636 phone: bPhone, 637 company: bCompany, 638 addr1: bAddress1, 639 addr2: bAddress2, 640 count: bCountry, 641 city: bCity, 642 state: bState, 643 postal: bPostal 644 }, 645 success: function(result) { 646 //var test = null; 647 var response = JSON.parse(result); 648 649 if (response.error == false) { 650 651 if ($('#store-copy-billing').is(":checked")) { 652 communityStore.copyBillingToShipping(); 653 $("#store-checkout-form-group-shipping").submit(); 654 $('#store-copy-billing').prop('checked', false) 655 } else { 656 $(".store-whiteout").remove(); 657 } 658 659 obj.find('.store-checkout-form-group-summary .store-summary-name').html(response.first_name + ' ' + response.last_name); 660 obj.find('.store-checkout-form-group-summary .store-summary-phone').html(response.phone); 661 obj.find('.store-checkout-form-group-summary .store-summary-email').html(response.email); 662 obj.find('.store-checkout-form-group-summary .store-summary-address').html(response.address); 663 obj.find('.store-checkout-form-group-summary .store-summary-company').html(response.company); 664 communityStore.nextPane(obj); 665 communityStore.refreshCartTotals(); 666 667 } else { 668 $("#store-checkout-form-group-billing .store-checkout-form-group-body ").prepend('<div class="store-checkout-errors"><div class="store-checkout-error alert alert-danger"></div></div>'); 669 $("#store-checkout-form-group-billing .store-checkout-error").html(response.errors.join('<br>')); 670 $('.store-whiteout').remove(); 671 } 672 }, 673 error: function(data) { 674 $(".store-whiteout").remove(); 675 } 676 }); 677 678 }); 679 680 $("#store-checkout-form-group-shipping").submit(function(e) { 681 e.preventDefault(); 682 var sfName = $("#store-checkout-shipping-first-name").val(); 683 var slName = $("#store-checkout-shipping-last-name").val(); 684 var sCompany = ''; 685 686 if ($("#store-checkout-shipping-company")) { 687 sCompany = $("#store-checkout-shipping-company").val(); 688 } 689 690 var sAddress1 = $("#store-checkout-shipping-address-1").val(); 691 var sAddress2 = $("#store-checkout-shipping-address-2").val(); 692 var sCountry = $("#store-checkout-shipping-country").val(); 693 var sCity = $("#store-checkout-shipping-city").val(); 694 var sState = $("#store-checkout-shipping-state").val(); 695 var sPostal = $("#store-checkout-shipping-zip").val(); 696 $("#store-checkout-form-group-shipping .store-checkout-form-group-body .store-checkout-errors").remove(); 697 698 var ccm_token = $(this).find('[name=ccm_token]').val(); 699 700 if ($('#store-checkout-form-group-shipping #store-checkout-form-group-other-attributes').length) { 701 communityStore.processOtherAttributes(); 702 } 703 704 communityStore.waiting(); 705 var obj = $(this); 706 $.ajax({
707 url: CHECKOUTURL + "/updater" + TRAILINGSLASH, 708 type: 'post', 709 cache: false, 710 dataType: 'text', 711 data: { 712 ccm_token: ccm_token, 713 adrType: 'shipping', 714 fName: sfName, 715 lName: slName, 716 company: sCompany, 717 addr1: sAddress1, 718 addr2: sAddress2, 719 count: sCountry, 720 city: sCity, 721 state: sState, 722 postal: sPostal 723 }, 724 //dataType: 'json', 725 success: function(result) { 726 var response = JSON.parse(result); 727 if (response.error == false) { 728 obj.find('.store-checkout-form-group-summary .store-summary-name').html(response.first_name + ' ' + response.last_name); 729 obj.find('.store-checkout-form-group-summary .store-summary-address').html(response.address); 730 obj.find('.store-checkout-form-group-summary .store-summary-company').html(response.company); 731 if (response.vat_number != '') { 732 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(response.vat_number); 733 } else { 734 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html('-'); 735 } 736 communityStore.showShippingMethods(function() { 737 communityStore.refreshCartTotals(); 738 communityStore.nextPane(obj); 739 }); 740 } else { 741 $("#store-checkout-form-group-shipping .store-checkout-form-group-body").prepend('<div class="store-checkout-errors"><div class="alert alert-danger"></div></div>'); 742 $("#store-checkout-form-group-shipping .alert").html(response.errors.join('<br>')); 743 $('.store-whiteout').remove(); 744 } 745 }, 746 error: function(data) { 747 $(".store-whiteout").remove(); 748 } 749 }); 750 751 }); 752 753 $("#store-checkout-form-group-vat").submit(function(e) { 754 e.preventDefault(); 755 var vat_number = $("#store-checkout-shipping-vat-number").val(); 756 $("#store-checkout-form-group-vat .store-checkout-errors").remove(); 757 var ccm_token = $(this).find('[name=ccm_token]').val(); 758 759 if ($('#store-checkout-form-group-vat #store-checkout-form-group-other-attributes').length) { 760 communityStore.processOtherAttributes(); 761 } 762 763 communityStore.waiting(); 764 var obj = $(this); 765 $.ajax({
766 url: HELPERSURL + "/tax/setvatnumber" + TRAILINGSLASH, 767 type: 'post', 768 cache: false, 769 dataType: 'text', 770 data: { 771 vat_number: vat_number, 772 ccm_token: ccm_token 773 }, 774 success: function(result) { 775 //var test = null; 776 var response = JSON.parse(result); 777 if (response.error == false) { 778 if (response.vat_number != '') { 779 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(response.vat_number); 780 } else { 781 obj.find('.store-checkout-form-group-summary .store-summary-vat-number').html(obj.find('.store-checkout-form-group-summary .store-summary-vat-number').data('vat-blank')); 782 } 783 communityStore.refreshCartTotals(); 784 communityStore.nextPane(obj); 785 $('.store-whiteout').remove(); 786 } else { 787 788 789 $("#store-checkout-form-group-vat .store-checkout-form-group-body ").prepend('<div class="store-checkout-errors"><div class="store-checkout-error alert alert-danger"></div></div>'); 790 $("#store-checkout-form-group-vat .store-checkout-error").html(response.errors.join('<br>')); 791 $('.store-whiteout').remove(); 792 } 793 }, 794 error: function(data) { 795 $(".store-whiteout").remove(); 796 } 797 }); 798 799 }); 800 801 $("#store-checkout-form-group-shipping-method").submit(function(e) { 802 e.preventDefault(); 803 communityStore.waiting(); 804 var obj = $(this); 805 var ccm_token = $(this).find('[name=ccm_token]').val(); 806 807 if ($("#store-checkout-shipping-method-options input[type='radio']:checked").length < 1) { 808 $('.store-whiteout').remove(); 809 alert($('#store-checkout-shipping-method-options').data('error-message')); 810 } else { 811 var smID = $("#store-checkout-shipping-method-options input[type='radio']:checked").val(); 812 var methodText = $.trim($("#store-checkout-shipping-method-options input[type='radio']:checked").parent().find('.store-shipping-details').html()); 813 obj.find('.summary-shipping-method').html(methodText); 814 var sInstructions = $('#store-checkout-shipping-instructions').val(); 815 obj.find('.summary-shipping-instructions').html(sInstructions); 816 817 $.ajax({
818 type: 'post', 819 cache: false, 820 dataType: 'text', 821 data: { 822 smID: smID, 823 sInstructions: sInstructions, 824 ccm_token: ccm_token 825 }, 826 url: HELPERSURL + "/shipping/selectshipping" + TRAILINGSLASH, 827 success: function(total) { 828 communityStore.refreshCartTotals(function() { 829 communityStore.nextPane(obj); 830 $('.store-whiteout').remove(); 831 }); 832 } 833 }); 834 835 } 836 }); 837 838 $(".store-btn-previous-pane").click(function(e) { 839 //hide the body of the current pane, go to the next pane, show that body. 840 var pane = $(this).closest(".store-checkout-form-group").find('.store-checkout-form-group-body').parent().prev(); 841 $('.store-active-form-group').removeClass('store-active-form-group'); 842 pane.addClass('store-active-form-group'); 843 844 $('html, body').animate({ 845 scrollTop: pane.parent().offset().top - CHECKOUTSCROLLOFFSET 846 }); 847 848 $(this).closest(".store-checkout-form-group").prev().removeClass("store-checkout-form-group-complete"); 849 e.preventDefault(); 850 }); 851 852 $("#store-checkout-payment-method-options input[type='radio']").change(function() { 853 communityStore.showPaymentForm(); 854 }); 855 856 $('#store-cart .store-btn-cart-list-remove').click(function(e) { 857 $('#deleteform input[name=instance]').val($(this).data('instance')); 858 $('#deleteform').submit(); 859 e.preventDefault(); 860 }); 861 862 $(document).on('click', '.store-btn-add-to-cart', function(e) { 863 var add = false; 864 865 if ($(this).data('invalid') == '1') { 866 $(this).data('invalid', '0'); 867 } else { 868 869 if (communityStore.hasFormValidation()) { 870 if (!$(this).closest('form')[0].checkValidity()) { 871 872 $(this).data('invalid', '1'); 873 $(this).click(); 874 } else { 875 add = true; 876 } 877 } else { 878 add = true; 879 } 880 881 if (add) { 882 communityStore.addToCart($(this).data('product-id'), $(this).data('add-type')); 883 e.preventDefault(); 884 } 885 } 886 887 }); 888 889 $(document).on('submit', '.store-product-block', function(e) { 890 if ($(this).find('.store-btn-add-to-cart').length > 0) { 891 communityStore.addToCart($(this).data('product-id'), $(this).data('add-type')); 892 } 893 e.preventDefault(); 894 }); 895 896 $(document).on('click', '.store-price-suggestion', function(e) { 897 var productform = $(this).closest('form'); 898 productform.find('.store-product-customer-price-entry-field').val($(this).data('suggestion-value')); 899 communityStore.addToCart(productform.data('product-id'), $(this).data('add-type')); 900 e.preventDefault(); 901 }); 902 903 $(document).on('click', '.store-btn-cart-list-remove', function(e) { 904 communityStore.removeItem($(this).data('instance-id'), $(this).data('modal')); 905 e.preventDefault(); 906 }); 907 908 $('.store-product-quick-view').click(function(e) { 909 communityStore.productModal($(this).data('product-id'), $(this).data('locale')); 910 e.preventDefault(); 911 }); 912 913 $('.store-cart-link-modal').click(function(e) { 914 communityStore.displayCart(false, true); 915 e.preventDefault(); 916 }); 917 918 $(document).on('click', '.store-modal-exit, .store-btn-cart-modal-continue', function(e) { 919 communityStore.exitModal(); 920 e.preventDefault(); 921 }); 922 923 $(document).on('click', '.store-btn-cart-modal-clear', function(e) { 924 communityStore.clearCart(true); 925 $(this).addClass('disabled'); 926 e.preventDefault(); 927 }); 928 929 $(document).on('click', '.store-btn-cart-modal-update', function(e) { 930 var update = false; 931 932 if ($(this).data('invalid') == '1') { 933 $(this).data('invalid', '0'); 934 } else { 935 if (communityStore.hasFormValidation()) { 936 if (!$(this).closest('form')[0].checkValidity()) { 937 $(this).data('invalid', '1'); 938 $(this).click(); 939 } else { 940 update = true; 941 } 942 } else { 943 update = true; 944 } 945 946 if (update) { 947 var instances = $("#store-modal-cart input[name='instance[]']").map(function() { 948 return $(this).val(); 949 }).get(); 950 var pQty = $("#store-modal-cart input[name='pQty[]']").map(function() { 951 return $(this).val(); 952 }).get(); 953 954 communityStore.updateMultiple(instances, pQty, true); 955 $(this).addClass('disabled'); 956 e.preventDefault(); 957 } 958 } 959 960 });
961 962 $('.store-cart-modal-link').click(function(e) { 963 e.preventDefault(); 964 communityStore.displayCart(false, true); 965 }); 966 967 $('.store-btn-filter').click(function(e) { 968 e.preventDefault(); 969 communityStore.submitProductFilter($(this)); 970 }); 971 972 $(document).on('change', '.store-product-filter-block-auto input[type="checkbox"]', function(e) { 973 communityStore.submitProductFilter($(this)); 974 }); 975 976 $(document).on('click', '.store-btn-filter-clear', function(e) { 977 communityStore.clearProductFilter($(this)); 978 }); 979 980});
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.