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