Files
backend-mm/public/web/shella/scripts/section.carousel-products.min.js
2025-09-25 03:03:31 +05:00

1 line
3.4 KiB
JavaScript

theme.CarouselProducts=function(){function t(t){this.$container=$(t),this.namespace=".carousel-products",this.onLoad()}return t.prototype=$.extend({},Section.prototype,t.prototype,{_checkProduct:function(a,t){var o=this,i=a.attr("data-handle");return!!i&&(t&&t(a),$.ajax({type:"GET",url:"https://"+window.location.hostname+"/products/"+i,data:{view:"collection"},cache:!1,dataType:"html",success:function(t){var e=$(t).clone();e.find("img").one("load",function(){a.add(o.$slick.find('.slick-cloned[data-handle="'+i+'"]')).html(e).removeAttr("data-handle")}),a.trigger("loaded")}}),!0)},onLoad:function(){var d=this,o=this.$container.find("[data-js-carousel]"),l=this.$container.find("[data-js-carousel-slick]"),i=this.$container.find("[data-carousel-control]"),n=this.$container.find("[data-carousel-items]"),s=null;if(this.$control=i,l.length){var c=l.find("> *"),t=o.find("[data-js-carousel-prev]"),e=o.find("[data-js-carousel-next]"),a=t.add(e),u=+o.attr("data-count"),r="true"===o.attr("data-autoplay"),h=+o.attr("data-speed"),p="true"===o.attr("data-infinite"),f="true"===o.attr("data-arrows"),m="true"===o.attr("data-bullets");if(this.$slick=l,f){function v(){var t=0;l.find(".carousel__item img").each(function(){t=Math.max(t,$(this).innerHeight())}),a.css({top:t/2})}$window.on("theme.resize.carousel-products",v)}function k(){l.one("init",function(){f&&v(),o.removeClass("invisible"),theme.Loader.unset(o.parent())}),l.on("beforeChange",function(t,e,a,o){var i=o-1,n=o+u;function s(t){c.unbind("loaded"),t.one("loaded",function(){theme.ProductReview.update()})}d._checkProduct(l.find('[data-slick-index="'+i+'"]'),s);for(var r=n;a+1<r;r--)d._checkProduct(l.find('[data-slick-index="'+r+'"]'),s)}),theme.Tooltip&&l.on("afterChange",function(){theme.Tooltip.init()}),l.slick({lazyLoad:!1,arrows:f,prevArrow:t,nextArrow:e,dots:m,dotsClass:"slick-dots d-flex flex-wrap flex-center list-unstyled mt-7",adaptiveHeight:!0,autoplay:r,autoplaySpeed:h,infinite:p,slidesToShow:u,slidesToScroll:u,rtl:theme.rtl,responsive:[{breakpoint:theme.breakpoints.values.xl,settings:{slidesToShow:3,slidesToScroll:3}},{breakpoint:theme.breakpoints.values.md,settings:{slidesToShow:2,slidesToScroll:2}},{breakpoint:theme.breakpoints.values.sm,settings:{slidesToShow:2,slidesToScroll:2}}]})}k(),i.on("click","a",function(t){var e=$(this);if(!e.hasClass("active")){s&&s.abort(),theme.Loader.set(o),o.css({"min-height":n.innerHeight()});var a=e.attr("data-collection");s=$.ajax({type:"GET",url:"/collections/"+a,cache:!1,data:{view:"carousel",constraint:"max_count="+n.attr("data-max-count")+"+products_pre_row="+n.attr("data-products-pre-row")+"+async_ajax_loading="+n.attr("data-async-ajax-loading")},dataType:"html",success:function(t){o.addClass("invisible"),l.slick("destroy").off(),l.one("init",function(){o.removeAttr("style"),theme.Loader.unset(o)}),n.html(t),c=l.find("> *"),k(),theme.ImagesLazyLoad.update(),theme.ProductReview.update(),theme.Tooltip&&theme.Tooltip.init(),i.find("a").removeClass("active"),e.addClass("active"),s=null}})}return t.preventDefault(),!1}),theme.is_loaded&&(theme.ImagesLazyLoad.update(),theme.ProductReview.update(),theme.Tooltip&&theme.Tooltip.init())}},onUnload:function(){this.$container.off(this.namespace),this.$slick&&(this.$slick.slick("destroy").off(),this.$slick=null,$window.unbind("theme.resize.carousel-products")),this.$control.off(),theme.Tooltip&&theme.Tooltip.destroy()}}),t}(),$(function(){theme.sections.register("carousel-products",theme.CarouselProducts)});