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.refreshFragmentsOnPageLoad(); 269 this.eventHandlers(); 270 271 } 272 273 274 refreshFragmentsOnPageLoad(){ 275 setTimeout(function(){ 276 this.refreshMyFragments(); 277 }.bind(this), xoo_wsc_params.fetchDelay ) 278 } 279 280 eventHandlers(){ 281 282 super.eventHandlers(); 283 284 this.$modal.on( 'click', '.xoo-wsc-smr-del', this.deleteIconClick.bind(this) ); 285 this.$modal.on( 'click', '.xoo-wsch-close, .xoo-wsc-opac, .xoo-wsc-cart-close', this.closeCartOnClick.bind(this) ); 286 this.$modal.on( 'click', '.xoo-wsc-basket', this.toggleCart.bind(this) ); 287 288 $(document.body).on( 'xoo_wsc_cart_updated', this.updateCartCheckoutPage.bind(this) ); 289 $(document.body).on( 'click', 'a.added_to_cart, .xoo-wsc-cart-trigger', this.openCart.bind(this) ); 290 $(document.body).on( 'added_to_cart', this.addedToCart.bind(this) ); 291 292 $(document.body).on( 'wc-blocks_added_to_cart', this.blockAddedToCart.bind(this) ); 293 294 if( xoo_wsc_params.autoOpenCart === 'yes' && xoo_wsc_params.addedToCart === 'yes'){ 295 this.openCart(); 296 } 297 298 if( xoo_wsc_params.ajaxAddToCart === 'yes' ){ 299 $(document.body).on( 'submit', 'form.cart', this.addToCartFormSubmit.bind(this) ); 300 } 301 302 if( typeof wc_cart_fragments_params === 'undefined' ){ 303 $( window ).on( 'pageshow' , this.onPageShow.bind(this) ); 304 } 305 306 if( xoo_wsc_params.triggerClass ){ 307 $(document.body).on( 'click', '.'+xoo_wsc_params.triggerClass, this.openCart.bind(this) ); 308 } 309 310 311 if( isCheckoutPage || isCartPage ){ 312 $(document.body).on( 'updated_shipping_method', this.refreshMyFragments.bind(this) ); 313 } 314 315 this.initMasonryLayout(); 316 317 } 318 319 toggleCart(e){ 320 if( this.isOpen() ){ 321 this.closeCartOnClick(e); 322 } 323 else{ 324 this.openCart(e); 325 } 326 327 } 328 329 openCart(e){ 330 if( e ){ 331 e.preventDefault(); 332 e.stopImmediatePropagation(); 333 } 334 this.toggle('show'); 335 Notice.hideMarkupNotice(); 336 } 337 338 addToCartFormSubmit(e){ 339 340 var $form = $(e.currentTarget); 341 342 if( $form.closest('.product').hasClass('product-type-external') || $form.siblings('.xoo-wsc-disable-atc').length ) return; 343 344 var $button = e.originalEvent && e.originalEvent.submitter ? $(e.originalEvent.submitter) : $form.find( 'button[type="submit"]'), 345 formData = new FormData($form.get(0)), 346 productData = $form.serializeArray(), 347 hasProductId = false; 348 349 //Check for woocommerce custom quantity code 350 //https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/ 351 $.each( productData, function( key, form_item ){ 352 if( form_item.name === 'productID' || form_item.name === 'add-to-cart' ){ 353 if( form_item.value ){ 354 hasProductId = true; 355 return false; 356 } 357 } 358 }) 359 360 //If no product id found , look for the form action URL 361 if( !hasProductId && $form.attr('action') ){ 362 var is_url = $form.attr('action').match(/add-to-cart=([0-9]+)/), 363 productID = is_url ? is_url[1] : false; 364 } 365 366 // Add submitted button value 367 if( $button.attr('name') && $button.attr('value') ){ 368 formData.append( $button.attr('name'), $button.attr('value') ); 369 } 370 371 if( productID ){ 372 formData.append( 'add-to-cart', productID ); 373 } 374 375 formData.append( 'action', 'xoo_wsc_add_to_cart' ); 376
377 var doAjaxAddToCart = true; 378 379 380 $.each( xoo_wsc_params.skipAjaxForData, function( key, value ){ 381 if( formData.has(key) && ( !value || formData.get(key) == value ) ){ 382 doAjaxAddToCart = false; 383 return false; 384 } 385 } ) 386 387 388 if( doAjaxAddToCart ){ 389 e.preventDefault(); 390 this.addToCartAjax( $button, formData );//Ajax add to cart 391 } 392 393 } 394 395 396 addToCartAjax( $button, formData ){ 397 398 this.block(); 399 400 $button.addClass('loading'); 401 402 // Trigger event. 403 $( document.body ).trigger( 'adding_to_cart', [ $button, formData ] ); 404 405 $.ajax({ 406 url: get_wcurl( 'xoo_wsc_add_to_cart' ), 407 type: 'POST', 408 context: this, 409 cache: false, 410 contentType: false, 411 processData: false, 412 data: formData, 413 success: function(response){ 414 415 if(response.fragments){ 416 // Trigger event so themes can refresh other areas. 417 $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $button ] ); 418 }else if(response.error){ 419 Notice.$noticeContainer().replaceWith(response.notice); 420 Notice.showMarkupNotice(); 421 } 422 else{ 423 window.location.reload(); 424 } 425 426 }, 427 complete: function(){ 428 this.unblock(); 429 $button 430 .removeClass('loading') 431 .addClass('added'); 432 } 433 }) 434 } 435 436 addedToCart( e, response, hash, $button ){ 437 438 this.updateFragments( { fragments: response } ); 439 440 this.onCartUpdate(); 441 442 var _this = this; 443 444 445 if( xoo_wsc_params.autoOpenCart === "yes" ){ 446 setTimeout(function(){ 447 _this.openCart(); 448 },20 ) 449 } 450 451 } 452 453 blockAddedToCart(){ 454 455 $( document.body ).trigger( 'wc_fragment_refresh' ); 456 457 this.block(); 458 459 var _this = this; 460 461 if( xoo_wsc_params.autoOpenCart === "yes" ){ 462 setTimeout(function(){ 463 _this.openCart(); 464 },20 ) 465 } 466 } 467 468 469 closeCartOnClick(e){ 470 e.preventDefault(); 471 this.toggle( 'hide' ); 472 } 473 474 475 onPageShow(e){ 476 if ( e.originalEvent.persisted ) { 477 this.refreshMyFragments(); 478 $( document.body ).trigger( 'wc_fragment_refresh' ); 479 } 480 } 481 482 deleteIconClick(e){ 483 this.updateItemQty( $( e.currentTarget ).parents('.xoo-wsc-product').data('key'), 0 ); 484 } 485 486 updateItemQty( cart_key, qty ){ 487 488 if( !cart_key || qty === undefined ) return; 489 490 this.block(); 491 492 var formData = { 493 cart_key: cart_key, 494 qty: qty 495 } 496 497 $.ajax({ 498 url: get_wcurl( 'xoo_wsc_update_item_quantity' ), 499 type: 'POST', 500 context: this, 501 data: this.setAjaxData(formData), 502 success: function(response){ 503 this.updateFragments( response ); 504 $(document.body).trigger( 'xoo_wsc_quantity_updated', [response] ); 505 $(document.body).trigger( 'xoo_wsc_cart_updated', [response] ); 506 this.unblock(); 507 } 508 509 }) 510 } 511 512 onCartUpdate(){ 513 super.onCartUpdate(); 514 this.toggleBasket(); 515 this.initMasonryLayout(); 516 } 517 518 519 initMasonryLayout(){ 520 if( xoo_wsc_params.productLayout !== 'cards' ) return; 521 $('.xoo-wsc-products.xoo-wsc-pattern-card').masonry({ 522 // options 523 itemSelector: '.xoo-wsc-product-cont', 524 columnWidth: '.xoo-wsc-product-cont', /* Each column takes 50% */ 525 percentPosition: true 526 }); 527 } 528 529 530 toggleBasket(){ 531 532 var $basket = $('.xoo-wsc-basket'), 533 show = xoo_wsc_params.showBasket, 534 hasProducts = this.$modal.find('.xoo-wsc-product').length; 535 536 if( show === "always_show" ){ 537 $basket.show(); 538 } 539 else if( show === "hide_empty" ){ 540 if( hasProducts){ 541 $basket.show(); 542 } 543 else{ 544 $basket.hide(); 545 } 546 } 547 else{ 548 $basket.hide(); 549 } 550 551 var $shortcode = $('.xoo-wsc-sc-cont'); 552 553 if( $shortcode.length && xoo_wsc_params.menuCartHideOnEmpty.length ){ 554 555 var shortcodeEls = xoo_wsc_params.shortcodeEls; 556 557 $.each( xoo_wsc_params.menuCartHideOnEmpty, function( index, val ){ 558 559 if( shortcodeEls[val] ){ 560 if( hasProducts ){ 561 $(shortcodeEls[val]).show(); 562 } 563 else{ 564 $(shortcodeEls[val]).hide(); 565 } 566 } 567 568 }) 569 570 } 571 } 572 573 574 575 } 576 577 578 579 580 var cart = new Cart( $('.xoo-wsc-modal') ); 581 582 583 var AnimateCard = { 584 585 type: xoo_wsc_params.cardAnimate.type, 586 duration: xoo_wsc_params.cardAnimate.duration, 587 588 init: function(){ 589 590 var onEvent = xoo_wsc_params.cardAnimate.event === 'back_hover' ? 'mouseenter' : 'click'; 591 592 $('body').on( onEvent, '.xoo-wsc-has-back', this.animate ); 593 $('body').on( 'mouseleave', '.xoo-wsc-has-back', this.reverseAnimate ); 594 595 }, 596 animate: function(e){
597 598 if( e.target.classList.contains('xoo-wsc-smr-del') ) return; 599 600 var $img = $(this).find('.xoo-wsc-img-col'); 601 602 if( !$img.hasClass('xoo-wsc-caniming') ){ 603 e.preventDefault(); 604 } 605 else{ 606 return; 607 } 608 609 $img.attr('data-exclasses', $img.attr('class') ); 610 611 $img.removeClass() 612 $img.addClass($img.attr('data-exclasses')); 613 614 $img.addClass( 'xoo-wsc-caniming' + ' ' + AnimateCard.type ); 615 616 }, 617 reverseAnimate: function(){ 618 619 var $img = $(this).find('.xoo-wsc-img-col'); 620 621 if( !$img.hasClass( 'xoo-wsc-caniming' ) ) return; 622 623 $img.addClass(AnimateCard.type+'Return'); 624 625 AnimateCard.clear = setTimeout(function(){ 626 $img.removeClass().addClass( $img.attr('data-exclasses') ); 627 }, AnimateCard.duration * 1000); 628 629 } 630 } 631 632 if( xoo_wsc_params.cardAnimate.enable === "yes" ){ 633 AnimateCard.init(); 634 } 635 636 637})
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.