PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.0
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.0
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / assets / js / modules / quick-view / quick-view.min.js

quick-view.min.js in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.0, at assets/js/modules/quick-view/quick-view.min.js

1 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var merchant=merchant||{};merchant.modules=merchant.modules||{},(m=>{merchant.modules.quickView={init:function(){var u=this,e=m(".merchant-quick-view-modal");e.length&&e.each(function(){var i=m(this),t=i.find(".merchant-quick-view-close-button"),r=i.find(".merchant-quick-view-nav-prev"),o=i.find(".merchant-quick-view-nav-next"),c=i.find(".merchant-quick-view-inner"),s=i.find(".merchant-quick-view-content"),e=i.find(".merchant-quick-view-overlay"),d=!1,l=-1,a=!1;function n(n,e){s.empty(),i.addClass("merchant-show"),i.addClass("merchant-loading"),d=!0,window.merchant.setting.sync_url_hash&&("push"===e?history.pushState({merchantQuickView:n},"","#merchant-quick-view-"+n):"replace"===e&&history.replaceState({merchantQuickView:n},"","#merchant-quick-view-"+n)),m.post(window.merchant.setting.ajax_url,{action:"merchant_quick_view_content",nonce:window.merchant.setting.nonce,product_id:n},function(e){var t,a;e.success&&d?(s.html(e.data),c.addClass("merchant-show"),i.removeClass("merchant-loading"),t=n,a=u.getProductIds(),l=a.indexOf(t),a.length<2||-1===l?(r.removeClass("merchant-quick-view-nav-visible"),o.removeClass("merchant-quick-view-nav-visible")):(r.toggleClass("merchant-quick-view-nav-visible",0<l),o.toggleClass("merchant-quick-view-nav-visible",l<a.length-1)),t=s.find(".woocommerce-product-gallery"),wc_single_product_params.zoom_enabled=window.merchant.setting.quick_view_zoom,"function"==typeof m.fn.wc_product_gallery&&t.length&&(t.trigger("wc-product-gallery-before-init",[t.get(0),wc_single_product_params]),wc_single_product_params.flexslider_enabled="1",t.wc_product_gallery(wc_single_product_params),t.trigger("wc-product-gallery-after-init",[t.get(0),wc_single_product_params])),a=s.find(".variations_form"),"function"==typeof m.fn.wc_variation_form&&a.length&&a.each(function(){m(this).wc_variation_form()}),window.botiga&&window.botiga.productSwatch&&window.botiga.productSwatch.init(),window.botiga&&window.botiga.qtyButton&&window.botiga.qtyButton.init("quick-view"),window.merchant.setting.ajax_add_to_cart&&u.initAjaxAddToCart(s,i)):(s.html(e.data),c.addClass("merchant-show"),i.removeClass("merchant-loading"),r.removeClass("merchant-quick-view-nav-visible"),o.removeClass("merchant-quick-view-nav-visible")),window.dispatchEvent(new Event("merchant.quickview.ajax.loaded"))}).fail(function(e,t){s.html(t),c.addClass("merchant-show"),i.removeClass("merchant-loading"),r.removeClass("merchant-quick-view-nav-visible"),o.removeClass("merchant-quick-view-nav-visible")})}m(document).on("click",".merchant-quick-view-button",function(e){e.preventDefault(),a=!!window.merchant.setting.sync_url_hash,n(m(this).data("product-id"),"push")}),r.on("click",function(e){e.preventDefault();e=u.getProductIds();0<l&&n(e[l-1],"replace")}),o.on("click",function(e){e.preventDefault();e=u.getProductIds();-1<l&&l<e.length-1&&n(e[l+1],"replace")}),e.on("click",function(e){e.preventDefault(),t.trigger("click")}),m(document).on("keydown",function(e){"Escape"===e.key&&d&&t.trigger("click")}),t.on("click",function(e){e.preventDefault(),d=!1,i.removeClass("merchant-show"),c.removeClass("merchant-show"),window.merchant.setting.sync_url_hash&&(a?history.back():history.replaceState(null,"",location.pathname+location.search),a=!1)}),window.merchant.setting.sync_url_hash&&(window.addEventListener("popstate",function(){var e=location.hash.match(/^#merchant-quick-view-(\d+)$/);e?n(parseInt(e[1],10),"none"):d&&(d=!1,i.removeClass("merchant-show"),c.removeClass("merchant-show"),a=!1)}),e=location.hash.match(/^#merchant-quick-view-(\d+)$/))&&n(parseInt(e[1],10),"none")})},getProductIds:function(){var t=[];return m(".merchant-quick-view-button[data-product-id]").each(function(){var e=m(this).data("product-id");e&&-1===t.indexOf(e)&&t.push(e)}),t},initAjaxAddToCart:function(d,l){var u=this;d.off("submit","form.cart"),d.on("submit","form.cart",function(e){var n,a,i,r,o,t=e.originalEvent?e.originalEvent.submitter:null,c=m(t),s=!1;if(s=t&&"add-to-cart"!==c.attr("name")&&!c.hasClass("single_add_to_cart_button")?s:!0)return e.preventDefault(),e.stopImmediatePropagation(),c=(t=m(this)).find('button[type="submit"], input[type="submit"]'),(n=(n=t.find(".single_add_to_cart_button")).length?n:c.first()).hasClass("loading")||n.prop("disabled")||(s=t.serializeArray(),a={action:"merchant_quick_view_add_to_cart",nonce:window.merchant.setting.nonce},i=!1,m.each(s,function(e,t){if(t.name&&0===t.name.indexOf("quantity["))return!(i=!0)}),m.each(s,function(e,t){"quantity"!==t.name&&"add-to-cart"!==t.name&&(a[t.name]=t.value)}),(e=t.closest('[id^="product-"]')).length&&(c=e.attr("id").match(/product-(\d+)/))&&c[1]&&(a.product_id=c[1]),a.product_id||(s=t.find('input[name="add-to-cart"]')).length&&s.val()&&(a.product_id=s.val()),a.product_id?(t.find(".variations_form").length&&(e=t.find('input[name="variation_id"]').val())&&(a.variation_id=parseInt(e,10)),i?delete a.quantity:(delete a.quantity,s=(c=t.find('input[name="quantity"]')).length?parseInt(c.val(),10):1,(isNaN(s)||s<1)&&(s=1),a.quantity=s),r=n.html(),o=n.prop("disabled"),n.addClass("loading").prop("disabled",!0),n.is("button")&&(n.data("original-text",r),n.html('<span class="spinner"></span>')),m.ajax({type:"POST",url:window.merchant.setting.ajax_url,data:a,success:function(e){u.handleAddToCartSuccess(e,n,r,o,d,l)},error:function(e,t,a){u.handleAddToCartError(e,t,a,n,r,o,d)}})):console.error("Quick View: Could not determine product ID")),!1})},handleAddToCartSuccess:function(e,t,a,n,i,r){t.removeClass("loading").prop("disabled",n),t.is("button")&&t.data("original-text")&&t.html(t.data("original-text")),e.success&&e.data?(e.data.fragments&&m.each(e.data.fragments,function(e,t){m(e).replaceWith(t)}),m(document.body).trigger("added_to_cart",[e.data.fragments,e.data.cart_hash,t,"quick-view"]),m(document.body).trigger("wc_fragment_refresh"),e.data.message&&(i.find(".merchant-quick-view-inner .woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),m(document).trigger("merchant_quick_view_add_to_cart_success",[e.data.message,i]))):this.handleAddToCartError(null,"error","Unexpected response format",t,a,n,i)},handleAddToCartError:function(e,t,a,n,i,r,o){n.removeClass("loading").prop("disabled",r),n.is("button")&&n.data("original-text")&&n.html(n.data("original-text"));r="",e&&e.responseJSON&&e.responseJSON.data&&e.responseJSON.data.message?r=e.responseJSON.data.message:e&&e.responseJSON&&e.responseJSON.data&&e.responseJSON.data.notices?(n=e.responseJSON.data.notices).error&&0<n.error.length&&(r=n.error[0].notice):r=a||t||"An error occurred while adding the product to cart.",o.find(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),e=m('<div class="woocommerce-error" role="alert"></div>').text(r);o.find("form.cart").before(e),e[0].scrollIntoView({behavior:"smooth",block:"nearest"})}},m(document).ready(function(){merchant.modules.quickView.init()})})(jQuery);