1 2var PlrPubCommon = { 3 4 lazyLoader: null, 5 6 init: function() { 7 PlrPubCommon.lazyLoader = new LazyLoad({ elements_selector: 'img.lazy' }); 8 }, 9 10 lazyReload: function() { 11 console.log('PlrPubCommon', this); 12 this.lazyLoader.update(); 13 }, 14 15 buildUrl: function(path) { 16 var siteUrl = plr_pub_data.site_relative_url; 17 if (siteUrl.endsWith('/')) { 18 siteUrl = siteUrl.slice(0, -1); 19 } 20 return siteUrl + path; 21 }, 22 23}; 24 25var PlrPubUser = { 26 27 user: null, 28 29 getUser: function() { 30 31 var url = PlrPubCommon.buildUrl('/mshops/user'); 32 33 var promise = jQuery.ajax(url) 34 .error(function (response) { 35 console.error(response); 36 }) 37 .done(function (response) { 38 39 if (response.value && response.value.user) { 40 this.user = response.value.user; 41 } 42 43 }); 44 45 return promise.then(function (response) { return response.value && response.value.user ? response.value.user : null; }); 46 }, 47 48} 49 50var PlrPubCart = { 51 52 hideNoticesTimeout: null, 53 54 init: function () { 55 56 jQuery('.plr-pub-add-to-cart-button').on('click', function(event) { 57 event.stopPropagation(); 58 event.preventDefault(); 59 60 var button = jQuery(this); 61 button.addClass('loading'); 62 63 var productUuid = button.data('product-uuid'); 64 65 PlrPubCart.add(productUuid) 66 .done(function (response) { 67 if (response.value.errors) { 68 var errorMessage = $('<div class="plr-pub-shop-error plr-pub-error" style="display: none;">' + response.value.errors[0] + '</div>'); 69 button.after(errorMessage); 70 errorMessage.fadeIn(500).delay(2000).fadeOut(500, function() { 71 $(this).remove(); 72 }); 73 } 74 }) 75 .always(function() { 76 button.removeClass('loading'); 77 }); 78 79 }); 80 81 this.initActions(); 82 83 }, 84 85 initActions: function () { 86 87 jQuery('.plr-pub-cart-item-actions-remove').unbind(); 88 jQuery('.plr-pub-cart-item-actions-remove').on('click', function() { 89 var uuid = jQuery(this).data('uuid'); 90 91 jQuery('.plr-pub-shopping-cart-side-product[data-uuid="' + uuid + '"] .plr-pub-cart-item-loading').removeClass('d-none'); 92 93 PlrPubCart.remove(uuid) 94 .done(function(response) { 95 96 jQuery('.plr-pub-shopping-cart-side-product[data-uuid="' + uuid + '"]').remove(); 97 jQuery('.plr-pub-shop-checkout-products-table .cart_item[data-uuid="' + uuid + '"]').remove(); 98 99 var notice = '<div class="plr-pub-shopping-cart-side-notice" data-type="success">' + response.value.message + '</div>'; 100 console.log('appending notice: ' + notice); 101 jQuery('.plr-pub-shopping-cart-side-notices-wrapper').append(notice).show(); 102 jQuery('.plr-pub-shop-notices-wrapper').append(notice); 103 104 if (PlrPubCart.hideNoticesTimeout) { 105 clearTimeout(PlrPubCart.hideNoticesTimeout); 106 } 107 PlrPubCart.hideNoticesTimeout = setTimeout(function() { 108 jQuery('.plr-pub-shopping-cart-side-notices-wrapper').hide().html(''); 109 jQuery('.plr-pub-shop-notices-wrapper').html(''); 110 PlrPubCart.hideNoticesTimeout = null; 111 }, 5000); 112 113 PlrPubSideCart.checkIsEmpty(); 114 115 PlrPubCart.updateTotals(); 116 117 }); 118 119 return false; 120 }); 121 122 this.getCart().done(function(response) { 123 console.log(response); 124 if (response.value) { 125 PlrPubCart.refreshCounts(response.value); 126 } 127 }); 128 129 }, 130 131 add: function (uuid, index, showSideCart = true) { 132 133 var url = PlrPubCommon.buildUrl('/mshops/cart/add-product?uuid=' + uuid); 134 if (index) { 135 url += '&index=' + index; 136 } 137 138 return jQuery.ajax(url).done(function (response) { 139 140 if (!response.value.errors) { 141 PlrPubCart.refreshCounts(response.value.items); 142 143 if (showSideCart) { 144 PlrPubSideCart.show(true); 145 } 146 147 } 148 149 }); 150 }, 151 152 remove: function (uuid) { 153 154 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/cart/remove-product?uuid=' + uuid)) 155 .error(function(response) { 156 console.error(response); 157 }) 158 .done(function(response) { 159 160 if (!response.value.errors) { 161 PlrPubCart.refreshCounts(response.value.items); 162 } 163 164 }); 165 166 return promise.then(function (response) { return response; }); 167 }, 168 169 refreshCounts: function (items) { 170 171 if (jQuery('.plr-pub-header-cart-button .et-pb-icon .plr-pub-cart-items-count').length == 0) { 172 var html = jQuery('.plr-pub-header-cart-button .et-pb-icon').html(); 173 html += ' <span class="plr-pub-cart-items-count"></span>'; 174 jQuery('.plr-pub-header-cart-button .et-pb-icon').html(html); 175 } 176 177 if (items.length > 0) { 178 jQuery('.plr-pub-cart-items-count').html('(' + items.length + ')'); 179 } else { 180 jQuery('.plr-pub-cart-items-count').html(''); 181 } 182 183 var total = 0; 184 for (var i = 0; i < items.length; i++) { 185 var item = items[i]; 186 var amount = parseInt(item.p) * parseInt(item.q); 187 total += amount; 188 } 189 190 jQuery('.plr-pub-cart-items-total').html(total); 191 }, 192 193 getCart: function() { 194 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/cart/get-cart')); 195 return promise.then(function (response) { return response; }); 196 }, 197 198 getCartProducts: function() { 199 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/cart/get-cart-products')); 200 return promise.then(function (response) { return response; }); 201 }, 202 203 updateTotals: function() { 204 var total = 0; 205 var i = 0; 206 207 var processedProducts = []; 208 209 jQuery('.plr-pub-shopping-cart-side-product').each(function() { 210 var productRow = jQuery(this); 211 var uuid = productRow.data('uuid'); 212 if (processedProducts.indexOf(uuid) == -1) { 213 var amount = parseFloat(productRow.data('amount')); 214 total += amount; 215 216 console.log('Sidebar cart adding up ' + (++i) + ' ' + amount); 217
218 processedProducts.push(uuid); 219 220 console.log('Processed products: ' + JSON.stringify(processedProducts)); 221 } 222 }); 223 224 jQuery('.plr-pub-shopping-cart-side-total-amount').html(total.toFixed(2)); 225 jQuery('.plr-pub-shopping-cart-total-amount').html(total.toFixed(2)); 226 }, 227 228}; 229jQuery(document).ready(function() { 230 PlrPubCart.init(); 231}); 232 233var PlrPubSideCart = { 234 235 cartEmptyLabel: 'Your cart is empty. Shop now', 236 checkoutNowLabel: 'Checkout now', 237 238 show: function (reload) { 239 240 var sideCart = jQuery('#plr-pub-shopping-cart-side'); 241 if (sideCart) { 242 window.setTimeout(function() { 243 sideCart.css("transform", "translateX(0%)"); 244 jQuery('body').append('<div class="modal-backdrop show"></div>') 245 .css('overflow', 'hidden'); 246 var bd = jQuery('.modal-backdrop'); 247 248 if(bd) { 249 bd.css('z-index', '1'); 250 bd.on('click', function() { PlrPubSideCart.hide(); }); 251 } 252 253 }, 100); 254 255 if (reload) { 256 PlrPubCart.getCartProducts().done(function(response) { 257 PlrPubSideCart.addProducts(response.value); 258 PlrPubCart.initActions(); 259 PlrPubSideCart.init(); 260 }); 261 } 262 } 263 }, 264 265 hide: function () { 266 267 var sideCart = jQuery('#plr-pub-shopping-cart-side'); 268 if (sideCart) { 269 sideCart.css("transform", "translateX(100%)"); 270 jQuery('body').css('overflow', 'initial'); 271 jQuery('.modal-backdrop').remove(); 272 273 } 274 }, 275 276 init: function() { 277 278 this.checkIsEmpty(); 279 280 jQuery('.plr-pub-shopping-cart-side-product-link').unbind(); 281 jQuery('.plr-pub-shopping-cart-side-product-link').on('click', function() { 282 var href = jQuery(this).attr('href'); 283 document.location = href; 284 return false; 285 }); 286 287 jQuery('.plr-pub-shopping-cart-checkout-button').on('click', function() { 288 var href = jQuery(this).attr('href'); 289 document.location = href; 290 return false; 291 }); 292 293 }, 294 295 addProducts: function(products) { 296 297 var html = ''; 298 for(var uuid in products) { 299 var product = products[uuid]; 300 301 html += '<div class="plr-pub-shopping-cart-side-product" data-uuid="' + uuid + '" data-amount="' + product.cart_item.p + '">' + 302 ' <div class="plr-pub-cart-item-container">' + 303 ' <div class="plr-pub-cart-item-image">' + 304 ' <a' + 305 ' href="' + product.url + '" class="plr-pub-shopping-cart-side-product-link">' + 306 ' <img width="300" height="305"' + 307 ' src="' + product.image_url + '"' + 308 ' alt="">' + 309 ' </a>' + 310 ' </div>' + 311 ' <div class="plr-pub-cart-item-product">' + 312 ' <div class="plr-pub-cart-item-details">' + 313 ' <div class="plr-pub-cart-item-product-name">' + 314 ' <div class="plr-pub-cart-item-product-link">' + 315 ' <a' + 316 ' href="' + product.url + '" class="plr-pub-shopping-cart-side-product-link">' + product.title + '</a>' + 317 ' </div>' + 318 ' </div>' + 319 ' </div>' + 320 ' </div>' + 321 ' </div>' + 322 ' <div class="plr-pub-cart-item-actions">' + 323 ' <button aria-label="Remove Item From Cart"' + 324 ' class="plr-pub-cart-item-actions-remove"' + 325 ' data-uuid="' + uuid + '">' + 326 ' <svg xmlns="http://www.w3.org/2000/svg"' +
327 ' viewBox="0 0 512.001 512.001">' + 328 ' <defs></defs>' + 329 ' <path d="M512.001 84.853L427.148 0 256.001 171.147 84.853 0 0 84.853 171.148 256 0 427.148l84.853 84.853 171.148-171.147 171.147 171.147 84.853-84.853L340.853 256z"></path>' + 330 ' </svg>' + 331 ' </button>' + 332 ' <div class="plr-pub-cart-item-actions-pricing">' + 333 ' <div class="plr-pub-cart-item-price">' + 334 ' ' + product.cart_item.p + 335 ' </div>' + 336 ' </div>' + 337 '</div>' + 338 '<div class="plr-pub-cart-item-loading d-none">' + 339 ' <div class="plr-pub-cart-item-spinner"></div>' + 340 '</div>' + 341 '</div>'; 342 343 344 } 345 346 jQuery('.plr-pub-shopping-cart-side-products-container').html(html); 347 348 this.updateTotals(); 349 }, 350 351 updateTotals: function() { 352 var total = 0; 353 var i = 0; 354 355 var processedProducts = []; 356 jQuery('.plr-pub-shopping-cart-side-product').each(function() { 357 358 var productRow = jQuery(this); 359 var uuid = productRow.data('uuid'); 360 if (processedProducts.indexOf(uuid) == -1) { 361 362 var amount = parseFloat(productRow.data('amount')); 363 total += amount; 364 365 console.log('Sidebar cart adding up ' + (++i) + ' ' + amount); 366 367 processedProducts.push(uuid); 368 369 console.log('Processed products: ' + JSON.stringify(processedProducts)); 370 } 371 }); 372 jQuery('.plr-pub-shopping-cart-side-total-amount').html(total.toFixed(2)); 373 }, 374 375 checkIsEmpty: function() { 376 if (jQuery('.plr-pub-shopping-cart-side-product').length == 0) { 377 378 jQuery('.plr-pub-shopping-cart-side-empty').removeClass('d-none'); 379 jQuery('.plr-pub-shopping-cart-side-total-container').addClass('d-none'); 380 jQuery('.plr-pub-shopping-cart-checkout-button') 381 .html(this.cartEmptyLabel) 382 .attr('href', PlrPubCommon.buildUrl('/')); 383 384 } else { 385 386 jQuery('.plr-pub-shopping-cart-side-empty').addClass('d-none'); 387 jQuery('.plr-pub-shopping-cart-side-total-container').removeClass('d-none'); 388 jQuery('.plr-pub-shopping-cart-checkout-button') 389 .html(this.checkoutNowLabel) 390 .attr('href', PlrPubCommon.buildUrl('/checkout/')); 391 392 } 393 }, 394 395}; 396 397function getWishlistProductUuids() { 398 return typeof(wishlistProductUuids) != 'undefined' ? wishlistProductUuids : []; 399} 400 401var PlrPubWishlist = { 402 403 init: function () { 404 405 jQuery.ajax(PlrPubCommon.buildUrl('/mshops/wishlist/get-products-count')) 406 .done(function (response) { 407 if (!response.value.errors) { 408 PlrPubWishlist.refreshCounts(response.value.count); 409 } 410 }); 411 412 jQuery('.plr-pub-add-to-wishlist').each(function() { 413 414 var button = jQuery(this); 415 416 var uuid = button.data('product-uuid'); 417 if (getWishlistProductUuids().indexOf(uuid) != -1) { 418 button.find('.plr-pub-add-to-wishlist-text').addClass('d-none'); 419 button.find('.plr-pub-add-to-wishlist-icon').addClass('d-none'); 420 421 button.find('.plr-pub-already-in-wishlist-text').removeClass('d-none'); 422 button.find('.plr-pub-already-in-wishlist-icon').removeClass('d-none'); 423 } 424 }); 425 426 jQuery('.plr-pub-add-to-wishlist').off('click', this.addToWishlistOnClick); 427 jQuery('.plr-pub-add-to-wishlist').on('click', this.addToWishlistOnClick); 428 429 }, 430 431 addToWishlistOnClick: function (event) { 432 event.preventDefault(); 433 434 var button = jQuery(this); 435 436 var uuid = button.data('product-uuid'); 437 if (uuid) { 438 439 button.addClass('plr-pub-pulse'); 440 441 jQuery('.plr-pub-add-to-wishlist-header-button').addClass('plr-pub-pulse'); 442 443 PlrPubWishlist.add(uuid) 444 .done(function (response) { 445 console.log('Got response:', response); 446 if (response.value.count > 0) { 447 jQuery('button.plr-pub-add-to-wishlist[data-product-uuid="' + uuid + '"] .plr-pub-add-to-wishlist-text').addClass('d-none'); 448 jQuery('button.plr-pub-add-to-wishlist[data-product-uuid="' + uuid + '"] .plr-pub-add-to-wishlist-icon').addClass('d-none'); 449 450 jQuery('button.plr-pub-add-to-wishlist[data-product-uuid="' + uuid + '"] .plr-pub-added-to-wishlist-text').removeClass('d-none');
451 jQuery('button.plr-pub-add-to-wishlist[data-product-uuid="' + uuid + '"] .plr-pub-added-to-wishlist-icon').removeClass('d-none'); 452 } 453 }) 454 .always(function () { 455 button.removeClass('plr-pub-pulse'); 456 }); 457 458 } 459 }, 460 461 add: function (uuid) { 462 463 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/wishlist/add-product?uuid=' + uuid)) 464 .error(function (response) { 465 console.error(response); 466 }) 467 .done(function (response) { 468 469 if (!response.value.errors) { 470 PlrPubWishlist.refreshCounts(response.value.count); 471 472 if (getWishlistProductUuids().indexOf(uuid) == -1) { 473 getWishlistProductUuids().push(uuid); 474 } 475 } 476 477 }); 478 479 return promise.then(function (response) { return response; }); 480 }, 481 482 remove: function (uuid) { 483 484 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/wishlist/remove-product?uuid=' + uuid)) 485 .error(function (response) { 486 console.error(response); 487 }) 488 .done(function (response) { 489 490 if (!response.value.errors) { 491 PlrPubWishlist.refreshCounts(response.value.count); 492 493 var index = getWishlistProductUuids().indexOf(uuid); 494 if (index != -1) { 495 getWishlistProductUuids().splice(index, 1); 496 } 497 } 498 499 }); 500 501 return promise.then(function (response) { return response; }); 502 }, 503 504 removeProducts: function (productUuids) { 505 506 var promise = jQuery.ajax(PlrPubCommon.buildUrl('/mshops/wishlist/remove-products?uuids=' + productUuids.join(','))) 507 .error(function (response) { 508 console.error(response); 509 }) 510 .done(function (response) { 511 512 if (!response.value.errors) { 513 PlrPubWishlist.refreshCounts(response.value.count); 514 515 for (var i = 0; i < productUuids.length; i++) { 516 var uuid = productUuids[i]; 517 var index = getWishlistProductUuids().indexOf(uuid); 518 if (index != -1) { 519 getWishlistProductUuids().splice(index, 1); 520 } 521 } 522 523 } 524 525 }); 526 527 return promise.then(function (response) { return response; }); 528 529 }, 530 531 addProductsToCart: function(productUuids, wishlistCode = null) { 532 533 var url = PlrPubCommon.buildUrl('/mshops/wishlist/add-products-to-cart?uuids=' + productUuids.join(',')); 534 if (wishlistCode) { 535 url += '&code=' + encodeURIComponent(wishlistCode); 536 } 537 var promise = jQuery.ajax(url) 538 .error(function(response) { 539 console.error(response); 540 }) 541 .done(function(response) { 542 console.log('Got add to cart response: ', response); 543 PlrPubCart.refreshCounts(response.value.items); 544 }); 545 546 return promise.then(function (response) { return response; }); 547 }, 548 549 refreshCounts: function (count) { 550 if (count > -1) { 551 if (jQuery('.plr-pub-wishlist-counter span.wishlist-counter').length == 0) { 552 var html = jQuery('.plr-pub-wishlist-counter').html(); 553 html += ' <span class="wishlist-counter"></span>'; 554 jQuery('.plr-pub-wishlist-counter').html(html); 555 } 556 557 var html = count > 0 ? ('(' + count + ')') : ''; 558 jQuery('.plr-pub-wishlist-counter span.wishlist-counter').html(html); 559 } 560 }, 561 562}; 563jQuery(document).ready(function() {
564 PlrPubWishlist.init(); 565}); 566 567var PlrPubListing = { 568 569 listingUuid: null, 570 ajaxLoadUrl: null, 571 orderBy: null, 572 page: 1, 573 filter: [], 574 tag: null, 575 search: null, 576 577 isOnListingPage: function() { 578 return jQuery('.plr-pub-product-listing').length; 579 }, 580 581 setListingUuid: function(listingUuid) { 582 this.listingUuid = listingUuid; 583 return this; 584 }, 585 586 setAjaxLoadUrl: function(ajaxLoadUrl) { 587 this.ajaxLoadUrl = ajaxLoadUrl; 588 return this; 589 }, 590 591 setOrderBy: function(orderBy) { 592 this.orderBy = orderBy; 593 return this; 594 }, 595 596 setPage: function(page) { 597 this.page = page; 598 return this; 599 }, 600 601 addFilter: function(name, value, allowMultiple = true) { 602 603 if (!allowMultiple) { 604 this.filter[name] = value; 605 } else { 606 var values = this.filter[name] || []; 607 if (!values.includes(value)) { 608 values.push(value); 609 this.filter[name] = values; 610 } 611 } 612 this.page = 1; 613 614 return this; 615 }, 616 617 removeFilter: function(name, value) { 618 619 this.page = 1; 620 621 var values = this.filter[name] || []; 622 var index = values.indexOf(value); 623 if (index != -1) { 624 values.splice(index, 1); 625 this.filter[name] = values; 626 } 627 628 return this; 629 }, 630 631 setFilter: function(filter) { 632 this.filter = filter; 633 this.page = 1; 634 return this; 635 }, 636 637 setTag: function(tag) { 638 this.tag = tag; 639 this.page = 1; 640 return this; 641 }, 642 643 resetFilter: function() { 644 this.filter = []; 645 this.page = 1; 646 return this; 647 }, 648 649 setSearch: function(search) { 650 this.search = search; 651 this.page = 1; 652 return this; 653 }, 654 655 init: function() { 656 657 console.log('Initializing products listing view...'); 658 659 jQuery(document).ready(function() { 660 PlrPubCommon.lazyReload(); 661 }); 662 663 window.addEventListener('load', function() { 664 console.log("Page is fully loaded"); 665 PlrPubCommon.lazyReload(); 666 }); 667 668 PlrPubCommon.lazyReload(); 669 670 jQuery('.plr-pub-add-to-wishlist').each(function() { 671 var button = jQuery(this); 672 673 var uuid = button.data('product-uuid'); 674 if (getWishlistProductUuids().indexOf(uuid) != -1) { 675 button.addClass('inited-add-wishlist'); 676 } 677 }); 678 679 jQuery('.plr-pub-add-to-cart').on('click', function() { 680 var button = jQuery(this); 681 682 var uuid = button.data('product-uuid'); 683 if (uuid) { 684 685 button.addClass('loading'); 686 687 PlrPubCart.add(uuid) 688 .done(function(response) { 689 690 if (response.value.errors) { 691 692 var error = '<div class="plr-pub-error" role="alert">' + 693 response.value.errors[0] 694 '</div>'; 695 696 jQuery('.plr-pub-notices-wrapper').html(error); 697 698 } 699 700 }) 701 .always(function() { 702 button.removeClass('loading'); 703 }); 704 705 } 706 }); 707 708 jQuery('#plr-pub-listing-products-sort').on('change', function() { 709 var orderBy = jQuery(this).val(); 710 711 PlrPubListing 712 .setOrderBy(orderBy) 713 .load() 714 .done(function(response) { 715 jQuery('.plr-pub-listing-container').html(response.value.view); 716 717 PlrPubListing.init(); 718 }); 719 720 return false; 721 }); 722 723 jQuery('.plr-pub-listing-pagination .page-numbers').on('click', function() { 724 var page = jQuery(this).data('page'); 725 726 console.log('Loading page', page); 727 728 PlrPubListing 729 .setPage(page) 730 .load() 731 .done(function() { 732 733 }); 734 735 return false; 736 }); 737 738 739
740 PlrPubWishlist.init(); 741 742 }, 743 744 load: function() { 745 746 var url = this.ajaxLoadUrl; 747 748 var urlSearchParams = new URLSearchParams(document.location.search); 749 750 var queryString = ''; 751 var delimiter = ''; 752 753 if (this.orderBy) { 754 755 var orderByParam = '_order_by'; 756 if (plr_pub_data.listing_pagination_mode == 'per-listing') { 757 orderByParam += '_' + this.listingUuid; 758 } 759 760 queryString += delimiter + orderByParam + '=' + this.orderBy; 761 delimiter = '&'; 762 763 urlSearchParams.set(orderByParam, this.orderBy); 764 } 765 766 if (this.page && this.page > 1) { 767 768 var pageParam = '_page'; 769 if (plr_pub_data.listing_pagination_mode == 'per-listing') { 770 pageParam += '_' + this.listingUuid; 771 } 772 773 queryString += delimiter + pageParam + '=' + this.page; 774 delimiter = '&'; 775 776 urlSearchParams.set(pageParam, this.page); 777 778 } else { 779 780 urlSearchParams.delete('_page'); 781 782 } 783 784 var filterQuery = ''; 785 786 if (Object.keys(this.filter).length > 0 ) { 787 788 var filterDelimiter = ''; 789 for (var name in this.filter) { 790 var value = this.filter[name]; 791 792 console.log("Building query for filter " + name + " => ", value); 793 794 if (Array.isArray(value)) { 795 796 for (var i = 0; i < value.length; i++) { 797 var val = value[i]; 798 799 filterQuery += filterDelimiter + name + '[]=' + val; 800 filterDelimiter = '&'; 801 } 802 803 } else { 804 filterQuery += filterDelimiter + name + '=' + value; 805 filterDelimiter = '&'; 806 } 807 808 } 809 810 } 811 812 var filterParam = '_filter'; 813 if (plr_pub_data.listing_pagination_mode == 'per-listing') { 814 filterParam += '_' + this.listingUuid; 815 } 816 817 if (filterQuery.length > 0) { 818 queryString += delimiter + filterParam + '=' + encodeURIComponent(filterQuery); 819 delimiter = '&'; 820 821 urlSearchParams.set(filterParam, encodeURIComponent(filterQuery)); 822 } else { 823 urlSearchParams.delete(filterParam); 824 } 825 826 if (this.search) { 827 queryString += delimiter + 's=' + encodeURIComponent(this.search); 828 delimiter = '&'; 829 830 urlSearchParams.set('s', encodeURIComponent(this.search)); 831 } 832 833 url += '&' + urlSearchParams.toString(); 834 835 if (this.tag) { 836 url += '&_tag=' + encodeURIComponent(this.tag); 837 } 838 839 console.log(urlSearchParams.toString()); 840 841 var searchParams = urlSearchParams.toString(); 842 var currentPath = window.location.pathname; 843 var pageUrl = searchParams ? (currentPath + '?' + searchParams) : currentPath; 844 window.history.pushState('', '', pageUrl); 845 846 jQuery('.plr-pub-listing-container-loader').removeClass('d-none'); 847 848 var promise = jQuery.ajax(url) 849 .error(function(response) { 850 console.error(response); 851 }) 852 .done(function(response) { 853 console.log(response); 854 855 var dom = jQuery(response.value.view); 856 var html = dom.find('.plr-pub-listing-container').html(); 857 jQuery('.plr-pub-listing-container').html(html); 858 859 PlrPubListing.init(); 860 861 jQuery('html, body').animate({ 862 scrollTop: jQuery(".plr-pub-listing-container").offset().top - 150 863 }, 500); 864 }) 865 .always(function() { 866 jQuery('.plr-pub-listing-container-loader').addClass('d-none'); 867 }); 868 869 return promise.then(function (response) { return response; }); 870 871 }, 872 873}; 874 875var PlrPubQuickView = { 876 877 init: function() { 878 879 jQuery('.plr-pub-product-quick-view-button').on('click', function() { 880 881 var uuid = jQuery(this).data('product-uuid'); 882 883 var url = PlrPubCommon.buildUrl('/mshops/product/render-quick-view?product_uuid=' + uuid); 884 885 jQuery.ajax(url) 886 .error(function(response) { 887 console.error(response); 888 }) 889 .done(function(response) { 890 console.log(response); 891 892 var modal = jQuery('#yith-quick-view-modal'); 893 modal.addClass('open'); 894 895 jQuery('#yith-quick-view-content').html(response.value.html); 896 897 jQuery('#yith-quick-view-modal .plr-pub-add-to-cart').on('click', function() { 898 var button = jQuery(this); 899 900 var uuid = button.data('product-uuid'); 901 if (uuid) { 902 903 button.addClass('loading'); 904 905 PlrPubCart.add(uuid) 906 .done(function(response) { 907 908 if (response.value.errors) { 909 910 var error = '<div class="plr-pub-error" role="alert">
910' + 911 response.value.errors[0] 912 '</div>'; 913 914 jQuery('.plr-pub-notices-wrapper').html(error); 915 916 } 917 918 }) 919 .always(function() { 920 button.removeClass('loading'); 921 922 modal.removeClass('open'); 923 }); 924 925 } 926 }); 927 928 }); 929 930 }); 931 932 }, 933 934}; 935 936var PlrPubModals = { 937 938 init: function() { 939 jQuery('.plr-pub-modal').on('click', function (e) { 940 var target = jQuery(e.target); 941 if (target.hasClass('plr-pub-modal')) { 942 $(this).hide(); 943 } 944 }); 945 jQuery('.plr-pub-modal-close').on('click', function () { 946 jQuery(this).closest('.plr-pub-modal').hide(); 947 }); 948 } 949} 950 951PlrPubModals.init(); 952 953var PlrPubAdvancedSearch = { 954 955 init: function() { 956 957 jQuery('.plr-pub-advanced-search-form').on('submit', function (event) { 958 /* 959 event.preventDefault(); 960 961 var form = jQuery(this); 962 var id = form.attr('id'); 963 964 var searchExact = jQuery('[name=s]', '#' + id).val(); 965 var searchAll = jQuery('[name=_search_all]', '#' + id).val(); 966 var searchAny = jQuery('[name=_search_any]', '#' + id).val(); 967 var searchNone = jQuery('[name=_search_none]', '#' + id).val(); 968 969 console.log('searchExact', searchExact); 970 console.log('searchAll', searchAll); 971 console.log('searchAny', searchAny); 972 console.log('searchNone', searchNone); 973 974 var category = jQuery('[name=_category\\[\\]]', '#' + id).val(); 975 var period = jQuery('[name=_period]', '#' + id).val(); 976 var yearFrom = jQuery('[name=_year_from]', '#' + id).val(); 977 var monthFrom = jQuery('[name=_month_from]', '#' + id).val(); 978 var dayFrom = jQuery('[name=_day_from]', '#' + id).val();
979 var yearTo = jQuery('[name=_year_to]', '#' + id).val(); 980 var monthTo = jQuery('[name=_month_to]', '#' + id).val(); 981 var dayTo = jQuery('[name=_day_to]', '#' + id).val(); 982 983 console.log('category', category); 984 console.log('period', period); 985 console.log('yearFrom', yearFrom); 986 console.log('monthFrom', monthFrom); 987 console.log('dayFrom', dayFrom); 988 console.log('yearTo', yearTo); 989 console.log('monthTo', monthTo); 990 console.log('dayTo', dayTo); 991 992 var searchInTitle = jQuery('[name=_sit]', '#' + id).is(':checked'); 993 console.log('searchInTitle', searchInTitle); 994 var searchInDescription = jQuery('[name=_sid]', '#' + id).is(':checked'); 995 console.log('searchInDescription', searchInDescription); 996 997 var termIds = []; 998 jQuery('[name=_term\\[\\]]:checked', '#' + id).each(function () { 999 termIds.push(jQuery(this).val()); 1000 }); 1001 console.log('termIds', termIds); 1002 1003 return false; 1004 */ 1005 1006 1007 event.preventDefault(); 1008 1009 var form = jQuery(this); 1010 var id = form.attr('id'); 1011 1012 var params = [/*'s', */'_search_all', '_search_any', '_search_none', '_category\\[\\]', '_period', 1013 '_year_from', '_month_from', '_day_from', '_year_to', '_month_to', '_day_to', '_sit', '_sid', '_term\\[\\]']; 1014 1015 params.forEach(function(param) { 1016 var input = jQuery('[name=' + param + ']', '#' + id); 1017 if (!input.val()) { 1018 input.prop('disabled', true); 1019 } 1020 }); 1021 1022 form.off('submit').submit(); 1023 }); 1024 1025 }, 1026 1027}; 1028 1029PlrPubAdvancedSearch.init(); 1030 1031var PlrPubPreview = { 1032 1033 check: function(productUuid) { 1034 1035 var url = PlrPubCommon.buildUrl('/mshops/check-preview?uuid=' + productUuid + '&r=' + Math.random()); 1036 jQuery.ajax(url) 1037 .error(function(response) { 1038 if (response.responseText) { 1039 1040 try { 1041 var resp = JSON.parse(response.responseText); 1042 switch (resp.code) { 1043 case 401: 1044 //login 1045 jQuery('.plr-pub-preview-login-message').removeClass('d-none'); 1046 jQuery('.plr-pub-product-preview-panel').addClass('d-none') 1047 break; 1048 case 403: 1049 //purchase subscription 1050 jQuery('.plr-pub-preview-subscription-message').removeClass('d-none'); 1051 jQuery('.plr-pub-product-preview-panel').addClass('d-none') 1052 break; 1053 case 500: 1054 jQuery('.plr-pub-preview-system-error-message').removeClass('d-none'); 1055 jQuery('.plr-pub-product-preview-panel').addClass('d-none') 1056 break; 1057 } 1058 } catch(e) { 1059 console.error(e); 1060 jQuery('.plr-pub-preview-system-error-message').removeClass('d-none'); 1061 jQuery('.plr-pub-product-preview-panel').addClass('d-none') 1062 } 1063 1064 } 1065 1066 }) 1067 .done(function(response) { 1068 1069 jQuery('.plr-pub-product-preview-panel').removeClass('d-none'); 1070 jQuery('.plr-pub-preview-login-message').addClass('d-none'); 1071 1072 }) 1073 .always(function(response) { 1074 response = response.responseText ? JSON.parse(response.responseText) : response; 1075 if (response.free_preview_message) { 1076 jQuery('.plr-pub-product-free-previews-notice').html(response.free_preview_message); 1077 } 1078 jQuery('.plr-pub-preview-loader').addClass('d-none'); 1079 1080 /* Always show modal if the preview panel display-mode is "modal" */ 1081 var modal = jQuery('.plr-pub-product-preview-modal'); 1082 modal.appendTo('body').show(); 1083 }); 1084 1085 }, 1086 1087}; 1088 1089PlrPubCommon.init();
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.