1jQuery(document).ready(function($){ 2 3 var isCartPage = xoo_wsc_params.isCart == '1', 4 isCheckoutPage = xoo_wsc_params.isCheckout == '1'; 5 6 var get_wcurl = function( endpoint ) { 7 return xoo_wsc_params.wc_ajax_url.toString().replace( 8 '%%endpoint%%', 9 endpoint 10 ); 11 }; 12 13 14 class Notice{ 15 16 constructor( $modal ){ 17 this.$modal = $modal; 18 this.timeout = null; 19 } 20 21 add( notice, type = 'success', clearPrevious = true ){ 22 23 var $noticeCont = this.$modal.find('.xoo-wsc-notice-container'); 24 25 if( clearPrevious ){ 26 $noticeCont.html(''); 27 } 28 29 var noticeHTML = type === 'success' ? xoo_wsc_params.html.successNotice.toString().replace( '%s%', notice ) : xoo_wsc_params.html.errorNotice.toString().replace( '%s%', notice ); 30 31 $noticeCont.html( noticeHTML ); 32 33 } 34 35 showNotification(){ 36 37 var $noticeCont = this.$modal.find('.xoo-wsc-notice-container'); 38 39 if( !$noticeCont.length || $noticeCont.children().length === 0 ) return; 40 41 $noticeCont.slideDown(); 42 43 clearTimeout(this.timeout); 44 45 this.timeout = setTimeout(function(){ 46 $noticeCont.slideUp('slow',function(){ 47 //$noticeCont.html(''); 48 }); 49 },xoo_wsc_params.notificationTime ) 50 51 } 52 53 hideNotification(){ 54 this.$modal.find('.xoo-wsc-notice-container').hide(); 55 } 56 } 57 58 59 class Container{ 60 61 constructor( $modal, container ){ 62 this.$modal = $modal; 63 this.container = container || 'cart'; 64 this.notice = new Notice( this.$modal ); 65 } 66 67 eventHandlers(){ 68 $(document.body).on( 'wc_fragments_refreshed updated_checkout', this.onCartUpdate.bind(this) ); 69 } 70 71 onCartUpdate(){ 72 this.unblock(); 73 this.notice.showNotification(); 74 } 75 76 setAjaxData( data, noticeSection ){ 77 78 var ajaxData = { 79 container: this.container, 80 noticeSection: noticeSection || this.noticeSection || this.container, 81 isCheckout: isCheckoutPage, 82 isCart: isCartPage 83 } 84 85 86 if( typeof data === 'object' ){ 87 88 $.extend( ajaxData, data ); 89 90 } 91 else{ 92 93 var serializedData = data; 94 95 $.each( ajaxData, function( key, value ){ 96 serializedData += ( '&'+key+'='+value ); 97 } ) 98 99 ajaxData = serializedData; 100 101 } 102 103 return ajaxData; 104 } 105 106 107 toggle( type ){ 108 109 var $activeEls = this.$modal.add( 'body' ).add('html'), 110 activeClass = 'xoo-wsc-'+ this.container +'-active'; 111 112 if( type === 'show' ){ 113 $activeEls.addClass(activeClass); 114 } 115 else if( type === 'hide' ){ 116 $activeEls.removeClass(activeClass); 117 this.notice.hideNotification(); 118 } 119 else{ 120 $activeEls.toggleClass(activeClass); 121 } 122 123 $(document.body).trigger( 'xoo_wsc_' + this.container + '_toggled', [ type ] ); 124 125 } 126 127 128 block(){ 129 this.$modal.addClass('xoo-wsc-loading'); 130 } 131 132 unblock(){ 133 this.$modal.removeClass('xoo-wsc-loading'); 134 } 135 136 137 refreshMyFragments(){ 138 139 if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){ 140 $( document.body ).trigger( 'wc_fragment_refresh' ); 141 return; 142 } 143 144 this.block(); 145 146 $.ajax({ 147 url: get_wcurl( 'xoo_wsc_refresh_fragments' ), 148 type: 'POST', 149 context: this, 150 data: {}, 151 success: function( response ){ 152 this.updateFragments(response); 153 }, 154 complete: function(){ 155 this.unblock(); 156 } 157 }) 158 159 } 160 161 162 updateCartCheckoutPage(){ 163 164 //Refresh checkout page 165 if( isCheckoutPage ){ 166 if( $( 'form.checkout' ).length === 0 ){ 167 location.reload(); 168 return; 169 } 170 $(document.body).trigger("update_checkout"); 171 } 172 173 //Refresh Cart page 174 if( isCartPage ){ 175 $(document.body).trigger("wc_update_cart"); 176 } 177 178 } 179 180 updateFragments( response ){ 181 182 if( response.fragments ){ 183 184 $( document.body ).trigger( 'xoo_wsc_before_loading_fragments', [ response ] ); 185 186 this.block(); 187 188 //Set fragments 189 $.each( response.fragments, function( key, value ) { 190 $( key ).replaceWith( value ); 191 }); 192 193 if( typeof wc_cart_fragments_params !== 'undefined' && ( 'sessionStorage' in window && window.sessionStorage !== null ) ){ 194 195 sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( response.fragments ) ); 196 localStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash ); 197 sessionStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash ); 198 199 if ( response.cart_hash ) { 200 sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() ); 201 } 202 203 } 204 205 $( document.body ).trigger( 'wc_fragments_refreshed' ); 206 207 this.unblock(); 208 209 } 210 211 if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){ 212 this.block(); 213 $( document.body ).trigger( 'wc_fragment_refresh' ); 214 return; 215 } 216 217 } 218 219 } 220 221 222 class Cart extends Container{ 223 224 constructor( $modal ){ 225 226 super( $modal, 'cart' ); 227 228 this.baseQty = 1; 229 this.qtyUpdateDelay = null; 230 231 this.refreshFragmentsOnPageLoad(); 232 this.eventHandlers(); 233 this.initSlider(); 234 235 } 236 237 238 refreshFragmentsOnPageLoad(){ 239 setTimeout(function(){ 240 this.refreshMyFragments(); 241 }.bind(this), xoo_wsc_params.fetchDelay ) 242 } 243 244 eventHandlers(){ 245 246 super.eventHandlers(); 247 248 this.$modal.on( 'click', '.xoo-wsc-chng', this.toggleQty.bind(this) ); 249 this.$modal.on( 'change', '.xoo-wsc-qty', this.changeInputQty.bind(this) ); 250 this.$modal.on( 'click', '.xoo-wsc-undo-item', this.undoItem.bind(this) ); 251 this.$modal.on( 'focusin', '.xoo-wsc-qty', this.saveQtyFocus.bind(this) ); 252 this.$modal.on( 'click', '.xoo-wsc-smr-del', this.deleteIconClick.bind(this) ); 253 this.$modal.on( 'click', '.xoo-wsch-close, .xoo-wsc-opac, .xoo-wsc-cart-close', this.closeCartOnClick.bind(this) ); 254 this.$modal.on( 'click', '.xoo-wsc-basket', this.toggle.bind(this) ); 255 256 $( document.body ).on( 'click', '.xoo-wsc-ecl', this.emptyCart.bind(this) ); 257 258 $(document.body).on( 'xoo_wsc_cart_updated', this.updateCartCheckoutPage.bind(this) ); 259 $(document.body).on( 'click', 'a.added_to_cart, .xoo-wsc-cart-trigger', this.openCart.bind(this) ); 260 $(document.body).on( 'added_to_cart', this.addedToCart.bind(this) ); 261 262 if( xoo_wsc_params.autoOpenCart === 'yes' && xoo_wsc_params.addedToCart === 'yes'){ 263 this.openCart(); 264 } 265 266 if( xoo_wsc_params.ajaxAddToCart === 'yes' ){ 267 $(document.body).on( 'submit', 'form.cart', this.addToCartFormSubmit.bind(this) ); 268 } 269 270 if( typeof wc_cart_fragments_params === 'undefined' ){ 271 $( window ).on( 'pageshow' , this.onPageShow ); 272 } 273 274 275 if( isCheckoutPage || isCartPage ){ 276 $(document.body).on( 'updated_shipping_method', this.refreshMyFragments.bind(this) ); 277 } 278 279 //Animate shipping bar 280 $(document.body).on( 'xoo_wsc_before_loading_fragments', this.storeShippingBarWidth.bind(this) ); 281 282 } 283 284 285 openCart(e){ 286 if( e ){ 287 e.preventDefault(); 288 } 289 this.toggle('show'); 290 } 291 292 addToCartFormSubmit(e){ 293 294 var $form = $(e.currentTarget); 295 296 if( $form.closest('.product').hasClass('product-type-external') ) return; 297 298 e.preventDefault(); 299 300 var $button = $form.find( 'button[type="submit"]'), 301 productData = $form.serializeArray(), 302 hasProductId = false; 303 304 //Check for woocommerce custom quantity code 305 //https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/ 306 $.each( productData, function( key, form_item ){ 307 if( form_item.name === 'productID' || form_item.name === 'add-to-cart' ){ 308 if( form_item.value ){ 309 hasProductId = true; 310 return false; 311 } 312 } 313 }) 314 315 //If no product id found , look for the form action URL 316 if( !hasProductId && $form.attr('action') ){ 317 var is_url = $form.attr('action').match(/add-to-cart=([0-9]+)/), 318 productID = is_url ? is_url[1] : false; 319 } 320 321 // if button as name add-to-cart get it and add to form 322 if( $button.attr('name') && $button.attr('name') == 'add-to-cart' && $button.attr('value') ){ 323 var productID = $button.attr('value'); 324 } 325 326 if( productID ){ 327 productData.push({name: 'add-to-cart', value: productID}); 328 } 329 330 productData.push({name: 'action', value: 'xoo_wsc_add_to_cart'}); 331 332 this.addToCartAjax( $button, productData );//Ajax add to cart 333 } 334 335 336 addToCartAjax( $button, productData ){
337 338 this.block(); 339 340 $button.addClass('loading'); 341 342 // Trigger event. 343 $( document.body ).trigger( 'adding_to_cart', [ $button, productData ] ); 344 345 $.ajax({ 346 url: get_wcurl( 'xoo_wsc_add_to_cart' ), 347 type: 'POST', 348 context: this, 349 data: $.param(productData), 350 success: function(response){ 351 352 if(response.fragments){ 353 // Trigger event so themes can refresh other areas. 354 $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $button ] ); 355 }else{ 356 window.location.reload(); 357 } 358 359 }, 360 complete: function(){ 361 this.unblock(); 362 $button 363 .removeClass('loading') 364 .addClass('added'); 365 } 366 }) 367 } 368 369 addedToCart( e, response, hash, $button ){ 370 371 this.updateFragments( { fragments: response } ); 372 373 this.onCartUpdate(); 374 375 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 376 377 var _this = this; 378 379 this.flyToCart( $button, function(){ 380 if( xoo_wsc_params.autoOpenCart === "yes" ){ 381 setTimeout(function(){ 382 _this.openCart(); 383 },20 ) 384 } 385 } ); 386 } 387 388 389 flyToCart( $atcEL, callback ){ 390 391 var $basket = this.$modal.find('.xoo-wsc-basket').length ? this.$modal.find('.xoo-wsc-basket') : $(document.body).find('.xoo-wsc-sc-cont'); 392 393 if( !$basket.length || xoo_wsc_params.flyToCart !== 'yes' || !$atcEL || !$atcEL.length ){ 394 callback(); 395 return; 396 } 397 398 var customDragImgClass = xoo_wsc_params.productFlyClass, 399 $dragIMG = null, 400 $product = $atcEL.closest('.product'); 401 402 403 //If has product container 404 if( $product.length ){ 405 406 $product = $($product[0]); 407 408 var $productGallery = $product.find('.woocommerce-product-gallery'); 409 410 if( customDragImgClass && $product.find( customDragImgClass ).length ){ 411 $dragIMG = $product.find( customDragImgClass ); 412 } 413 else if( $product.find( 'img[data-xooWscFly="fly"]' ).length ){ 414 if( $productGallery.length ){ 415 $dragIMG = $productGallery.find( '.flex-active-slide img[data-xooWscFly="fly"]' ).length ? $productGallery.find( '.flex-active-slide img[data-xooWscFly="fly"]' ) : $productGallery.find( 'img[data-xooWscFly="fly"]' ) 416 } 417 else{ 418 $dragIMG = $product.find( 'img[data-xooWscFly="fly"]' ); 419 } 420 } 421 else if( $productGallery.length ){ 422 $dragIMG = $productGallery; 423 } 424 else{ 425 $dragIMG = $product; 426 } 427 428 } 429 else if( customDragImgClass ){ 430 var moveUp = 4; 431 for ( var i = moveUp; i >= 0; i-- ) { 432 var $foundImg = $atcEL.parent().find( customDragImgClass ); 433 if( $foundImg.length ){ 434 $dragIMG = $foundImg; 435 return false; 436 } 437 } 438 } 439 440 441 if( !$dragIMG || !$dragIMG.length ){ 442 callback(); 443 return; 444 } 445 446 $dragIMG = $dragIMG.eq(0); 447 448 var $imgclone = $dragIMG 449 .clone() 450 .offset({ 451 top: $dragIMG.offset().top, 452 left: $dragIMG.offset().left 453 }) 454 .addClass( 'xoo-wsc-fly-animating' ) 455 .appendTo( $('body') ) 456 .animate({ 457 'top': $basket.offset().top - 20, 458 'left': $basket.offset().left - 20, 459 'width': 75, 460 'height': 75 461 }, parseInt( xoo_wsc_params.flyToCartTime ), 'easeInOutExpo' ); 462 463 setTimeout(function () { 464 callback() 465 }, parseInt( xoo_wsc_params.flyToCartTime ) ); 466 467 $imgclone.animate({ 468 'width': 0, 469 'height': 0 470 }, function () { 471 $(this).detach(); 472 }); 473 474 } 475 476 477 toggleQty(e){ 478 479 var $toggler = $(e.currentTarget), 480 $input = $toggler.siblings('.xoo-wsc-qty'); 481 482 if( !$input.length ) return; 483 484 var baseQty = this.baseQty = parseFloat( $input.val() ), 485 step = parseFloat( $input.attr('step') ), 486 action = $toggler.hasClass( 'xoo-wsc-plus' ) ? 'add' : 'less', 487 newQty = action === 'add' ? baseQty + step : baseQty - step; 488 489 490 $input.val(newQty).trigger('change'); 491 492 } 493 494 changeInputQty(e){ 495 496 this.notice.hideNotification(); 497 498 var $_this = this, 499 $input = $(e.currentTarget), 500 newQty = parseFloat( $input.val() ), 501 step = parseFloat( $input.attr('step') ), 502 min = parseFloat( $input.attr('min') ), 503 max = parseFloat( $input.attr('max') ), 504 invalid = false, 505 message = false; 506 507 508 //Validation 509 510 if( isNaN( newQty ) || newQty < 0 || newQty < min ){ 511 invalid = true; 512 } 513 else if( newQty > max ){ 514 invalid = true;
515 message = xoo_wsc_params.strings.maxQtyError.replace( '%s%', max ); 516 } 517 else if( ( newQty % step ) !== 0 ){ 518 invalid = true; 519 message = xoo_wsc_params.strings.stepQtyError.replace( '%s%', step ); 520 } 521 522 //Set back to default quantity 523 if( invalid ){ 524 $input.val( this.baseQty ); 525 if( message ){ 526 this.notice.add( message, 'error' ); 527 this.notice.showNotification(); 528 } 529 return; 530 } 531 532 //Update 533 $input.val( newQty ); 534 535 clearTimeout( this.qtyUpdateDelay ); 536 537 this.qtyUpdateDelay = setTimeout(function(){ 538 $_this.updateItemQty( $input.parents('.xoo-wsc-product').data('key'), newQty ) 539 }, xoo_wsc_params.qtyUpdateDelay ); 540 541 542 } 543 544 updateItemQty( cart_key, qty ){ 545 546 if( !cart_key || qty === undefined ) return; 547 548 this.block(); 549 550 551 var bodyPosition = this.$modal.find('.xoo-wsc-body').length ? this.$modal.find('.xoo-wsc-body').scrollTop() : false; 552 553 554 var formData = { 555 cart_key: cart_key, 556 qty: qty 557 } 558 559 $.ajax({ 560 url: get_wcurl( 'xoo_wsc_update_item_quantity' ), 561 type: 'POST', 562 context: this, 563 data: this.setAjaxData(formData), 564 success: function(response){ 565 this.updateFragments( response ); 566 $(document.body).trigger( 'xoo_wsc_quantity_updated', [response] ); 567 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 568 if( bodyPosition !== false ){ 569 this.$modal.find( '.xoo-wsc-body' ).scrollTop( bodyPosition ); 570 } 571 this.unblock(); 572 } 573 574 }) 575 } 576 577 578 closeCartOnClick(e){ 579 e.preventDefault(); 580 this.toggle( 'hide' ); 581 } 582 583 584 saveQtyFocus(e){ 585 this.baseQty = $(e.currentTarget).val(); 586 } 587 588 589 onPageShow(e){ 590 if ( e.originalEvent.persisted ) { 591 this.refreshMyFragments(); 592 $( document.body ).trigger( 'wc_fragment_refresh' ); 593 } 594 } 595 596 deleteIconClick(e){ 597 this.updateItemQty( $( e.currentTarget ).parents('.xoo-wsc-product').data('key'), 0 ); 598 } 599 600 undoItem(e){ 601 602 var $undo = $(e.currentTarget), 603 formData = { 604 cart_key: $undo.data('key') 605 } 606 607 this.block(); 608 609 $.ajax({ 610 url: get_wcurl('xoo_wsc_undo_item'), 611 type: 'POST', 612 context: this, 613 data: this.setAjaxData(formData), 614 success: function(response){ 615 this.updateFragments( response ); 616 $(document.body).trigger( 'xoo_wsc_item_restored', [response] ); 617 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 618 this.unblock(); 619 } 620 621 }) 622 } 623 624 storeShippingBarWidth( e ){ 625 var $bar = $(document.body).find( '.xoo-wsc-sb-bar > span' ); 626 if( !$bar.length ) return; 627 this.shippingBarWidth = $bar.prop('style').width; 628 } 629 630 onCartUpdate(){ 631 super.onCartUpdate(); 632 this.animateShippingBar(); 633 this.initSlider(); 634 this.showBasket(); 635 } 636 637 showBasket(){ 638 639 var $basket = $('.xoo-wsc-basket'), 640 show = xoo_wsc_params.showBasket; 641 642 if( show === "always_show" ){ 643 $basket.show(); 644 } 645 else if( show === "hide_empty" ){ 646 if( this.$modal.find('.xoo-wsc-product').length ){ 647 $basket.show(); 648 } 649 else{ 650 $basket.hide(); 651 } 652 } 653 else{ 654 $basket.hide(); 655 } 656 } 657 658 animateShippingBar(){ 659 if( isCartPage || isCheckoutPage ) return; 660 var $bar = $(document.body).find( '.xoo-wsc-sb-bar > span' ); 661 if( !$bar.length || !this.shippingBarWidth ) return; 662 var newWidth = $bar.prop('style').width; 663 $bar 664 .width( this.shippingBarWidth ) 665 .animate({ width: newWidth }, 400, 'linear') 666 } 667 668 669 emptyCart(){ 670 671 this.block(); 672 673 $.ajax({ 674 url: get_wcurl( 'xoo_wsc_empty_cart' ), 675 type: 'POST', 676 context: this, 677 data: {}, 678 success: function(response){ 679 680 this.updateFragments( response ); 681 // Trigger event. 682 $( document.body ).trigger( 'xoo_wsc_cart_emptied' ); 683 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 684 }, 685 complete: function(){ 686 this.unblock(); 687 } 688 }) 689 } 690 691 692 initSlider(){ 693 694 if( !$.isFunction( $.fn.lightSlider ) ) return; 695 696 $('ul.xoo-wsc-sp-slider').lightSlider({ 697 item: 1, 698 }); 699 700 } 701 702 } 703 704
705 706 class Slider extends Container{ 707 708 constructor( $modal ){ 709 710 super( $modal, 'slider' ); 711 712 if( xoo_wsc_params.sliderAutoClose ) this.noticeSection = 'cart'; 713 714 this.eventHandlers(); 715 716 this.shipping = xoo_wsc_params.shippingEnabled ? Shipping.init( this ) : null; 717 } 718 719 eventHandlers(){ 720 721 super.eventHandlers(); 722 723 724 $( document.body ).on( 'click', '.xoo-wsc-toggle-slider', this.triggerSlider.bind(this) ); 725 $( document.body ).on( 'xoo_wsc_cart_toggled', this.closeSliderOnCartClose.bind(this) ); 726 727 if( xoo_wsc_params.sliderAutoClose ){ 728 $( document.body ).on( 'xoo_wsc_coupon_applied xoo_wsc_shipping_calculated updated_shipping_method xoo_wsc_coupon_removed', this.closeSlider.bind(this) ); 729 } 730 731 this.$modal.on( 'submit', 'form.xoo-wsc-sl-apply-coupon', this.submitCouponForm.bind(this) ); 732 this.$modal.on( 'click', '.xoo-wsc-coupon-apply-btn', this.applyCouponFromBtn.bind(this) ); 733 $(document.body).on( 'click', '.xoo-wsc-remove-coupon', this.removeCoupon.bind(this) ); 734 } 735 736 737 removeCoupon(e){ 738 739 e.preventDefault(); 740 741 var $removeEl = $(e.currentTarget), 742 coupon = $removeEl.data('code'), 743 formData = { 744 coupon: coupon 745 }; 746 747 this.block(); 748 749 $.ajax( { 750 url: get_wcurl( 'xoo_wsc_remove_coupon' ), 751 type: 'POST', 752 context: this, 753 data: this.setAjaxData( formData, cart.$modal.find( $removeEl ).length ? 'cart' : 'slider' ), 754 success: function( response ) { 755 this.updateFragments(response); 756 }, 757 complete: function() { 758 this.unblock(); 759 this.updateCartCheckoutPage(); 760 $( document.body ).trigger( 'xoo_wsc_coupon_removed' ); 761 } 762 } ); 763 } 764 765 onCartUpdate(){ 766 super.onCartUpdate(); 767 this.toggleContent(); 768 } 769 770 closeSlider(){ 771 this.toggle('hide'); 772 } 773 774 775 applyCouponFromBtn(e){ 776 this.applyCoupon( $(e.currentTarget).val() ); 777 } 778 779 submitCouponForm(e){ 780 781 e.preventDefault(); 782 783 var $form = $(e.currentTarget); 784 785 this.applyCoupon( $form.find('input[name="xoo-wsc-slcf-input"]').val() ); 786 787 } 788 789 790 closeSliderOnCartClose(e){ 791 792 var $this = $(e.currentTarget); 793 794 if( !cart.$modal.hasClass('xoo-wsc-cart-active') ){ 795 this.toggle('hide'); 796 } 797 798 } 799 800 801 triggerSlider(e){ 802 803 var $toggler = $(e.currentTarget), 804 slider = $toggler.data('slider'); 805 806 if( slider === 'shipping' && isCheckoutPage ){ 807 this.notice.add( xoo_wsc_params.strings.calculateCheckout, 'error' ); 808 this.notice.showNotification(); 809 return; 810 } 811 812 813 this.$modal.attr( 'data-slider', slider ); 814 815 this.toggle(); 816 817 this.toggleContent(); 818 } 819 820 821 toggleContent(){ 822 823 var activeSlider = ''; 824 825 $('.xoo-wsc-sl-content').hide(); 826 827 var activeSlider = this.$modal.attr('data-slider'), 828 $toggleEl = $('.xoo-wsc-sl-content[data-slider="'+activeSlider+'"]'); 829 830 if( $toggleEl.length ) $toggleEl.show(); 831 832 $( document.body ).trigger( 'xoo_wsc_slider_data_toggled', [activeSlider] ); 833 } 834 835 836 applyCoupon( coupon ){ 837 838 if( !coupon ){ 839 this.notice.add( xoo_wsc_params.strings.couponEmpty, 'error' ); 840 this.notice.showNotification(); 841 return; 842 } 843 844 this.block(); 845 846 var formData = { 847 'coupon': coupon, 848 } 849 850 $.ajax( { 851 url: get_wcurl('xoo_wsc_apply_coupon'), 852 type: 'POST', 853 context: this, 854 data: this.setAjaxData( formData ), 855 success: function( response ) { 856 this.updateFragments(response); 857 }, 858 complete: function() { 859 this.unblock(); 860 this.updateCartCheckoutPage(); 861 $( document.body ).trigger( 'xoo_wsc_coupon_applied' ); 862 } 863 } ); 864 865 } 866 867 } 868 869 870 871 var Shipping = { 872 873 init: function( slider ){ 874 slider.$modal.on( 'change', 'input.xoo-wsc-shipping-method', this.shippingMethodChange ); 875 slider.$modal.on( 'submit', 'form.woocommerce-shipping-calculator', this.shippingCalculatorSubmit ); 876 slider.$modal.on( 'click', '.shipping-calculator-button', this.toggleCalculator ); 877 $(document.body).on( 'wc_fragments_refreshed wc_fragments_loaded xoo_wsc_slider_data_toggled', this.initSelect2 ); 878 }, 879 880 toggleCalculator: function(e){
881 882 e.preventDefault(); 883 e.stopImmediatePropagation(); 884 885 $(this).siblings('.shipping-calculator-form').slideToggle(); 886 $( document.body ).trigger( 'country_to_state_changed' ); 887 }, 888 889 shippingCalculatorSubmit: function(e){ 890 891 e.preventDefault(); 892 e.stopImmediatePropagation(); 893 894 var $form = $(this); 895 896 slider.block(); 897 898 // Provide the submit button value because wc-form-handler expects it. 899 $( '<input />' ) 900 .attr( 'type', 'hidden' ) 901 .attr( 'name', 'calc_shipping' ) 902 .attr( 'value', 'x' ) 903 .appendTo( $form ); 904 905 var formData = $form.serialize(); 906 907 // Make call to actual form post URL. 908 $.ajax( { 909 url: get_wcurl( 'xoo_wsc_calculate_shipping' ), 910 type: 'POST', 911 context: this, 912 data: slider.setAjaxData(formData), 913 success: function( response ) { 914 slider.updateFragments(response); 915 }, 916 complete: function() { 917 slider.unblock(); 918 slider.updateCartCheckoutPage(); 919 $( document.body ).trigger( 'xoo_wsc_shipping_calculated' ); 920 } 921 } ); 922 923 }, 924 925 shippingMethodChange: function(e){ 926 927 e.preventDefault(); 928 e.stopImmediatePropagation(); 929 930 var shipping_methods = {}; 931 932 slider.block(); 933 934 $( 'select.shipping_method, :input[name^=xoo-wsc-shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]' ).each( function() { 935 shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val(); 936 } ); 937 938 var formData = { 939 shipping_method: shipping_methods, 940 } 941 942 $.ajax( { 943 type: 'POST', 944 url: get_wcurl( 'xoo_wsc_update_shipping_method' ), 945 data: slider.setAjaxData( formData ), 946 success: function( response ) { 947 slider.updateFragments(response); 948 }, 949 complete: function() { 950 slider.unblock(); 951 slider.updateCartCheckoutPage(); 952 $( document.body ).trigger( 'updated_shipping_method' ); 953 } 954 } ); 955 956 }, 957 958 initSelect2: function(e){ 959 $( document.body ).trigger( 'country_to_state_changed' ); 960 }, 961 } 962 963 964 var cart = new Cart( $('.xoo-wsc-modal') ), 965 slider = new Slider( $('.xoo-wsc-slider-modal') ); 966 967})
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.