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 var markupTimeout = null; 15 16 class Notice{ 17 18 constructor( $modal ){ 19 this.$modal = $modal; 20 this.timeout = null; 21 } 22 23 add( notice, type = 'success', clearPrevious = true ){ 24 25 var $noticeCont = this.$modal.find('.xoo-wsc-notice-container'); 26 27 if( clearPrevious ){ 28 $noticeCont.html(''); 29 } 30 31 var noticeHTML = type === 'success' ? xoo_wsc_params.html.successNotice.toString().replace( '%s%', notice ) : xoo_wsc_params.html.errorNotice.toString().replace( '%s%', notice ); 32 33 $noticeCont.html( noticeHTML ); 34 35 } 36 37 showNotification(){ 38 39 Notice.showMarkupNotice(); 40 41 var $noticeCont = this.$modal.find('.xoo-wsc-notice-container'); 42 43 if( !$noticeCont.length || $noticeCont.children().length === 0 ) return; 44 45 $noticeCont.slideDown(); 46 47 clearTimeout(this.timeout); 48 49 this.timeout = setTimeout(function(){ 50 $noticeCont.slideUp('slow',function(){ 51 //$noticeCont.html(''); 52 }); 53 },xoo_wsc_params.notificationTime ) 54 55 } 56 57 58 59 hideNotification(){ 60 this.$modal.find('.xoo-wsc-notice-container').hide(); 61 } 62 63 static hideMarkupNotice(){ 64 Notice.$noticeContainer().removeClass('xoo-wsc-active'); 65 } 66 67 static $noticeContainer(){ 68 return $('.xoo-wsc-markup-notices') 69 } 70 71 static showMarkupNotice(){ 72 73 if( cart.isOpen() ) return; 74 75 var $markupNotice = Notice.$noticeContainer(); 76 77 var $notices = $markupNotice.find('.xoo-wsc-notice-container .xoo-wsc-notices'); 78 79 if( !$notices.length || $notices.children().length === 0 ) return; 80 81 setTimeout(function(){$markupNotice.addClass('xoo-wsc-active')},10); 82 83 clearTimeout(markupTimeout); 84 85 markupTimeout = setTimeout(function(){ 86 $markupNotice.removeClass('xoo-wsc-active'); 87 },xoo_wsc_params.notificationTime ) 88 } 89 } 90 91 92 class Container{ 93 94 constructor( $modal, container ){ 95 this.$modal = $modal; 96 this.container = container || 'cart'; 97 this.notice = new Notice( this.$modal ); 98 } 99 100 isOpen(){ 101 return this.$modal.hasClass('xoo-wsc-'+this.container+'-active'); 102 } 103 104 eventHandlers(){ 105 $(document.body).on( 'wc_fragments_refreshed updated_checkout', this.onCartUpdate.bind(this) ); 106 } 107 108 onCartUpdate(){ 109 this.unblock(); 110 this.notice.showNotification(); 111 } 112 113 setAjaxData( data, noticeSection ){ 114 115 var ajaxData = { 116 container: this.container, 117 noticeSection: noticeSection || this.noticeSection || this.container, 118 isCheckout: isCheckoutPage, 119 isCart: isCartPage 120 } 121 122 123 if( typeof data === 'object' ){ 124 125 $.extend( ajaxData, data ); 126 127 } 128 else{ 129 130 var serializedData = data; 131 132 $.each( ajaxData, function( key, value ){ 133 serializedData += ( '&'+key+'='+value ); 134 } ) 135 136 ajaxData = serializedData; 137 138 } 139 140 return ajaxData; 141 } 142 143 144 toggle( type ){ 145 146 var $activeEls = this.$modal.add( 'body' ).add('html'), 147 activeClass = 'xoo-wsc-'+ this.container +'-active'; 148 149 if( type === 'show' ){ 150 $activeEls.addClass(activeClass); 151 } 152 else if( type === 'hide' ){ 153 $activeEls.removeClass(activeClass); 154 } 155 else{ 156 $activeEls.toggleClass(activeClass); 157 } 158 159 $(document.body).trigger( 'xoo_wsc_' + this.container + '_toggled', [ type ] ); 160 161 this.notice.hideNotification(); 162 163 } 164 165 166 block(){ 167 this.$modal.addClass('xoo-wsc-loading'); 168 } 169 170 unblock(){ 171 this.$modal.removeClass('xoo-wsc-loading'); 172 } 173 174 175 refreshMyFragments(){ 176 177 if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){ 178 $( document.body ).trigger( 'wc_fragment_refresh' ); 179 return; 180 } 181 182 this.block(); 183 184 $.ajax({ 185 url: get_wcurl( 'xoo_wsc_refresh_fragments' ), 186 type: 'POST', 187 context: this, 188 data: {}, 189 success: function( response ){ 190 this.updateFragments(response); 191 }, 192 complete: function(){ 193 this.unblock(); 194 } 195 }) 196 197 } 198 199 200 updateCartCheckoutPage(){ 201 202 //Refresh checkout page 203 if( isCheckoutPage ){ 204 if( $( 'form.checkout' ).length === 0 ){ 205 location.reload(); 206 return; 207 } 208 $(document.body).trigger("update_checkout"); 209 } 210 211 //Refresh Cart page 212 if( isCartPage ){ 213 $(document.body).trigger("wc_update_cart"); 214 } 215 216 } 217 218 updateFragments( response ){ 219 220 console.log('updated'); 221 222 if( response.fragments ){ 223 224 $( document.body ).trigger( 'xoo_wsc_before_loading_fragments', [ response ] ); 225 226 this.block(); 227 228 //Set fragments 229 $.each( response.fragments, function( key, value ) { 230 $( key ).replaceWith( value ); 231 }); 232 233 if( typeof wc_cart_fragments_params !== 'undefined' && ( 'sessionStorage' in window && window.sessionStorage !== null ) ){ 234 235 sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( response.fragments ) ); 236 localStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash ); 237 sessionStorage.setItem( wc_cart_fragments_params.cart_hash_key, response.cart_hash ); 238 239 if ( response.cart_hash ) { 240 sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() ); 241 } 242 243 } 244 245 $( document.body ).trigger( 'wc_fragments_refreshed' ); 246 247 this.unblock(); 248 249 } 250 251 if( xoo_wsc_params.refreshCart === "yes" && typeof wc_cart_fragments_params !== 'undefined' ){ 252 this.block(); 253 $( document.body ).trigger( 'wc_fragment_refresh' ); 254 return; 255 } 256 257 } 258 259 } 260 261 262 class Cart extends Container{ 263 264 constructor( $modal ){ 265 266 super( $modal, 'cart' ); 267 268 this.cartLoaded = false; 269 270 this.refreshFragmentsOnPageLoad(); 271 this.eventHandlers(); 272 273 } 274 275 276 refreshFragmentsOnPageLoad(){ 277 if( xoo_wsc_params.fetchCart === 'page_load' ){ 278 setTimeout(function(){ 279 this.refreshMyFragments(); 280 }.bind(this), xoo_wsc_params.fetchDelay ) 281 } 282 } 283 284 eventHandlers(){ 285 286 super.eventHandlers(); 287 288 this.$modal.on( 'click', '.xoo-wsc-smr-del', this.deleteIconClick.bind(this) ); 289 this.$modal.on( 'click', '.xoo-wsch-close, .xoo-wsc-opac, .xoo-wsc-cart-close', this.closeCartOnClick.bind(this) ); 290 this.$modal.on( 'click', '.xoo-wsc-basket', this.toggleCart.bind(this) ); 291 292 $(document.body).on( 'xoo_wsc_cart_updated', this.updateCartCheckoutPage.bind(this) ); 293 $(document.body).on( 'click', 'a.added_to_cart, .xoo-wsc-cart-trigger', this.openCart.bind(this) ); 294 $(document.body).on( 'added_to_cart', this.addedToCart.bind(this) ); 295 296 $(document.body).on( 'wc-blocks_added_to_cart', this.blockAddedToCart.bind(this) ); 297 298 if( xoo_wsc_params.autoOpenCart === 'yes' && xoo_wsc_params.addedToCart === 'yes'){ 299 this.openCart(); 300 } 301 302 if( xoo_wsc_params.ajaxAddToCart === 'yes' ){ 303 $(document.body).on( 'submit', 'form.cart', this.addToCartFormSubmit.bind(this) ); 304 } 305 306 if( typeof wc_cart_fragments_params === 'undefined' ){ 307 $( window ).on( 'pageshow' , this.onPageShow.bind(this) ); 308 } 309 310 if( xoo_wsc_params.triggerClass ){ 311 $(document.body).on( 'click', '.'+xoo_wsc_params.triggerClass, this.openCart.bind(this) ); 312 } 313 314 315 if( isCheckoutPage || isCartPage ){ 316 $(document.body).on( 'updated_shipping_method', this.refreshMyFragments.bind(this) ); 317 } 318 319 this.initMasonryLayout(); 320 321 } 322 323 toggleCart(e){ 324 if( this.isOpen() ){ 325 this.closeCartOnClick(e); 326 } 327 else{ 328 this.openCart(e); 329 } 330 331 } 332 333 openCart(e){ 334 if( e ){ 335 e.preventDefault(); 336 e.stopImmediatePropagation(); 337 } 338 339 if( !this.cartLoaded && xoo_wsc_params.fetchCart === 'cart_open' ){ 340 this.refreshMyFragments(); 341 this.cartLoaded = true; 342 } 343 344 this.toggle('show'); 345 Notice.hideMarkupNotice(); 346 } 347 348 addToCartFormSubmit(e){ 349 350 var $form = $(e.currentTarget); 351 352 if( $form.closest('.product').hasClass('product-type-external') || $form.siblings('.xoo-wsc-disable-atc').length ) return; 353 354 var $button = e.originalEvent && e.originalEvent.submitter ? $(e.originalEvent.submitter) : $form.find( 'button[type="submit"]'), 355 formData = new FormData($form.get(0)), 356 productData = $form.serializeArray(), 357 hasProductId = false; 358 359 //Check for woocommerce custom quantity code 360 //https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/ 361 $.each( productData, function( key, form_item ){ 362 if( form_item.name === 'productID' || form_item.name === 'add-to-cart' ){ 363 if( form_item.value ){ 364 hasProductId = true; 365 return false; 366 } 367 } 368 }) 369 370 //If no product id found , look for the form action URL 371 if( !hasProductId && $form.attr('action') ){ 372 var is_url = $form.attr('action').match(/add-to-cart=([0-9]+)/), 373 productID = is_url ? is_url[1] : false; 374 } 375 376 // Add submitted button value 377 if( $button.attr('name') && $button.attr('value') ){ 378 formData.append( $button.attr('name'), $button.attr('value') ); 379 } 380 381 if( productID ){ 382 formData.append( 'add-to-cart', productID ); 383 } 384 385 formData.append( 'action', 'xoo_wsc_add_to_cart' ); 386
387 var doAjaxAddToCart = true; 388 389 390 $.each( xoo_wsc_params.skipAjaxForData, function( key, value ){ 391 if( formData.has(key) && ( !value || formData.get(key) == value ) ){ 392 doAjaxAddToCart = false; 393 return false; 394 } 395 } ) 396 397 398 if( doAjaxAddToCart ){ 399 e.preventDefault(); 400 this.addToCartAjax( $button, formData );//Ajax add to cart 401 } 402 403 } 404 405 406 addToCartAjax( $button, formData ){ 407 408 this.block(); 409 410 $button.addClass('loading'); 411 412 // Trigger event. 413 $( document.body ).trigger( 'adding_to_cart', [ $button, formData ] ); 414 415 $.ajax({ 416 url: get_wcurl( 'xoo_wsc_add_to_cart' ), 417 type: 'POST', 418 context: this, 419 cache: false, 420 contentType: false, 421 processData: false, 422 data: formData, 423 success: function(response){ 424 425 if(response.fragments){ 426 // Trigger event so themes can refresh other areas. 427 $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $button ] ); 428 }else if(response.error){ 429 Notice.$noticeContainer().replaceWith(response.notice); 430 Notice.showMarkupNotice(); 431 } 432 else{ 433 window.location.reload(); 434 } 435 436 }, 437 complete: function(){ 438 this.unblock(); 439 $button 440 .removeClass('loading') 441 .addClass('added'); 442 } 443 }) 444 } 445 446 addedToCart( e, response, hash, $button ){ 447 448 this.updateFragments( { fragments: response } ); 449 450 this.onCartUpdate(); 451 452 var _this = this; 453 454 455 if( xoo_wsc_params.autoOpenCart === "yes" ){ 456 setTimeout(function(){ 457 _this.openCart(); 458 },20 ) 459 } 460 461 } 462 463 blockAddedToCart(){ 464 465 $( document.body ).trigger( 'wc_fragment_refresh' ); 466 467 this.block(); 468 469 var _this = this; 470 471 if( xoo_wsc_params.autoOpenCart === "yes" ){ 472 setTimeout(function(){ 473 _this.openCart(); 474 },20 ) 475 } 476 } 477 478 479 closeCartOnClick(e){ 480 e.preventDefault(); 481 this.toggle( 'hide' ); 482 } 483 484 485 onPageShow(e){ 486 if ( e.originalEvent.persisted ) { 487 this.refreshMyFragments(); 488 $( document.body ).trigger( 'wc_fragment_refresh' ); 489 } 490 } 491 492 deleteIconClick(e){ 493 this.updateItemQty( $( e.currentTarget ).parents('.xoo-wsc-product').data('key'), 0 ); 494 } 495 496 updateItemQty( cart_key, qty ){ 497 498 if( !cart_key || qty === undefined ) return; 499 500 this.block(); 501 502 var formData = { 503 cart_key: cart_key, 504 qty: qty 505 } 506 507 $.ajax({ 508 url: get_wcurl( 'xoo_wsc_update_item_quantity' ), 509 type: 'POST', 510 context: this, 511 data: this.setAjaxData(formData), 512 success: function(response){ 513 this.updateFragments( response ); 514 $(document.body).trigger( 'xoo_wsc_quantity_updated', [response] ); 515 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 516 this.unblock(); 517 } 518 519 }) 520 } 521 522 onCartUpdate(){ 523 super.onCartUpdate(); 524 this.cartLoaded = true; 525 this.toggleBasket(); 526 this.initMasonryLayout(); 527 } 528 529 530 initMasonryLayout(){ 531 if( xoo_wsc_params.productLayout !== 'cards' ) return; 532 $('.xoo-wsc-products.xoo-wsc-pattern-card').masonry({ 533 // options 534 itemSelector: '.xoo-wsc-product-cont', 535 columnWidth: '.xoo-wsc-product-cont', /* Each column takes 50% */ 536 percentPosition: true 537 }); 538 } 539 540 541 toggleBasket(){ 542 543 var $basket = $('.xoo-wsc-basket'), 544 show = xoo_wsc_params.showBasket, 545 hasProducts = this.$modal.find('.xoo-wsc-product').length; 546 547 if( show === "always_show" ){ 548 $basket.show(); 549 } 550 else if( show === "hide_empty" ){ 551 if( hasProducts){ 552 $basket.show(); 553 } 554 else{ 555 $basket.hide(); 556 } 557 } 558 else{ 559 $basket.hide(); 560 } 561 562 var $shortcode = $('.xoo-wsc-sc-cont'); 563 564 if( $shortcode.length && xoo_wsc_params.menuCartHideOnEmpty.length ){ 565 566 var shortcodeEls = xoo_wsc_params.shortcodeEls; 567 568 $.each( xoo_wsc_params.menuCartHideOnEmpty, function( index, val ){ 569 570 if( shortcodeEls[val] ){ 571 if( hasProducts ){ 572 $(shortcodeEls[val]).show(); 573 } 574 else{ 575 $(shortcodeEls[val]).hide(); 576 } 577 } 578 579 }) 580 581 } 582 } 583 584 585 586 } 587 588 589 590 591 var cart = new Cart( $('.xoo-wsc-modal') ); 592 593 594 var AnimateCard = { 595 596 type: xoo_wsc_params.cardAnimate.type, 597 duration: xoo_wsc_params.cardAnimate.duration, 598 599 init: function(){ 600 601 var onEvent = xoo_wsc_params.cardAnimate.event === 'back_hover' ? 'mouseenter' : 'click'; 602 603 $('body').on( onEvent, '.xoo-wsc-has-back', this.animate ); 604 $('body').on( 'mouseleave', '.xoo-wsc-has-back', this.reverseAnimate ); 605 606 }, 607 animate: function(e){
608 609 if( e.target.classList.contains('xoo-wsc-smr-del') ) return; 610 611 var $img = $(this).find('.xoo-wsc-img-col'); 612 613 if( !$img.hasClass('xoo-wsc-caniming') ){ 614 e.preventDefault(); 615 } 616 else{ 617 return; 618 } 619 620 $img.attr('data-exclasses', $img.attr('class') ); 621 622 $img.removeClass() 623 $img.addClass($img.attr('data-exclasses')); 624 625 $img.addClass( 'xoo-wsc-caniming' + ' ' + AnimateCard.type ); 626 627 }, 628 reverseAnimate: function(){ 629 630 var $img = $(this).find('.xoo-wsc-img-col'); 631 632 if( !$img.hasClass( 'xoo-wsc-caniming' ) ) return; 633 634 $img.addClass(AnimateCard.type+'Return'); 635 636 AnimateCard.clear = setTimeout(function(){ 637 $img.removeClass().addClass( $img.attr('data-exclasses') ); 638 }, AnimateCard.duration * 1000); 639 640 } 641 } 642 643 if( xoo_wsc_params.cardAnimate.enable === "yes" ){ 644 AnimateCard.init(); 645 } 646 647 648})
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.