1(function ($) { 2 'use strict'; 3 4 var zeomart = zeomart || {}; 5 zeomart.init = function () { 6 zeomart.$body = $(document.body), 7 zeomart.$window = $(window), 8 zeomart.$header = $('#site-header'); 9 10 this.headerProductSearch(); 11 this.searchNavAttributes(); 12 this.shopView(); 13 this.WidgetToggle(); 14 this.WidgetCollapse(); 15 this.AjaxFilter(); 16 this.widgetSMSL(); 17 this.addToCartBundles(); 18 this.addToCartAjax(); 19 this.CartOpenPopup(); 20 this.miniCartQuantity(); 21 this.ProductCustomQuantity(); 22 this.updateCartFragments(); 23 this.filterPopup(); 24 this.WoocommerceLoginForm(); 25 this.VendorProductSearch(); 26 this.buyNowButton(); 27 this.viewMoreToggle(); 28 this.productGallery(); 29 this.openPopup(); 30 this.productQuickView(); 31 this.ClosePopup(); 32 // this.moveContentAfterGallery(); 33 }; 34 35 zeomart.moveContentAfterGallery = function() { 36 37 if ( $('body.single-product') && $('.zeomart-single-product').hasClass('zeomart-product-layout-style-4') ) { 38 console.log('test'); 39 } 40 }; 41 42 zeomart.viewMoreToggle = function() { 43 44 const $viewMoreBtn = $('.zeomart-product-detail #view-more-btn'); 45 const $hideMoreBtn = $('.zeomart-product-detail #hide-more-btn'); 46 const $tableRowElements = $('.zeomart-product-detail .woocommerce-product-attributes-item'); 47 const $additionalTableRows = $('.zeomart-product-detail .woocommerce-product-attributes-item.hidden'); 48 49 // Hide additional table rows 50 $additionalTableRows.hide(); 51 52 // Show "View More" button if there are additional items 53 if ($additionalTableRows.length > 0) { 54 $viewMoreBtn.removeClass('hide'); 55 } 56 57 // Show additional table rows and hide "View More" button 58 $viewMoreBtn.click(function() { 59 $additionalTableRows.show(); 60 $viewMoreBtn.hide(); 61 $hideMoreBtn.show(); 62 }); 63 64 // Hide additional table rows and show "View More" button 65 $hideMoreBtn.click(function() { 66 $additionalTableRows.hide(); 67 $viewMoreBtn.show(); 68 $hideMoreBtn.hide(); 69 }); 70 }; 71 72 zeomart.productGallery = function () { 73 var $images = $('.woocommerce-product-gallery'); 74 75 if (!$images.length) { 76 return; 77 } 78 79 $images.find('.woocommerce-product-gallery__image').on('mouseenter', function () { 80 $(this).closest('.woocommerce-product-gallery').find('.ms-image-view').removeClass('hide'); 81 $(this).closest('.woocommerce-product-gallery').find('.ms-image-zoom').addClass('hide'); 82 }); 83 84 $images.find('.woocommerce-product-gallery__image').on('mouseleave', function () { 85 $(this).closest('.woocommerce-product-gallery').find('.ms-image-view').addClass('hide'); 86 $(this).closest('.woocommerce-product-gallery').find('.ms-image-zoom').removeClass('hide'); 87 }); 88 }; 89 90 zeomart.openPopup = function() { 91 jQuery('.zeomart-popup-link').on('click', function(e) { 92 e.preventDefault(); 93 var $modal_id = jQuery(this).attr('id'); 94 if ( ! $modal_id ) { 95 return; 96 } 97 98 var $content_wrapper = jQuery( '.zeomart-popup-wrapper'+'#'+$modal_id ); 99 if ( ! $content_wrapper ) { 100 return; 101 } 102 103 $content_wrapper.addClass('active'); 104 jQuery('body').addClass('zm-popup-active'); 105 zeomart.ClosePopup(); 106 }); 107 }; 108 109 zeomart.ClosePopup = function() { 110 111 $(document).on('click', function( event ) { 112 var target = $( event.target ); 113 if ( target.hasClass('zm-popup-active') ) { 114 jQuery('.zeomart-popup-wrapper.active .close-popup').trigger('click'); 115 } 116 }); 117 118 jQuery('.zeomart-popup-close .close-popup').on('click', function(e) { 119 jQuery('.zeomart-popup-wrapper').removeClass('active'); 120 jQuery('body').removeClass('zm-popup-active'); 121 }); 122 }; 123 124 zeomart.productChangeView = function() { 125 var currentView = 'grid'; 126 $('.zeomart-catalog-view-wrapper a').click(function(e) { 127 e.preventDefault(); 128 129 // Get the new view 130 var newView = $(this).hasClass('grid-view') ? 'grid' : 'list'; 131 132 // Don't do anything if we're already on the selected view 133 if (newView === currentView) { 134 return; 135 } 136 137 // Update the active class 138 $('.zeomart-catalog-view-wrapper a').removeClass('active'); 139 $(this).addClass('active'); 140 141 // Load products for the new view 142 zeomart.loadProducts(newView); 143 144 // Update current view 145 currentView = newView; 146 }); 147 }; 148 149 zeomart.loadProducts = function(view) { 150 var data = { 151 action: 'zm_load_products', 152 view: view, 153 }; 154 155 $.post(zeomartJsData.ajax_url, data, function(response) { 156 $('.zeomart-shop-content').html(response); 157 }); 158 }; 159 160 zeomart.productQuickView = function() { 161 162 var $modal = $('#zm-quick-view-modal'), 163 $product = $modal.find('.product-modal-content'); 164 165 zeomart.$body.on('click', '.gdlr-core-product-quick-view', function (e) { 166 e.preventDefault(); 167 168 var $a = $(this), 169 id = $a.data('id'); 170 171 $product.hide().html(''); 172 $modal.addClass('loading').removeClass('loaded'); 173 174 $modal.addClass('active'); 175 zeomart.$body.addClass('zm-popup-active'); 176 zeomart.closepopup(); 177 178 var data = { 179 nonce: zeomartJsData.nonce, 180 product_id: id 181 }, 182 ajax_url = zeomartJsData.wc_ajax_url.toString().replace('%%endpoint%%', 'zeomart_product_quick_view'); 183 184 $.post( 185 ajax_url, 186 data, 187 function (response) { 188 $product.show().append(response.data); 189 $modal.removeClass('loading').addClass('loaded'); 190 var $gallery = $product.find('.woocommerce-product-gallery'), 191 $variation = $('.variations_form'), 192 $buttons = $product.find('form.cart .actions-button'), 193 $buy_now = $buttons.find('.buy_now_button'); 194 195 $gallery.removeAttr('style'); 196 197 if ($buy_now.length > 0) { 198 $buttons.prepend($buy_now); 199 } 200 201 $gallery.find('.woocommerce-product-gallery__image').on('click', function (e) { 202 e.preventDefault(); 203 }); 204 205 if (typeof wc_add_to_cart_variation_params !== 'undefined') { 206 $variation.each(function () { 207 $(this).wc_variation_form(); 208 }); 209 } 210 211 if (typeof $.fn.tawcvs_variation_swatches_form !== 'undefined') { 212 $variation.tawcvs_variation_swatches_form(); 213 } 214 215 zeomart.buyNowButton(); 216 zeomart.addToCartAjax(); 217 $(document.body).trigger('yith_wcwl_init'); 218 $( document.body ).trigger( 'init_variation_swatches'); 219 } 220 ); 221 }); 222 223 $('.zeomart-popup-wrapper .close-popup').on('click', function(e) { 224 e.preventDefault(); 225 $modal.removeClass('active'); 226 zeomart.$body.removeClass('zm-popup-active'); 227 }); 228 229 zeomart.ClosePopup(); 230 }; 231 232 zeomart.headerProductSearch = function () { 233 234 var xhr = null, 235 searchResult = {}, 236 $form = zeomart.$body.find('form.gdlr-zeomart-products-search'); 237 238 $form.on('keyup', '.search-field', function (e) { 239 var is_valid = false; 240 241 if ( typeof e.which == 'undefined' ) { 242 is_valid = true; 243 } else if ( typeof e.which == 'number' && e.which > 0 ) { 244 is_valid = ! e.ctrlKey && ! e.metaKey && ! e.altKey; 245 } 246 247 if ( ! is_valid ) { 248 return; 249 } 250 251 if ( xhr ) { 252 xhr.abort(); 253 } 254 255 var $searchForm = $(this).closest('.gdlr-zeomart-products-search'), 256 $search = $searchForm.find('input.search-field'); 257 258 if ($search.val().length < 2) { 259 $searchForm.removeClass('searching actived'); 260 } 261 262 Header_Ajax_Search($searchForm); 263 }).on('change', '#gdlr-zeomart-header-search-categories', function () { 264 if (xhr) { 265 xhr.abort(); 266 } 267 268 var $searchForm = $(this).closest('.gdlr-zeomart-products-search'); 269 270 Header_Ajax_Search($searchForm); 271 }).on('focusout', '.search-field', function () { 272 var $searchForm = $(this).closest('.gdlr-zeomart-products-search'), 273 $search = $searchForm.find('input.search-field'); 274 if ($search.val().length < 2) { 275 $searchForm.removeClass('searching actived'); 276 } 277 }).on('click', function() { 278 if ( $(this).hasClass( 'found-products' ) ) { 279 $(this).addClass('actived'); 280 } 281 }); 282 283 $(document).on('click', function (e) { 284 if (!$form.hasClass('actived')) { 285 return; 286 } 287 var target = e.target; 288 289 if ($(target).closest('.gdlr-zeomart-products-search').length < 1) { 290 $form.removeClass('searching actived'); 291 } 292 }); 293 294 function Header_Ajax_Search($searchForm) { 295 var $search = $searchForm.find('input.search-field'), 296 keyword = $search.val(), 297 cat = 0, 298 $results = $searchForm.find('.search-results'); 299 300 if ($searchForm.find('#gdlr-zeomart-header-search-categories').length > 0) { 301 cat = $searchForm.find('#gdlr-zeomart-header-search-categories').val(); 302 } 303 304 if ( keyword.trim().length < 2 ) { 305 $searchForm.removeClass('searching').addClass(''); 306 return; 307 } 308 309 $searchForm.removeClass('').addClass('searching'); 310 311 var cat_key = keyword + cat; 312 313 if (cat_key in searchResult) { 314 var result = searchResult[cat_key]; 315 316 $searchForm.removeClass('searching'); 317 318 $searchForm.addClass('found-products'); 319 320 $results.html(result.products); 321 322 $(document.body).trigger('zeomart_ajax_search_request_success', [$results]); 323 324 $searchForm.removeClass(''); 325 326 $searchForm.addClass('actived'); 327 } else { 328 329 var data = { 330 'term': keyword, 331 'nonce': zeomartJsData.nonce, 332 'cat': cat, 333 'search_type': zeomartJsData.search_content_type 334 }, 335 ajax_url = zeomartJsData.wc_ajax_url.toString().replace('%%endpoint%%', 'zeomart_search_products'); 336 337 xhr = $.post( 338 ajax_url, 339 data, 340 function (response) { 341 var $products = response.data; 342 searchFormResult($searchForm, $results, $products, cat_key); 343 } 344 ); 345 } 346 } 347 348 function searchFormResult($searchForm, $results, $products, cat_key) { 349 $searchForm.removeClass('searching'); 350 351 $searchForm.addClass('found-products'); 352 353 $results.html($products); 354 355 $searchForm.removeClass(''); 356 357 $(document.body).trigger('zeomart_ajax_search_request_success', [$results]); 358 359 // Cache 360 searchResult[cat_key] = { 361 found: true, 362 products: $products 363 }; 364 365 $searchForm.addClass('actived'); 366 } 367 }; 368 369 zeomart.searchNavAttributes = function () { 370 var $widget = $('.zeomart-widget-layered-nav'); 371 372 if ( $widget.length < 1 ) { 373 return; 374 } 375 376 $widget.on('keyup', '.zeomart-input-search-nav', function (e) { 377 var find = false; 378 379 if ( typeof e.which == 'undefined' ) { 380 find = true; 381 } else if ( typeof e.which == 'number' && e.which > 0 ) { 382 find = ! e.ctrlKey && ! e.metaKey && !e.altKey; 383 } 384 385 if ( ! find ) { 386 return; 387 } 388 389 var val = $(this).val(); 390 391 if (typeof val === 'number') { 392 val = '' + val; 393 } 394 395 var filter = val.toUpperCase(), 396 widget = $(this).closest('.zeomart-widget-layered-nav'), 397 ul = widget.find('.woocommerce-widget-layered-nav-list'), 398 items = ul.children('.wc-layered-nav-term'); 399 400 items.each(function () { 401 var a = $(this).find('a').data('title'); 402 403 if (typeof a === 'number') { 404 a = '' + a; 405 } 406 407 a = a.toUpperCase(); 408 409 if (a.indexOf(filter) > -1) { 410 $(this).show(); 411 } else { 412 $(this).hide(); 413 } 414 }); 415 }); 416 }; 417 418 zeomart.shopView = function () { 419 420 if ( zeomart.$body && zeomart.$body.find( '.zeomart-catalog-view-wrapper' ).length ) { 421 // Do something with the elements 422 zeomart.$body.on('click', '.zeomart-catalog-view', function (e) { 423 e.preventDefault(); 424 var $el = $(this), 425 view = $el.data('view'); 426 427 if ($el.hasClass('active')) { 428 return; 429 } 430 431 zeomart.$body.find('.zeomart-catalog-view').removeClass('active'); 432 $el.addClass('active'); 433 zeomart.$body.removeClass('shop-view-grid shop-view-list').addClass('shop-view-' + view); 434 435 document.cookie = 'shop_view=' + view + ';domain=' + window.location.host + ';path=/'; 436 }); 437 } 438 }; 439 440 zeomart.TopSellingCarousel = function() { 441 var gdlr_core_custom = $('.zeomart-products-catalog-carousel .gdlr-core-js-custom'); 442 443 $.fn.zeomart_gdlr_core_flexslider( gdlr_core_custom ); 444 }; 445
446 zeomart.CategoriesCarousel = function() { 447 var gdlr_core_custom = $('.gdlr-categories-carousel'); 448 449 $.fn.zeomart_product_cat_flexslider( gdlr_core_custom ); 450 }; 451 452 zeomart.WidgetToggle = function(e) { 453 454 zeomart.$body.find('.zeomart-sidebar-area .sidebar-box.woocommerce .sidebar_heading, .zeomart-sticky-filter-popup .sidebar-box.woocommerce .sidebar_heading').each( function() { 455 var a = document.createElement("span"); 456 a.className = "widget-toggle-btn"; 457 this.appendChild(a); 458 }); 459 }; 460 461 zeomart.WidgetCollapse = function() { 462 zeomart.$body.on("click", ".zeomart-sidebar-area .sidebar-box.woocommerce .sidebar_heading, .zeomart-sticky-filter-popup .sidebar-box.woocommerce .sidebar_heading", (function(e) { 463 var target = jQuery(e.currentTarget); 464 465 var siblings = target.siblings("*:not(script):not(style)"); 466 target.addClass("sliding"); 467 468 siblings.slideToggle(300, (function() { 469 target.removeClass("sliding"); 470 } )); 471 472 target.toggleClass("collapsed"); 473 })); 474 }; 475 476 zeomart.VendorProductSearch = function () { 477 478 if ( ! zeomart.$body.hasClass( 'zeomart-wcfm-theme-template' ) ) { 479 return; 480 } 481 482 zeomart.$body.on('click', 'ul.woocommerce-ordering a:not(.zeomart-cancel-order)', function (e) { 483 e.preventDefault(); 484 var url = $(this).attr('href'); 485 $(document.body).trigger('zeomart_vendor_filter_ajax', url, $(this)); 486 }); 487 488 $(document.body).on('zeomart_vendor_filter_ajax', function (e, url, element) { 489 490 var $content = $('#products-wrapper'), 491 $pageBreadcurmbs = $('.woocommerce-breadcrumb'), 492 $headerTitle = $('head').find('title'); 493 494 NProgress.start(); 495 496 $('.zeomart-body-outer-wrapper').removeClass('fade-in'); 497 498 if ('?' == url.slice(-1)) { 499 url = url.slice(0, -1); 500 } 501 502 url = url.replace(/%2C/g, ','); 503 504 history.pushState(null, null, url); 505 506 $(document.body).trigger('ajax_filter_before_request', [url, element]);
507 508 if (zeomart.ajaxXHR) { 509 zeomart.ajaxXHR.abort(); 510 } 511 512 zeomart.ajaxXHR = $.get(url, function (res) { 513 $content.replaceWith($(res).find('#products-wrapper')); 514 515 $(document.body).trigger('zeomart_ajax_filter_request_success', [res, url]); 516 517 $(document.body).trigger('yith_wcwl_init'); 518 519 }, 'html'); 520 }); 521 522 }; 523 524 zeomart.filterPopup = function() { 525 var $sticky_popup = $('.zeomart-sticky-filter-popup'); 526 if ( ! $sticky_popup.length ) { 527 return; 528 } 529 530 zeomart.$body.on('click', '#zeomart-filter-mobile', function(e) { 531 e.preventDefault(); 532 $sticky_popup.addClass('active'); 533 zeomart.$body.addClass('zm-popup-active'); 534 }); 535 536 zeomart.ClosePopup(); 537 }; 538 539 zeomart.AjaxFilter = function () { 540 541 if ( ! zeomart.$body.hasClass( 'zeomart-catalog-ajax-filter' ) || zeomart.$body.hasClass( 'zeomart-wcfm-theme-template' ) ) { 542 return; 543 } 544 545 $(document.body).on('price_slider_change', function (event, ui) { 546 var form = $('.price_slider').closest('form').get(0), 547 $form = $(form), 548 url = $form.attr('action') + '?' + $form.serialize(); 549 550 $(document.body).trigger('zeomart_shop_filter_ajax', url, $(this)); 551 }); 552 553 zeomart.$body.on('click', '.zm_widget_product_categories a, .zeomart-widget-layered-nav a, .widget_rating_filter a, .widget_layered_nav_filters a, ul.woocommerce-ordering a:not(.zeomart-cancel-order)', function (e) { 554 e.preventDefault(); 555 var url = $(this).attr('href'); 556 $(this).parent('.wc-layered-nav-term').toggleClass('woocommerce-widget-layered-nav-list__item--chosen').toggleClass('chosen'); 557 558 $(document.body).trigger('zeomart_shop_filter_ajax', url, $(this)); 559 }); 560 561 $(document.body).on('zeomart_shop_filter_ajax', function (e, url, element) { 562 563 var $content = $('#zeomart-page-wrapper'), 564 $pageBreadcurmbs = $('.woocommerce-breadcrumb'), 565 $headerTitle = $('head').find('title'), 566 $loader = $('.zm-sticky-loader'); 567 568 $loader.addClass('zm-position-stick'); 569 $content.addClass('zm-ajax-loading'); 570 571 NProgress.start(); 572 573 if ('?' == url.slice(-1)) { 574 url = url.slice(0, -1); 575 } 576 577 url = url.replace(/%2C/g, ','); 578 579 history.pushState(null, null, url); 580 581 $(document.body).trigger('ajax_filter_before_request', [url, element]);
582 583 if (zeomart.ajaxXHR) { 584 zeomart.ajaxXHR.abort(); 585 } 586 587 zeomart.ajaxXHR = $.get(url, function (res) { 588 589 $content.replaceWith($(res).find('#zeomart-page-wrapper')); 590 $pageBreadcurmbs.html($(res).find('.woocommerce-breadcrumb').html()); 591 $headerTitle.html($(res).filter('title').text()); 592 593 $(document.body).trigger('zeomart_ajax_filter_request_success', [res, url]); 594 595 $(document.body).trigger('yith_wcwl_init'); 596 597 }, 'html'); 598 }); 599 600 $(document.body).on('zeomart_ajax_filter_request_success', function () { 601 zeomart.searchNavAttributes(); 602 zeomart.TopSellingCarousel(); 603 zeomart.WidgetToggle(); 604 zeomart.widgetSMSL(); 605 zeomart.CategoriesCarousel(); 606 NProgress.done(); 607 $('.zm-sticky-loader').removeClass('zm-position-stick'); 608 $('#zeomart-page-wrapper').removeClass('zm-ajax-loading'); 609 }); 610 }; 611 612 zeomart.buyNowButton = function () { 613 if ( ! zeomart.$body.find('.zeomart-page-wrapper .zeomart-has-buy-now') ) { 614 return; 615 } 616 617 zeomart.$body.find('form.cart').on('click', '.buy_now_button', function (e) { 618 e.preventDefault(); 619 var $form = $(this).closest('form.cart'), 620 is_disabled = $(this).is(':disabled'); 621 622 if (is_disabled) { 623 jQuery('html, body').animate({ 624 scrollTop: $(this).offset().top - 200 625 }, 900 626 ); 627 } else { 628 $form.append('<input type="hidden" value="true" name="buy_now" />'); 629 // $form.find('.single_add_to_cart_button').addClass('has-buy-now'); 630 $form.find('.single_add_to_cart_button').trigger('click'); 631 } 632 }); 633 var $variations_form = $('.variations_form'); 634 $variations_form.on('hide_variation', function (event) { 635 event.preventDefault(); 636 $variations_form.find('.buy_now_button').addClass('disabled wc-variation-selection-needed'); 637 }); 638 639 $variations_form.on('show_variation', function (event, variation, purchasable) { 640 event.preventDefault(); 641 if (purchasable) { 642 $variations_form.find('.buy_now_button').removeClass('disabled wc-variation-selection-needed'); 643 } else { 644 $variations_form.find('.buy_now_button').addClass('disabled wc-variation-selection-needed'); 645 } 646 }); 647 }; 648 649 zeomart.widgetSMSL = function () { 650 var $widget = $('.sidebar-box.widget_layered_nav'); 651 652 $widget.each( function() { 653 var $wrapper = $(this), 654 catNumbers = $wrapper.find('input.cat-numbers').val(); 655 if ( ! $wrapper.find('ul.woocommerce-widget-layered-nav-list').hasClass('has-view-more') ) { 656 return; 657 } 658 659 var count = $wrapper.find('ul.woocommerce-widget-layered-nav-list > li').size(); 660 661 if ( count > catNumbers ) { 662 $wrapper.find('.show-more').show(); 663 } 664 665 $wrapper.find('ul.woocommerce-widget-layered-nav-list > li:lt(' + catNumbers + ')').show(); 666 667 $(this).find('ul.woocommerce-widget-layered-nav-list > li').not(':lt(' + catNumbers + ')').hide(); 668 669 $wrapper.on('click', '.show-more', function () { 670 $wrapper.find('ul.woocommerce-widget-layered-nav-list > li').not(':lt(' + catNumbers + ')').show(); 671 $(this).hide(); 672 $wrapper.find('.show-less').show(); 673 }); 674 675 $wrapper.on('click', '.show-less', function () { 676 $wrapper.find('ul.woocommerce-widget-layered-nav-list > li').not(':lt(' + catNumbers + ')').hide(); 677 $(this).hide(); 678 $wrapper.find('.show-more').show(); 679 }); 680 }); 681 }; 682 683 zeomart.updateCartFragments = function() { 684 685 zeomart.$body.on('wc_fragments_refreshed wc_fragments_loaded', function() { 686 if (typeof zeomartJsData !== 'undefined') { 687 var wc_fragments = JSON.parse(sessionStorage.getItem(zeomartJsData.fragment_name)), 688 cart_hash_key = zeomartJsData.cart_hash_key, 689 cart_hash = sessionStorage.getItem(cart_hash_key), 690 cookie_hash = Cookies.get('woocommerce_cart_hash'), 691 cart_created = sessionStorage.getItem('wc_cart_created'), 692 day_in_ms = ( 24 * 60 * 60 * 1000 ); 693 694 if (cart_hash === null || cart_hash === undefined || cart_hash === '') { 695 cart_hash = ''; 696 } 697 698 if (cookie_hash === null || cookie_hash === undefined || cookie_hash === '') { 699 cookie_hash = ''; 700 } 701 702 if (cart_hash && (cart_created === null || cart_created === undefined || cart_created === '')) { 703 throw 'No cart_created'; 704 } 705 706 if (cart_created) { 707 var cart_expiration = ((1 * cart_created) + day_in_ms), 708 timestamp_now = (new Date()).getTime(); 709 if (cart_expiration < timestamp_now) { 710 throw 'Fragment expired'; 711 } 712 } 713 714 if (wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash) { 715 $.each(wc_fragments, function(key, value) { 716 $(key.replace('_zm', '')).replaceWith(value); 717 }); 718 } 719 } 720 }); 721 }; 722 723 zeomart.addToCartBundles = function() { 724 725 zeomart.$body.on('submit', 'form.zm-bumdle-form', function(e) { 726 var $form = $(this); 727 728 e.preventDefault(); 729 730 var $thisbutton = $form.find('.button'), 731 $product_ids = $form.find('input[name="bundle_items"]').val(); 732 733 $product_ids_list = []; 734 if ( $product_ids ) { 735 var $product_ids_list = $product_ids.split(","); 736 } 737 738 var data = { 739 action: 'zeomart_bundles_add_to_cart', 740 product_ids: $product_ids_list 741 }; 742 743 // Trigger event 744 zeomart.$body.trigger('adding_to_cart', [ 745 $thisbutton, 746 data 747 ]); 748 749 $.ajax({
750 url : zeomartJsData.ajax_url, 751 data: data, 752 method : 'POST', 753 success : function(response) { 754 755 if (!response) { 756 return; 757 } 758 759 var this_page = window.location.toString(); 760 761 this_page.replace('add-to-cart', 'added-to-cart'); 762 763 if (response.error && response.product_url) { 764 window.location = response.product_url; 765 return; 766 } 767 768 // Redirect to cart option 769 770 $thisbutton.removeClass('loading'); 771 772 var fragments = response.fragments; 773 var cart_hash = response.cart_hash; 774 775 // Block fragments class 776 if (fragments) { 777 $.each(fragments, function(key) { 778 $(key).addClass('updating'); 779 }); 780 } 781 782 // Replace fragments 783 if (fragments) { 784 $.each(fragments, function(key, value) { 785 $(key).replaceWith(value); 786 }); 787 } 788 789 // Show notices 790 var $noticeWrapper = $('.woocommerce-notices-wrapper'); 791 $noticeWrapper.empty(); 792 if (response.notices && response.notices.indexOf('error') > -1) { 793 $noticeWrapper.append(response.notices); 794 $thisbutton.addClass('not-added'); 795 } else { 796 // Changes button classes 797 $thisbutton.addClass('added'); 798 // Trigger event so themes can refresh other areas 799 zeomart.$body.trigger('added_to_cart', [ 800 fragments, 801 cart_hash, 802 $thisbutton 803 ]); 804 } 805 }, 806 error : function() { 807 console.log('ajax adding to cart error'); 808 }, 809 complete: function() { } 810 }); 811 }); 812 }; 813 814 // Add to cart ajax 815 zeomart.addToCartAjax = function () { 816 817 zeomart.$body.on('submit', 'form.cart', function(e) { 818 var $form = $(this); 819 var $productWrapper = $form.parents('.zeomart-single-product'); 820 821 if ($productWrapper.length === 0) { 822 $productWrapper = $form.parents('.product-quick-view'); 823 } 824 825 if ( $productWrapper.hasClass('product-type-external') 826 || $productWrapper.hasClass('product-type-zakeke') 827 || $productWrapper.hasClass('product-type-gift-card') 828 || $(e.target.activeElement).hasClass('buy_now_button') 829 ) { 830 return; 831 } 832 833 if ( $form.find('input[name="buy_now"]').length > 0 ) { 834 // the form has a hidden input field with name "buy-now" 835 // do something here 836 window.location = window.location.href; 837 return; 838 } 839 840 e.preventDefault(); 841 842 var $thisbutton = $form.find('.single_add_to_cart_button'), 843 data = $form.serialize(); 844 845 data += '&action=zeomart_ajax_add_to_cart'; 846 847 if ($thisbutton.val()) { 848 data += '&add-to-cart=' + $thisbutton.val(); 849 } 850 851 $thisbutton.removeClass('added not-added'); 852 $thisbutton.addClass('loading'); 853 854 // Trigger event 855 zeomart.$body.trigger('adding_to_cart', [ 856 $thisbutton, 857 data 858 ]); 859 860 $.ajax({
861 url : zeomartJsData.ajax_url, 862 data : data, 863 method : 'POST', 864 success : function(response) { 865 if (!response) { 866 return; 867 } 868 869 var this_page = window.location.toString(); 870 871 this_page.replace('add-to-cart', 'added-to-cart'); 872 873 if (response.error && response.product_url) { 874 window.location = response.product_url; 875 return; 876 } 877 878 // Redirect to cart option 879 880 $thisbutton.removeClass('loading'); 881 882 var fragments = response.fragments; 883 var cart_hash = response.cart_hash; 884 885 // Block fragments class 886 if (fragments) { 887 $.each(fragments, function(key) { 888 $(key).addClass('updating'); 889 }); 890 } 891 892 // Replace fragments 893 if (fragments) { 894 $.each(fragments, function(key, value) { 895 $(key).replaceWith(value); 896 }); 897 } 898 899 // Show notices 900 var $noticeWrapper = $('.woocommerce-notices-wrapper'); 901 $noticeWrapper.empty(); 902 if (response.notices && response.notices.indexOf('error') > -1) { 903 $noticeWrapper.append(response.notices); 904 $thisbutton.addClass('not-added'); 905 } else { 906 // Changes button classes 907 $thisbutton.addClass('added'); 908 // Trigger event so themes can refresh other areas 909 zeomart.$body.trigger('added_to_cart', [ 910 fragments, 911 cart_hash, 912 $thisbutton 913 ]); 914 } 915 }, 916 error : function() { 917 console.log('ajax adding to cart error'); 918 }, 919 complete: function() { } 920 }); 921 }); 922 923 zeomart.$body.on('click', '.variations_form .buy_now_button', function(e) { 924 var $this = $(this); 925 var $addToCartBtn = $this.siblings('.single_add_to_cart_button'); 926 927 if ( 'undefined' !== typeof wc_add_to_cart_variation_params && $addToCartBtn.hasClass('disabled') ) { 928 e.preventDefault(); 929 930 if ($addToCartBtn.hasClass('wc-variation-is-unavailable') ) { 931 alert( wc_add_to_cart_variation_params.i18n_unavailable_text ); 932 } else if ( $addToCartBtn.hasClass('wc-variation-selection-needed') ) { 933 alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text ); 934 } 935 } 936 }); 937 }; 938 939 zeomart.CartOpenPopup = function () { 940 941 var $cart_sticky = $('.zeomart-sticky-cart-popup'); 942 if ( ! $cart_sticky.length ) { 943 return; 944 } 945 946 zeomart.$body.on('click', '.cart-contents, .cart-contents-mobile, .zeomart-main-menu-cart', function(e) { 947 e.preventDefault(); 948 $cart_sticky.addClass('active'); 949 zeomart.$body.addClass('zm-popup-active'); 950 }); 951 952 zeomart.ClosePopup(); 953 954 zeomart.$body.on('added_to_cart', function() { 955 $(document.body).trigger('wc_fragment_refresh'); 956 if ( ! $cart_sticky.hasClass('active') ) { 957 $cart_sticky.addClass('active'); 958 zeomart.$body.addClass('zm-popup-active'); 959 } 960 }); 961 }; 962 963 zeomart.miniCartQuantity = function() { 964 var timeout; 965 966 $(document).on('change input', '.woocommerce-mini-cart .quantity .qty', function() { 967 var input = $(this); 968 var qtyVal = input.val(); 969 var itemID = input.parents('.woocommerce-mini-cart-item').data('key'); 970 var maxValue = input.attr('max'); 971 var cart_hash_key = zeomartJsData.cart_hash_key; 972 var fragment_name = zeomartJsData.fragment_name; 973 974 clearTimeout(timeout); 975 976 if (parseInt(qtyVal) > parseInt(maxValue)) { 977 qtyVal = maxValue; 978 } 979 980 timeout = setTimeout(function() { 981 input.parents('.mini_cart_item').addClass('zm-loading'); 982 983 $.ajax({
984 url : zeomartJsData.ajax_url, 985 data : { 986 action : 'zeomart_update_cart_item', 987 item_id: itemID, 988 qty : qtyVal 989 }, 990 success : function(data) { 991 if (data && data.fragments) { 992 $.each(data.fragments, function(key, value) { 993 if ($(key).hasClass('widget_shopping_cart_content')) { 994 var dataItemValue = $(value).find('.woocommerce-mini-cart-item[data-key="' + itemID + '"]'); 995 var dataFooterValue = $(value).find('.shopping-cart-widget-footer'); 996 var $itemSelector = $(key).find('.woocommerce-mini-cart-item[data-key="' + itemID + '"]'); 997 998 if (!data.cart_hash) { 999 $(key).replaceWith(value); 1000 } else { 1001 $itemSelector.replaceWith(dataItemValue); 1002 $('.shopping-cart-widget-footer').replaceWith(dataFooterValue); 1003 } 1004 } else { 1005 $(key).replaceWith(value); 1006 } 1007 }); 1008 1009 zeomart.$body.trigger( 'wc_fragments_refreshed' ); 1010 } 1011 }, 1012 dataType: 'json', 1013 method : 'GET' 1014 }); 1015 }, 500); 1016 }); 1017 }; 1018 1019 zeomart.ProductCustomQuantity = function() { 1020 1021 $(document).on( 'click', '.plus-btn, .minus-btn', function() { 1022 1023 var qty = $( this ).parent( '.quantity' ).find( '.qty' ); 1024 var val = parseFloat(qty.val()); 1025 var max = parseFloat(qty.attr( 'max' )); 1026 var min = parseFloat(qty.attr( 'min' )); 1027 var step = parseFloat(qty.attr( 'step' )); 1028 1029 if ( isNaN( val ) ) { // Check if val is NaN 1030 qty.val(min || 0).change(); 1031 return; 1032 } 1033 1034 if ( $( this ).is( '.plus-btn' ) ) { 1035 if ( max && ( max <= val ) ) { 1036 qty.val( max ).change(); 1037 } else { 1038 qty.val( val + step ).change(); 1039 } 1040 } else { 1041 if ( min && ( min >= val ) ) { 1042 qty.val( min ).change(); 1043 } else if ( val > 1 ) { 1044 qty.val( val - step ).change(); 1045 } 1046 } 1047 }); 1048 }; 1049 1050 zeomart.WoocommerceLoginForm = function() { 1051 $('.login-tabs a').click(function (e) { 1052 e.preventDefault(); 1053 1054 if (e.target.dataset.form === 'register') { 1055 $('.login-form-wrap').addClass('hide'); 1056 $('.register-form-wrap').removeClass('hide'); 1057 } else { 1058 $('.register-form-wrap').addClass('hide'); 1059 $('.login-form-wrap').removeClass('hide'); 1060 } 1061 1062 $('.login-tabs li').removeClass('active'); 1063 $(e.target).parents('li').addClass('active'); 1064 }); 1065 }; 1066 1067 $(function () { 1068 zeomart.init(); 1069 }); 1070}) 1071(jQuery);
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.