1let $ = jQuery.noConflict() 2 3function getCookie(name) { 4 let matches = document.cookie.match(new RegExp( 5 "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" 6 )); 7 return matches ? decodeURIComponent(matches[1]) : undefined; 8} 9 10function blockPage() { 11 $('body').block({ 12 message: null, 13 overlayCSS: { 14 backgroundColor: '#fff', 15 opacity: 0.6, 16 cursor: 'wait' 17 } 18 }); 19} 20 21$(document).on("click", ".single-use-code__tiles a", function (e) { 22 let link = $(this).attr('href'); 23 let LPbtn = '', urlParts = link.split('#'); 24 if (typeof urlParts[1] != 'undefined') { 25 e.preventDefault(); 26 if (urlParts[1] == 'login') LPbtn = 'signIn'; 27 if (urlParts[1] == 'register') LPbtn = 'signUp'; 28 if (LPbtn && LPbtn != '') $('.forms-switcher button[data-form="' + LPbtn + '"]').trigger('click'); 29 $(this).parents('.fancybox__container').find('.is-close').trigger('click'); 30 window.location.href = link; 31 } 32}); 33 34$(document).on("click", "#share-btns, .share-btns__close", function (e) { 35 e.preventDefault(); 36 $('.share-btns').parents('.btns').toggleClass('active'); 37}); 38 39$(document).on("change", "select[name='order-tracks']", function (e) { 40 e.preventDefault(); 41 $(this).parents('form').submit(); 42}); 43 44$(document).bind("update_checkout", function () { 45 $(".coupon-code button[name='update_cart']").removeAttr('disabled').trigger('click').prop('disabled', true); 46}); 47 48$(document).on("click", 'button[name="apply_coupon"]', function (e) { 49 e.preventDefault(); 50 blockPage(); 51 52 let block = $(this).parents('.coupon-code'), 53 coupone = block.find('input[name="coupon_code"]').val(), 54 error = ''; 55 56 block.find('.msg').remove(); 57 58 if (coupone == '') error = '<p class="msg">' + block.data('text_empty') + '</p>'; 59 60 if (error != '') { 61 block.find('.flex').after(error); 62 $('body').unblock(); 63 return false; 64 } else { 65 $.ajax({ 66 type: 'POST', 67 url: '/wp-admin/admin-ajax.php', 68 data: { 69 coupone: coupone, 70 action: 'apply_coupon_code' 71 }, 72 success: function (response) { 73 if (response.success === true) { 74 $('body').trigger('update_checkout'); 75 } else { 76 error = '<p class="msg">' + response.data.message + '</p>'; 77 block.find('.flex').after(error); 78 } 79 $('body').unblock(); 80 }, 81 error: function () { 82 console.log('Error'); 83 $('body').unblock(); 84 } 85 }) 86 } 87}); 88 89$(document).on('submit', '.signin-form', function (e) { 90 e.preventDefault() 91 92 blockPage(); 93 94 let form = $(this), 95 data = form.serializeArray(); 96 97 form.find('.form-message').attr('class', 'form-message').show().html(''); 98 99 if (validateForm(form)) { 100 $.ajax({ 101 type: 'POST', 102 url: '/wp-admin/admin-ajax.php', 103 data: data, 104 success: function (response) { 105 if (response.success === true) { 106 if (response.data.message != '') form.find('.form-message').addClass('success').html(response.data.message); 107 if (response.data.redirect != '') { 108 // window.location.replace(response.data.redirect); 109 // window.location.href = response.data.redirect; 110 document.location.href = response.data.redirect; 111 } 112 } else { 113 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 114 } 115 $('body').unblock(); 116 }, 117 error: function () { 118 console.log('Error'); 119 $('body').unblock(); 120 } 121 }) 122 } 123}) 124 125$(document).on('submit', '.resetpwd-form', function (e) { 126 e.preventDefault() 127 128 blockPage(); 129 130 let form = $(this), 131 data = form.serializeArray(); 132 133 form.find('.form-message').attr('class', 'form-message').show().html(''); 134 135 if (validateForm(form)) { 136 $.ajax({ 137 type: 'POST', 138 url: '/wp-admin/admin-ajax.php', 139 data: data, 140 success: function (response) { 141 if (response.success === true) { 142 if (response.data.message != '') form.find('.form-message').addClass('success').html(response.data.message); 143 if (response.data.redirect != '') location.href = response.data.redirect 144 } else { 145 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 146 } 147 $('body').unblock(); 148 }, 149 error: function () { 150 console.log('Error'); 151 $('body').unblock(); 152 } 153 }) 154 } 155}
155) 156 157$(document).on('submit', '.signup-form', function (e) { 158 e.preventDefault() 159 160 blockPage(); 161 162 let form = $(this), 163 data = form.serializeArray() 164 165 form.find('.form-message').attr('class', 'form-message').show().html(''); 166 167 if (validateForm(form)) { 168 $.ajax({ 169 type: 'POST', 170 url: '/wp-admin/admin-ajax.php', 171 data: data, 172 success: function (response) { 173 if (response.success === true) { 174 if ($('#signup-after').length) { 175 $('#redirect-to-prev-page').data('href', response.data.redirect); 176 Fancybox.show([{ 177 'type': 'inline', 178 src: '#signup-after' 179 }]); 180 } else { 181 location.href = response.data.redirect 182 } 183 } else { 184 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 185 } 186 $('body').unblock(); 187 }, 188 error: function () { 189 console.log('Error') 190 $('body').unblock(); 191 } 192 }) 193 } 194}) 195 196$(document).on("click", "#redirect-to-prev-page", function (e) { 197 e.preventDefault(); 198 let href = $(this).data('href'); 199 location.href = href; 200}); 201 202$(document).on('submit', '.signup-form-prepare', function (e) { 203 e.preventDefault() 204 205 blockPage(); 206 207 let form = $(this), 208 data = form.serializeArray() 209 210 form.find('.form-message').attr('class', 'form-message').show().html(''); 211 212 if (validateForm(form)) { 213 $.ajax({ 214 type: 'POST', 215 url: '/wp-admin/admin-ajax.php', 216 data: data, 217 success: function (response) { 218 if (response.success === true) { 219 // Move value from prepare form 220 $.each(data, function (k, v) { 221 if (v.name != 'action') { 222 let field = $('.signup-form').find(`[name="${v.name}"]`); 223 if (field.length) field.val(v.value); 224 } 225 }); 226 227 $('.signup-form-prepare').hide(); 228 $('.signup-form').show(); 229 } else { 230 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 231 } 232 $('body').unblock(); 233 }, 234 error: function () { 235 console.log('Error') 236 $('body').unblock(); 237 } 238 }); 239 } 240}) 241 242/** 243 * Single-use code 244 * 245 * - submit handler 246 * - regenerate code 247 */ 248$(document).on('submit', '.signle-use-code form', function (e) { 249 e.preventDefault() 250 251 blockPage(); 252 253 let form = $(this), 254 data = form.serializeArray(), 255 handler = form.find('[name="handler"]').val(); 256 257 form.find('.form-message').attr('class', 'form-message').show().html(''); 258 259 $.ajax({ 260 type: 'POST', 261 url: '/wp-admin/admin-ajax.php', 262 data: data, 263 success: function (response) { 264 if (response.success === true) { 265 if (handler == 'check') { 266 $('.signle-use-code--step-1').hide(); 267 $('.signle-use-code--step-2').show(); 268 269 $('[name="source-email"]').val(response.data.source_email); 270 $('[name="source-phone"]').val(response.data.source_phone); 271 272 $('.signle-use-code--step-2 .signle-use-code__text').html(response.data.message).show(); 273 } 274 if (handler == 'send-code') { 275 $('.signle-use-code--step-1').hide(); 276 $('.signle-use-code--step-2').hide(); 277 $('.signle-use-code--step-3').show(); 278 279 $('[name="set-email"]').val(response.data.source_email); 280 $('[name="set-phone"]').val(response.data.source_phone); 281 $('[name="set-code"]').val(response.data.code); 282 $('[name="set-userid"]').val(response.data.userid); 283 284 if (response.data.source_email == '') $('#set-email').show(); 285 if (response.data.source_phone == '') $('#set-phone').show(); 286 if (response.data.source_email == '' || response.data.source_phone == '') $('.signle-use-code--step-3 .signle-use-code__text').show(); 287 288 $('.signle-use-code--step-3 > h2').text(response.data.h2); 289 } 290 if (handler == 'set-data') { 291 $('.signle-use-code--step-1').hide(); 292 $('.signle-use-code--step-2').hide(); 293 $('.signle-use-code--step-3').hide(); 294 $('.signle-use-code--step-4').show(); 295 } 296 $('body').unblock(); 297 } else { 298 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 299 } 300 $('body').unblock(); 301 }, 302 error: function () { 303 console.log('Error') 304 $('body').unblock(); 305 } 306 }) 307}); 308$(document).on("click", ".signle-use-code__reset-code a", function (e) { 309 e.preventDefault(); 310 blockPage(); 311 312 let form = $(this).parents('form'), 313 phone = form.find('[name="source-phone"]').val(), 314 email = form.find('[name="source-email"]').val(); 315 316 form.find('[name="code"]').val(''); 317 form.find('.form-message').attr('class', 'form-message').show().html(''); 318 319 $.ajax({ 320 type: 'POST', 321 url: '/wp-admin/admin-ajax.php', 322 data: {
323 action: 'single_use_code_regenerate', 324 phone: phone, 325 email: email 326 }, 327 success: function (response) { 328 if (response.success === true) { 329 330 } else { 331 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 332 } 333 $('body').unblock(); 334 }, 335 error: function () { 336 console.log('Error') 337 $('body').unblock(); 338 } 339 }); 340}); 341 342$(document).on('click', '.signup-switch', function (e) { 343 e.preventDefault() 344 345 let signup_tab = $('[data-form="signUp"]') 346 347 if (!signup_tab.hasClass('active')) { 348 signup_tab.trigger('click') 349 $('html, body').animate({ 350 scrollTop: $('#signUp').offset().top 351 }, 1000) 352 } 353}) 354 355/*$( document ).on( 'click', '.product-remove', function ( e ) { 356 e.preventDefault() 357 358 let button = $( this ), 359 data = { 360 action: 'remove_cart_product', 361 id: button.data( 'id' ) 362 } 363 364 $.ajax( { 365 type: 'POST', 366 url: '/wp-admin/admin-ajax.php', 367 data: data, 368 success: function ( response ) { 369 if ( response.success === true ) { 370 updateCart() 371 } else { 372 console.log( 'Error' ) 373 } 374 }, 375 error: function () { 376 console.log( 'Error' ) 377 } 378 } ) 379} )*/ 380 381$(document).on('submit', '.coupon-form', function (e) { 382 e.preventDefault() 383 384 let form = $(this), 385 coupon = form.find('input'), 386 data = { 387 action: 'add_coupon', 388 coupon: coupon.val() 389 } 390 391 if (coupon.val().length !== 0) { 392 $.ajax({ 393 type: 'POST', 394 url: '/wp-admin/admin-ajax.php', 395 data: data, 396 success: function (response) { 397 if (response.success === true) { 398 updateCart() 399 noticeMessage('Coupon added') 400 } else { 401 errorMessage(response.data) 402 } 403 }, 404 error: function () { 405 console.log('Error') 406 } 407 }) 408 } else { 409 errorMessage('Coupon is empty') 410 } 411}) 412 413$(document).on('click', '.remove-coupon', function (e) { 414 e.preventDefault() 415 416 let data = { 417 action: 'remove_coupon', 418 coupon: $(this).data('code') 419 } 420 421 $.ajax({ 422 type: 'POST', 423 url: '/wp-admin/admin-ajax.php', 424 data: data, 425 success: function (response) { 426 if (response.success === true) { 427 updateCart() 428 noticeMessage('Coupon removed') 429 } else { 430 console.log('Error') 431 } 432 }, 433 error: function () { 434 console.log('Error') 435 } 436 }) 437}); 438 439function updateQTY(key, val) { 440 let data = { 441 action: 'theme_woo_qty_cart_item', 442 qty: val, 443 key: key 444 } 445 446 blockPage(); 447 448 $.ajax({ 449 type: 'POST', 450 url: '/wp-admin/admin-ajax.php', 451 data: data, 452 success: function (response) { 453 updateCart(); 454 if ($('.update_cart').length) $('.update_cart').prop('disabled', false).attr('aria-disabled', false).trigger('click').prop('disabled', true).attr('aria-disabled', true); 455 }, 456 error: function () { 457 console.log('Error') 458 } 459 }) 460} 461 462$(document).on('click', '.product-count .plus', function (e) { 463 e.preventDefault() 464 465 let wrapper = $(this).parents('.product-count'), 466 input = wrapper.find('input'), 467 inputVal = input.val(), 468 inputMax = input.attr('max'), 469 key = input.parents('.product-quantity').data('key'); 470 if (parseInt(inputMax) > parseInt(inputVal) || parseInt(inputMax) === -1) { 471 input.val(++inputVal) 472 // input.trigger('change') 473 if (typeof key != 'undefined') updateQTY(key, input.val()); 474 } 475}) 476 477$(document).on('click', '.product-count .minus', function (e) { 478 e.preventDefault() 479 480 let wrapper = $(this).parents('.product-count'), 481 input = wrapper.find('input'), 482 inputVal = input.val(), 483 inputMin = input.attr('min'), 484 key = input.parents('.product-quantity').data('key'); 485 486 if (parseInt(inputMin) < parseInt(inputVal)) { 487 input.val(--inputVal) 488 // input.trigger('change') 489 if (typeof key != 'undefined') updateQTY(key, input.val()); 490 } 491}) 492 493/*$( document ).on( 'change', '.product-quantity', function ( e ) { 494 e.preventDefault() 495 496 let input = $( this ), 497 min = parseInt( input.attr( 'min' ) ), 498 max = parseInt( input.attr( 'max' ) ), 499 val = parseInt( input.val() ) 500 501 if ( val < min ) { 502 input.val( min ) 503 val = min 504 } 505 506 if ( val > max && max !== -1 ) { 507 input.val( max ) 508 val = max 509 } 510 511 let data = { 512 action: 'change_cart_product_quantity', 513 quantity: val, 514 product_id: input.data( 'id' ) 515 } 516 517 $.ajax( { 518 type: 'POST', 519 url: '/wp-admin/admin-ajax.php', 520 data: data, 521 success: function ( response ) { 522 if ( response.success === true ) { 523 updateCart() 524 } else { 525 console.log( 'Error' ) 526 } 527 }, 528 error: function () { 529 console.log( 'Error' ) 530 } 531 } ) 532} )*/ 533 534$(document).on('submit', 'form.cart', function (e) { 535 e.preventDefault() 536 537 let form = $(this), 538 action = form.attr('action'), 539 data = new FormData(form[0]) 540 541 $.ajax({ 542 type: 'POST', 543 url: action, 544 data: data, 545 cache: false, 546 contentType: false, 547 processData: false, 548 success: function (response) { 549 updateCart() 550 }, 551 error: function () { 552 console.log('Error') 553 } 554 }) 555}) 556
557$(document).on('change', '.woocommerce-cart-form .qty', function (e) { 558 updateCart() 559}) 560 561$(document).on('change', '.woocommerce-mini-cart-form .qty', function (e) { 562 updateMiniCart($(this)); 563}) 564 565$(document).on('click', '.add-to-cart', function (e) { 566 e.preventDefault() 567 568 let link = $(this), 569 data = { 570 action: 'add_to_cart', 571 id: link.data('id') 572 } 573 574 $.ajax({ 575 type: 'POST', 576 url: '/wp-admin/admin-ajax.php', 577 data: data, 578 success: function (response) { 579 if (response.success === true) { 580 updateCart() 581 } else { 582 console.log('Error') 583 } 584 }, 585 error: function () { 586 console.log('Error') 587 } 588 }) 589}) 590 591$(document).on('click', '.add-to-wishlist', function (e) { 592 e.preventDefault() 593 594 console.log('add-to-wishlist') 595}) 596 597$(document).on('click', '.close-modal', function (e) { 598 e.preventDefault() 599 600 $('html,body').removeClass('fixed') 601 $('.modals-wrapper, .overlay').fadeOut() 602 let parent = $(this).parents('.modal-block') 603 if (parent.hasClass('isActive')) { 604 parent.removeClass('isActive') 605 } else { 606 parent.fadeOut() 607 } 608}) 609 610$(document).on('submit', '.checkout', function (e) { 611 e.preventDefault() 612 613 /*let form = $( this ), 614 data = form.serializeArray() 615 616 if ( form ) { 617 $.ajax( { 618 type: 'POST', 619 url: '/wp-admin/admin-ajax.php', 620 data: data, 621 success: function ( response ) { 622 if ( response.success === true ) { 623 console.log( response.data ) 624 } else { 625 console.log( 'Error' ) 626 } 627 }, 628 error: function () { 629 console.log( 'Error' ) 630 } 631 } ) 632 }*/ 633}) 634 635$(document).on('submit', '.customer-information-form', function (e) { 636 e.preventDefault() 637 638 blockPage(); 639 640 let form = $(this), 641 data = form.serializeArray() 642 643 form.find('.form-message').attr('class', 'form-message').show().html(''); 644 645 $.ajax({ 646 type: 'POST', 647 url: '/wp-admin/admin-ajax.php', 648 data: data, 649 success: function (response) { 650 if (response.success === true) { 651 if (response.data.message != '') form.find('.form-message').addClass('success').html(response.data.message); 652 } else { 653 if (response.data.message != '') form.find('.form-message').addClass('error').html(response.data.message); 654 } 655 $('body').unblock(); 656 }, 657 error: function () { 658 console.log('Error') 659 } 660 }); 661 return false; 662 663 if (validateCustomerInformationForm(form)) { 664 665 } 666}) 667 668$(document).on('click', '.add-to-wishlist', function (e) { 669 e.preventDefault() 670 671 $('.icon-user__wrapper').toggleClass('added'); 672 673 let btn = $(this), 674 data = { 675 action: 'add_to_wishlist', 676 id: $(this).data('id') 677 } 678 btn.addClass('loading'); 679 $.ajax({ 680 type: 'POST', 681 url: '/wp-admin/admin-ajax.php', 682 data: data, 683 success: function (response) { 684 if (response.success === true) { 685 if ($('.wishlist-tabs').length) { 686 btn.parents('.wishlist-item').fadeOut(function () { 687 $(this).remove(); 688 }); 689 } 690 btn.toggleClass('active') 691 if (btn.hasClass('active')) { 692 $('.icon-user__wrapper').toggleClass('added'); 693 } 694 } else { 695 console.log('Error') 696 } 697 btn.removeClass('loading'); 698 localStorage.setItem('wishlist', response.data.wishlist); 699 }, 700 error: function () { 701 console.log('Error') 702 } 703 }) 704}) 705 706$(document).on('submit', '.add-note-to-wishlist-item-form', function (e) { 707 e.preventDefault() 708 709 let data = $(this).serializeArray() 710 711 $.ajax({ 712 type: 'POST', 713 url: '/wp-admin/admin-ajax.php', 714 data: data, 715 success: function (response) { 716 if (response.success === true) { 717 noticeMessage('Note Update') 718 } else { 719 console.log('Error') 720 } 721 }, 722 error: function () { 723 console.log('Error') 724 } 725 }) 726}) 727 728$(document).on('submit', '.add-to-cart-subscription', function (e) { 729 e.preventDefault() 730 731 let form = $(this), 732 select = form.find('select'), 733 data = form.serializeArray() 734 735 if (select.val().length !== 0) { 736 $.ajax({ 737 type: 'POST', 738 url: '/wp-admin/admin-ajax.php', 739 data: data, 740 success: function (response) { 741 if (response.success === true) { 742 location.href = response.data 743 } else { 744 console.log('Error') 745 } 746 }, 747 error: function () { 748 console.log('Error') 749 } 750 }) 751 } else { 752 // errorMessage('Choose Option') 753 select.addClass('error-select'); 754 setTimeout(function () { 755 select.removeClass('error-select'); 756 }, 2000); 757 } 758}) 759// upd 760$(document).on('submit', '.add-to-cart-flexible-subscriptions', function (e) { 761 e.preventDefault() 762 763 let form = $(this), 764 select_region = form.find('#variation_region'), 765 select_type = form.find('#variation_type'), 766 data = form.serializeArray(), 767 show_popup = false;
768 769 if (select_region.val().length === 0 || select_type.val().length === 0) { 770 // errorMessage('Choose Option') 771 /* 772 select_region.next().addClass('error-select'); 773 select_type.next().addClass('error-select'); 774 setTimeout(function () { 775 select_region.next().removeClass('error-select'); 776 select_type.next().removeClass('error-select'); 777 }, 2000); 778 return false; 779 */ 780 data.push({ name: 'show_popup', value: 'true' }); 781 } 782 783 $.ajax({ 784 type: 'POST', 785 url: '/wp-admin/admin-ajax.php', 786 data: data, 787 success: function (response) { 788 if (response.success === true) { 789 location.href = response.data 790 } else { 791 if ($('#popup-subs-page').length) { 792 $('#popup-subs-page .flexsubs-error p, #popup-subs-page .flexsubs-error h4').remove(); 793 $('#popup-subs-page .flexsubs-error').append(response.data); 794 Fancybox.show([{ 795 'type': 'inline', 796 src: '#popup-subs-page' 797 }]); 798 } else { 799 errorMessage(response.data); 800 } 801 } 802 }, 803 error: function () { 804 console.log('Error') 805 } 806 }) 807}) 808 809$(document).on('change', '.variation_change', function (e) { 810 e.preventDefault() 811 812 let input = $(this), 813 wrapper = input.parents('.variation_switcher_wrapper'), 814 data = { 815 action: 'change_cart_subscribtion_variation', 816 current_variation: wrapper.data('current_id'), 817 new_variation: input.val() 818 } 819 820 $.ajax({ 821 type: 'POST', 822 url: '/wp-admin/admin-ajax.php', 823 data: data, 824 success: function (response) { 825 if (response.success === true) { 826 updateCart() 827 } else { 828 console.log('Error') 829 } 830 }, 831 error: function () { 832 console.log('Error') 833 } 834 }) 835}) 836 837$(document).on('click', '.woocommerce-mini-cart-form .product-remove a', function (e) { 838 e.preventDefault() 839 840 $.ajax({ 841 type: 'POST', 842 url: $(this).attr('href'), 843 success: function (response) { 844 updateCart() 845 }, 846 error: function () { 847 console.log('Error') 848 } 849 }) 850}) 851 852function updateCountCart() { 853 $.ajax({ 854 type: 'POST', 855 url: '/wp-admin/admin-ajax.php', 856 data: { 857 action: 'update_count_cart' 858 }, 859 success: function (response) { 860 $('.cart-count').html(response.data); 861 if (response.data == 0) $('.cart-count').hide(); 862 else $('.cart-count').show(); 863 }, 864 error: function () { 865 console.log('Error') 866 } 867 }) 868} 869 870function updateCart() { 871 blockPage(); 872 updateCountCart(); 873 $.ajax({ 874 type: 'POST', 875 url: '/wp-admin/admin-ajax.php', 876 data: { 877 action: 'update_mini_cart' 878 }, 879 success: function (response) { 880 $('.mini-cart-wrapper').html(response.data); 881 $('body').unblock(); 882 }, 883 error: function () { 884 console.log('Error') 885 } 886 }) 887 888 if ($('.woocommerce-cart-form').length !== 0) { 889 $('.woocommerce-cart-form .update_cart').removeAttr('disabled') 890 $('.woocommerce-cart-form .update_cart').trigger('click') 891 } 892 893 $(document.body).trigger('wc_fragment_refresh') 894 895 896 if ($('.woocommerce-cart-form').length === 0) { 897 setTimeout(function () { 898 $('[data-modal=".mini-cart-wrapper"]').trigger('click') 899 }, 600) 900 } 901 902 if ($('.checkout-page').length !== 0) { 903 $(document.body).trigger('update_checkout') 904 } 905} 906 907function updateMiniCart(input) { 908 if ($('.woocommerce-cart-form').length !== 0) { 909 $('.woocommerce-cart-form [name="' + input.attr('name') + '"]').val(input.val()) 910 } 911 912 let cartForm = $('.woocommerce-mini-cart-form'), 913 formData = cartForm.serialize(); 914 915 blockPage(); 916 917 $.ajax({ 918 type: cartForm.attr('method'), 919 url: cartForm.attr('action'), 920 data: formData, 921 dataType: 'html', 922 success: function (response) { 923 $('body').unblock(); 924 updateCart(); 925 } 926 }) 927} 928 929function validateForm(form) { 930 let validation = true 931 932 form.find('.item-required').each(function (index) { 933 //$( this ).find( '.error-message' ).removeClass( 'active' ) 934 $(this).removeClass('validation-error') 935 if ($(this).find('input').val().length === 0) { 936 validation = false 937 $(this).addClass('validation-error') 938 //$( this ).find( '.error-message' ).addClass( 'active' ) 939 } 940 }) 941 942 return validation 943} 944 945function validateCustomerInformationForm(form) { 946 let validation = true 947 form.find('.validation-required').removeClass('validation-error') 948 949 $('.validation-required').each(function (index) { 950 if ($(this).hasClass('validation-text')) { 951 if ($(this).find('input').val() === '') { 952 validation = false 953 $(this).addClass('validation-error') 954 } 955 } 956 957 if ($(this).hasClass('validation-password')) { 958 let new_item = $(this), 959 new_input = new_item.find('input'), 960 new_password = new_input.val(), 961 confirm_input = $('#confirmPassword'), 962 confirm_item = confirm_input.parent('.validation-password'), 963 confirm_password = confirm_input.val() 964 965 if (new_password.length !== 0) { 966 if (new_password.length < 6) { 967 validation = false 968 errorMessage('Short Password') 969 new_item.addClass('validation-error') 970 confirm_item.addClass('validation-error') 971 } 972 973 if (new_password !== confirm_password) { 974 validation = false 975 errorMessage('Different Passwords') 976 new_item.addClass('validation-error') 977 confirm_item.addClass('validation-error') 978 } 979 } 980 } 981 }) 982 983 return validation 984} 985 986function noticeMessage(message, title = 'Notice', style = 'notice') { 987 let options = { 988 title: title, 989 message: message, 990 style: style 991 } 992 993 $.growl(options) 994} 995 996function errorMessage(message, title = 'Error', style = 'error') { 997 let options = { 998 title: title, 999 message: message, 1000 style: style 1001 } 1002 1003 $.growl(options) 1004} 1005 1006function setCountFilter() { 1007 $('.wpc-filters-section').each(function () {
1008 let count = $(this).find('input:checked').length; 1009 if (count > 0) $(this).find('.wpc-filter-title span').text(count); 1010 }); 1011} 1012 1013$(document).on("change", ".wpc-filters-widget-wrapper input", function (e) { 1014 e.preventDefault(); 1015 1016}); 1017 1018if ($('#signUpBirthday').length > 0) { 1019 var signUpBirthday = new Lightpick({ 1020 field: document.getElementById('signUpBirthday'), 1021 // lang: 'he', 1022 }); 1023} 1024 1025$(document).on("click", ".show-pass", function (e) { 1026 e.preventDefault(); 1027 $(this).toggleClass('show'); 1028 if ($(this).hasClass('show')) { 1029 $(this).parents('.form-item').find('input').attr('type', 'text'); 1030 } else { 1031 $(this).parents('.form-item').find('input').attr('type', 'password'); 1032 } 1033}); 1034/* 1035$(document).on("click touchend", ".recommended-trips a", function (e) { 1036 e.preventDefault(); 1037 let href = $(this).attr('href'); 1038 window.location.href = href; 1039}); 1040*/ 1041 1042$(document).on("click", "a.need-pdf", function (e) { 1043 if ($(this).attr('href') == '#') { 1044 e.preventDefault(); 1045 $(this).addClass('need-notice'); 1046 alert('Please wait a bit and we will notify you when the PDF is ready'); 1047 } 1048}); 1049 1050// <!-- Check user checkout 1051function checkingUserCheckout() { 1052 if (!$('#billing_email').length || $('#billing_email').val() == '') return false; 1053 1054 $.ajax({ 1055 type: 'POST', 1056 url: '/wp-admin/admin-ajax.php', 1057 data: { 1058 'billing_email': $('#billing_email').val(), 1059 'action': 'checkout_checking_user' 1060 }, 1061 success: function (response) { 1062 if (response.success === true) { 1063 console.log('Isset user'); 1064 } else { 1065 console.log('No user'); 1066 } 1067 if (response.data.form != '') { 1068 $('#checkout-login-form').html(response.data.form); 1069 $('#checkout-login-form').show(); 1070 } 1071 }, 1072 error: function () { 1073 console.log('Error'); 1074 } 1075 }) 1076} 1077// Check email 1078$(document).on("change keyup", "input[name=billing_email]", function (e) { 1079 e.preventDefault(); 1080 checkingUserCheckout(); 1081}); 1082// Login process 1083$(document).on("click", "#checkout-login-form button", function (e) { 1084 e.preventDefault(); 1085 blockPage(); 1086 $('#checkout-login-form-response').attr('class', '').html(''); 1087 let form = $(this).parents('#checkout-login-form'), password = form.find('#checkout_password').val(); 1088 $.ajax({ 1089 type: 'POST', 1090 url: '/wp-admin/admin-ajax.php', 1091 data: { 1092 'login': $('#billing_email').val(), 1093 'password': password, 1094 'action': 'checkout_login_user' 1095 }, 1096 success: function (response) { 1097 if (response.success === true) { 1098 $('#checkout-login-form-response').addClass('success').html(response.data.message); 1099 form.find('.form-item').fadeOut(function () { 1100 form.find('.form-item').remove(); 1101 }); 1102 location.reload(true); 1103 } else { 1104 $('#checkout-login-form-response').addClass('error').html(response.data.message); 1105 } 1106 1107 $('body').unblock(); 1108 }, 1109 error: function () { 1110 console.log('Error'); 1111 $('body').unblock(); 1112 } 1113 }) 1114}); 1115// Check user checkout --> 1116 1117// <!-- Scroll subscribtion page 1118function subscriptionScroll(duration = 1500) { 1119 if ($('.subscriptions-items-section').length) { 1120 if ($(window).width() > 768) { 1121 if (window.location.hash.substring(1) == 'subscriptions' || window.location.hash.substring(1) == 'subscriptions_flexible') $('body,html').animate({ scrollTop: $('.subscriptions-items-section').offset().top }, duration); 1122 } else { 1123 if (window.location.hash.substring(1) == 'subscriptions') $('body,html').animate({ scrollTop: $('.subscription-choose-item').eq(0).offset().top - $('.header').height() }, duration); 1124 if (window.location.hash.substring(1) == 'subscriptions_flexible') $('body,html').animate({ scrollTop: $('#subscriptions_flexible').offset().top - $('.header').height() }, duration); 1125 } 1126 } 1127} 1128// Scroll subscribtion page --> 1129subscriptionScroll(); 1130 1131// Popup before navigation 1132$(document).on("click", ".maps-links a", function (e) { 1133 let popupId = '#popup-note-before-map'; 1134 if ($(popupId).length) { 1135 e.preventDefault(); 1136 let href = $(this).attr('href'); 1137 $(popupId).find('a.btn').attr('href', href); 1138 Fancybox.show([{ 1139 'type': 'inline', 1140 src: popupId 1141 }]); 1142 } 1143}); 1144 1145$(document).ready(function () { 1146 checkingUserCheckout(); 1147 subscriptionScroll(1000); 1148 updateCountCart(); 1149 1150 // Gen pdf file
1151 if ($('.need-pdf').length) { 1152 let trackId = $('.need-pdf').data('id'), href = $('.need-pdf').attr('href'), thisLink = $('.need-pdf'); 1153 $.ajax({ 1154 type: 'POST', 1155 url: '/wp-admin/admin-ajax.php', 1156 data: { 1157 action: 'generate_pdf', 1158 post_id: trackId 1159 }, 1160 success: function (response) { 1161 if ($('.need-pdf').hasClass('need-notice')) { 1162 alert('PDF file is ready'); 1163 $('.need-pdf').removeClass('need-notice'); 1164 } 1165 if (!$('.rstrcd').length) 1166 $('.need-pdf').attr('href', '/wp-content/themes/maslulim/inc/get_pdf/' + trackId); 1167 $('.need-pdf').removeClass('need-pdf'); 1168 }, 1169 error: function () { 1170 console.log('Error') 1171 } 1172 }) 1173 } 1174 1175 // Firewall popup free views 1176 if ($('body').hasClass('single-tracks') && window.wp_data.is_subs != true) { 1177 $.ajax({ 1178 type: 'POST', 1179 url: '/wp-admin/admin-ajax.php', 1180 data: { 1181 action: 'check_firewall' 1182 }, 1183 success: function (response) { 1184 if (response.success && response.data.show) { 1185 Fancybox.show([{ 1186 'type': 'inline', 1187 src: '#popup-restricted' 1188 }]); 1189 } 1190 }, 1191 error: function () { 1192 console.log('Error') 1193 } 1194 }) 1195 } 1196 1197 if ($('body').hasClass('page-template-page-checkout') && !$('#tranzilla_iframe').length) { 1198 setTimeout(function () { 1199 $.get('/checkout/', function (data) { 1200 // .order-main 1201 let shippingMethods = $(data).find('.woocommerce-shipping-totals.shipping.additonal-part').html(); 1202 $('.woocommerce-shipping-totals.shipping.additonal-part').html(shippingMethods); 1203 if ($('#shipping_method .checkbox-item:first-child input').length) $('#shipping_method .checkbox-item:first-child input').trigger('click'); 1204 }); 1205 }, 700); 1206 } 1207 1208 // Show password 1209 $('.form-item input[type="password"]').each(function () { 1210 $(this).parents('.form-item').append('<a class="show-pass"></a>'); 1211 }); 1212 1213 $.validator.addMethod( 1214 "hebrewPhone", 1215 function (value, element) { 1216 var reg = /^0?[5|7]{1}([0|2|3|4|5|7|8]{1})?[0-9]{7}$/; 1217 return reg.test(value); 1218 }, 1219 "× × ×××× ×ספר" 1220 ); 1221 $.validator.addMethod( 1222 "selectRequired", 1223 function (value, element, arg) { 1224 return value === '××ר' ? false : true; 1225 }, 1226 "×ש×× ××× ××× × ×©×× ××××" 1227 ); 1228 $.validator.addMethod( 1229 "acceptRequired", 1230 function (value, element) { 1231 return !value ? false : true; 1232 }, 1233 "×ש×× ××× ××× × ×©×× ××××" 1234 ); 1235 $("#signUp form").validate({ 1236 rules: { 1237 tel: { 1238 hebrewPhone: true 1239 }, 1240 sex: { 1241 selectRequired: true 1242 }, 1243 accept_policy: { 1244 acceptRequired: true 1245 } 1246 }, 1247 messages: { 1248 tel: { 1249 hebrewPhone: "× × ×××× ×ספר" 1250 }, 1251 sex: { 1252 selectRequired: "×ש×× ××× ××× × ×©×× ××××" 1253 }, 1254 accept_policy: { 1255 acceptRequired: "××× ×××ש×× ×¢×××× ××שר ×ת ×ª×§× ×× ××תר" 1256 } 1257 }, 1258 errorElement: "div", 1259 errorPlacement: function (error, element) { 1260 var item = element.parents('.form-item'); 1261 item.append(error); 1262 } 1263 }); 1264 1265 $("#signIn form").validate({ 1266 errorElement: "div", 1267 errorPlacement: function (error, element) { 1268 var item = element.parents('.form-item'); 1269 item.append(error); 1270 } 1271 }); 1272 1273 /** 1274 * Single-use code 1275 * 1276 * - add method for validate at least one of the fields 1277 * - validate step 1 (main) 1278 * - validate step 2 (send code) 1279 * - validate step 3 (save data) 1280 */ 1281 $.validator.addMethod("require_use_code", function (value, element, options) { 1282 var numberRequired = options[0]; 1283 var selector = options[1]; 1284 var fields = $(selector, element.form); 1285 var filled_fields = fields.filter(function () { 1286 // it's more clear to compare with empty string 1287 return $(this).val() != ""; 1288 }); 1289 var empty_fields = fields.not(filled_fields); 1290 // we will mark only first empty field as invalid 1291 if (filled_fields.length < numberRequired && empty_fields[0] == element) { 1292 return false; 1293 } 1294 return true; 1295 }, $.validator.format("Please enter either phone/email address")); 1296 1297 // validate step 1 (main) 1298 $("#single-use-code-check").validate({ 1299 groups: { 1300 names: "phone email" 1301 }, 1302 rules: { 1303 phone: { 1304 require_use_code: [1, ".form-elem"] 1305 }, 1306 email: {
1307 require_use_code: [1, ".form-elem"] 1308 } 1309 }, 1310 errorElement: "div", 1311 errorPlacement: function (error, element) { 1312 var item = element.parents('.form-item'); 1313 item.append(error); 1314 } 1315 }); 1316 1317 // validate step 2 (send code) 1318 $("#single-use-code-send").validate({ 1319 errorElement: "div", 1320 errorPlacement: function (error, element) { 1321 var item = element.parents('.form-item'); 1322 item.append(error); 1323 } 1324 }); 1325 1326 // validate step 3 (save data) 1327 $("#single-use-code-set").validate({ 1328 rules: { 1329 phone: { 1330 hebrewPhone: true 1331 }, 1332 accept_policy: { 1333 acceptRequired: true 1334 } 1335 }, 1336 messages: { 1337 phone: { 1338 hebrewPhone: "× × ×××× ×ספר" 1339 }, 1340 accept_policy: { 1341 acceptRequired: "××× ×××ש×× ×¢×××× ××שר ×ת ×ª×§× ×× ××תר" 1342 } 1343 }, 1344 errorElement: "div", 1345 errorPlacement: function (error, element) { 1346 var item = element.parents('.form-item'); 1347 item.append(error); 1348 } 1349 }); 1350 1351 $('.wpc-filters-section').each(function () { 1352 // $(this).find('.wpc-filter-title').append('(<span>0</span>)'); 1353 // Hide empty filter group 1354 if ($(this).find('ul li').length == 1 && ($(this).find('ul li').text() == 'N/A' || $(this).find('ul li').text() == 'There are no filter terms yet')) { 1355 $(this).hide(); 1356 return; 1357 } 1358 $(this).find('.wpc-filter-header').trigger('click'); 1359 }); 1360 1361 setCountFilter(); 1362 1363 // Scroll to list if set filter item 1364 if ($('.wpc-custom-selected-terms li').length && $('.product-grid-section').length) { 1365 if ($('.recommended-trips-section').length) $('.recommended-trips-section').hide(); 1366 let scrollValue = ($('.category-page-intro').offset().top + $('.category-page-intro').height()); 1367 if (window.matchMedia("(max-width: 768px)").matches) scrollValue -= $('header.header').height(); 1368 $('body,html').animate({ scrollTop: scrollValue }, 400); 1369 } 1370 1371 // Set active tab login/reg page 1372 if ($('.page-template-page-login').length > 0 && window.location.hash) { 1373 let LPbtn = ''; 1374 if (window.location.hash == '#login') LPbtn = 'signIn'; 1375 if (window.location.hash == '#register') LPbtn = 'signUp'; 1376 if (LPbtn && LPbtn != '') { 1377 $('.forms-switcher button[data-form="' + LPbtn + '"]').trigger('click'); 1378 $('[name="redirect_to"]').val(getCookie('prev_url')); 1379 } 1380 } 1381 if ($('.page-template-page-login').length > 0 && window.location.href) { 1382 let LPbtn = '', urlParts = window.location.href.split('#'); 1383 if (typeof urlParts[1] !== 'undefined') { 1384 if (urlParts[1] == 'login') LPbtn = 'signIn'; 1385 if (urlParts[1] == 'register') LPbtn = 'signUp'; 1386 if (LPbtn && LPbtn != '') { 1387 $('.forms-switcher button[data-form="' + LPbtn + '"]').trigger('click'); 1388 $('[name="redirect_to"]').val(getCookie('prev_url')); 1389 } 1390 } 1391 } 1392 1393 document.cookie = "prev_url=" + window.location.href + "; path=/;"; 1394 1395 // Filter: replace product category as link 1396 if ($('#cat-for-filter').length && $('.wpc-filter-product_cat').length) { 1397 let catLinkList = $('#cat-for-filter ul').html(); 1398 $('.wpc-filter-product_cat ul').html(catLinkList); 1399 1400 $(document).on("click", ".wpc-filter-product_cat li", function (e) { 1401 e.preventDefault(); 1402 let link = $(this).find('a').attr('href').replace(/\/shop\//g, 'product-category'); 1403 $(this).parents('ul').find('li input').prop('checked', false); 1404 $(this).find('input').prop('checked', true); 1405 window.location.href = link; 1406 }); 1407 } 1408 1409 // Filter: hide empty groups 1410 if ($('.wpc-filters-section').length) { 1411 $('.wpc-filters-section').each(function () { 1412 if ($(this).find('ul li .wpc-help-tip').length == 1) { 1413 $(this).hide(); 1414 return; 1415 } 1416 }); 1417 } 1418});
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.