1 line
5.3 KiB
JavaScript
1 line
5.3 KiB
JavaScript
jQuery(function(a){if("undefined"==typeof wc_single_product_params)return!1;a("body").on("init",".wc-tabs-wrapper, .woocommerce-tabs",function(){a(".wc-tab, .woocommerce-tabs .panel:not(.panel .panel)").hide();var b=window.location.hash,c=window.location.href,d=a(this).find(".wc-tabs, ul.tabs").first();b.toLowerCase().indexOf("comment-")>=0||"#reviews"===b||"#tab-reviews"===b?d.find("li.reviews_tab a").click():c.indexOf("comment-page-")>0||c.indexOf("cpage=")>0?d.find("li.reviews_tab a").click():d.find("li:first a").click()}).on("click",".wc-tabs li a, ul.tabs li a",function(b){b.preventDefault();var c=a(this),d=c.closest(".wc-tabs-wrapper, .woocommerce-tabs"),e=d.find(".wc-tabs, ul.tabs");e.find("li").removeClass("active"),d.find(".wc-tab, .panel:not(.panel .panel)").hide(),c.closest("li").addClass("active"),d.find(c.attr("href")).show()}).on("click","a.woocommerce-review-link",function(){return a(".reviews_tab a").click(),!0}).on("init","#rating",function(){a("#rating").hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>')}).on("click","#respond p.stars a",function(){var b=a(this),c=a(this).closest("#respond").find("#rating"),d=a(this).closest(".stars");return c.val(b.text()),b.siblings("a").removeClass("active"),b.addClass("active"),d.addClass("selected"),!1}).on("click","#respond #submit",function(){var b=a(this).closest("#respond").find("#rating"),c=b.val();if(b.length>0&&!c&&"yes"===wc_single_product_params.review_rating_required)return window.alert(wc_single_product_params.i18n_required_rating_text),!1}),a(".wc-tabs-wrapper, .woocommerce-tabs, #rating").trigger("init");var b=function(b,c){return this.$target=b,this.$images=a(".woocommerce-product-gallery__image",b),0===this.$images.length?void this.$target.css("opacity",1):(b.data("product_gallery",this),this.flexslider_enabled=a.isFunction(a.fn.flexslider)&&wc_single_product_params.flexslider_enabled,this.zoom_enabled=a.isFunction(a.fn.zoom)&&wc_single_product_params.zoom_enabled,this.photoswipe_enabled="undefined"!=typeof PhotoSwipe&&wc_single_product_params.photoswipe_enabled,c&&(this.flexslider_enabled=!1!==c.photoswipe_enabled&&this.flexslider_enabled,this.zoom_enabled=!1!==c.zoom_enabled&&this.zoom_enabled,this.photoswipe_enabled=!1!==c.photoswipe_enabled&&this.photoswipe_enabled),this.initFlexslider=this.initFlexslider.bind(this),this.initZoom=this.initZoom.bind(this),this.initPhotoswipe=this.initPhotoswipe.bind(this),this.onResetSlidePosition=this.onResetSlidePosition.bind(this),this.getGalleryItems=this.getGalleryItems.bind(this),this.openPhotoswipe=this.openPhotoswipe.bind(this),this.flexslider_enabled?(this.initFlexslider(),b.on("woocommerce_gallery_reset_slide_position",this.onResetSlidePosition)):this.$target.css("opacity",1),this.zoom_enabled&&(this.initZoom(),b.on("woocommerce_gallery_init_zoom",this.initZoom)),void(this.photoswipe_enabled&&this.initPhotoswipe()))};b.prototype.initFlexslider=function(){var b=this.$images,c=this.$target;c.flexslider({selector:".woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image",animation:wc_single_product_params.flexslider.animation,smoothHeight:wc_single_product_params.flexslider.smoothHeight,directionNav:wc_single_product_params.flexslider.directionNav,controlNav:wc_single_product_params.flexslider.controlNav,slideshow:wc_single_product_params.flexslider.slideshow,animationSpeed:wc_single_product_params.flexslider.animationSpeed,animationLoop:wc_single_product_params.flexslider.animationLoop,start:function(){c.css("opacity",1);var d=0;b.each(function(){var b=a(this).height();b>d&&(d=b)}),b.each(function(){a(this).css("min-height",d)})}})},b.prototype.initZoom=function(){var b=this.$images,c=this.$target.width(),d=!1;if(this.flexslider_enabled||(b=b.first()),a(b).each(function(b,e){var f=a(e).find("img");if(f.data("large_image_width")>c)return d=!0,!1}),d){var e={touch:!1};"ontouchstart"in window&&(e.on="click"),b.trigger("zoom.destroy"),b.zoom(e)}},b.prototype.initPhotoswipe=function(){this.zoom_enabled&&this.$images.length>0&&(this.$target.prepend('<a href="#" class="woocommerce-product-gallery__trigger">🔍</a>'),this.$target.on("click",".woocommerce-product-gallery__trigger",this.openPhotoswipe)),this.$target.on("click",".woocommerce-product-gallery__image a",this.openPhotoswipe)},b.prototype.onResetSlidePosition=function(){this.$target.flexslider(0)},b.prototype.getGalleryItems=function(){var b=this.$images,c=[];return b.length>0&&b.each(function(b,d){var e=a(d).find("img"),f=e.attr("data-large_image"),g=e.attr("data-large_image_width"),h=e.attr("data-large_image_height"),i={src:f,w:g,h:h,title:e.attr("title")};c.push(i)}),c},b.prototype.openPhotoswipe=function(b){b.preventDefault();var c,d=a(".pswp")[0],e=this.getGalleryItems(),f=a(b.target);c=f.is(".woocommerce-product-gallery__trigger")?this.$target.find(".flex-active-slide"):f.closest(".woocommerce-product-gallery__image");var g={index:a(c).index(),shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0},h=new PhotoSwipe(d,PhotoSwipeUI_Default,e,g);h.init()},a.fn.wc_product_gallery=function(a){return new b(this,a),this},a(".woocommerce-product-gallery").each(function(){a(this).wc_product_gallery()})}); |