-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid-slider.min.js
2 lines (2 loc) · 4.66 KB
/
grid-slider.min.js
1
2
/*! Copyright: https://apps.shopify.com/partners/maggicart */
!function(i){"use strict";i.gridSlider=function(e,t){var n=this,r={selector:".grid-slider",IntersectionObserver:!1},a=i(e);n.settings={},n.init=function(){n.settings=i.extend({},r,t),n._initSlider()},n.uniqid=function(i){i=i||10;for(var e="",t="abcdefghijklmnopqrstuvwxyz0123456789",n=t.length,r=0;r<i;r++)e+=t.charAt(Math.floor(Math.random()*n));return e},n._initSlider=function(){var e=n.settings,t=e.IntersectionObserver,r=i("head"),d=a.find(e.selector);return d.length||(d=a),d.each(function(){var e=i(this),a=i("body").hasClass("rtl"),d="grid-slider-"+n.uniqid(),s=d;if(e.addClass(d),d="."+d,a&&(e.attr("dir","rtl"),e.data("rtl",!0)),void 0===l){var o=e.find("> .slick-list > .slick-track");o.length?o.children().addClass("alo-item"):e.children().addClass("alo-item");var l=".alo-item"}var c=e.data(),h=void 0===(c||{}).rows?1:c.rows,f=h?d+" "+l:d+" .slick-track > "+l,p=void 0===(c||{}).padding?0:c.padding,u=f+"{padding: 0 "+p+"px; box-sizing: border-box} "+d+"{margin: 0 -"+p+"px; }"+d+".grid-init{visibility: visible; opacity: 1;}";if(u+=f+"{float: left; min-height: 1px; min-width: 1px;}",(u+=".rtl "+f+"{float: right; min-height: 1px; min-width: 1px;}")&&r.append('<style type="text/css" >'+u+"</style>"),u="",c.slidesToShow)if("IntersectionObserver"in window&&t){var v=c.slidesToShow+1;u+=d+" .item:nth-child(n+ "+v+"){display: none;} "+d+" .item{float:left};";var g=new IntersectionObserver(function(e,t){e.forEach(function(e){if(e.isIntersecting){var t=e.target,a=i(t);a.on("init",function(){r.find("#"+s).remove()}),n.sliderRender(a)}})});e.each(function(i,e){g.observe(e)})}else n.sliderRender(e);if(c.appendArrows||c.appendDots){var m=c.wrapper?e.find(c.wrapper):e.parent();c.appendArrows&&e.data("append-Arrows",m.find(c.appendArrows)),c.appendDots&&e.data("append-Dots",m.find(c.appendDots))}var w=n.getPesponsive(c);if(void 0!=w){var b=Object.keys(w).length;i.each(w,function(e,t){var n=0,r=0,a=0;if(i.each(t,function(i,e){a=parseInt(i)+1,n=e}),e+2<b)i.each(w[e+1],function(i,e){r=i,n=e}),u+=" @media (min-width: "+a+"px) and (max-width: "+r+"px)";else{if(e+2==b)return;i.each(w[e],function(i,e){r=i,n=e}),u+=" @media (min-width: "+r+"px)"}var s=1!=h?f+":nth-child("+n+"n+1){clear: left}":" ";u+=" {"+d+"{margin: 0 -"+p+"px}"+f+"{padding: 0 "+p+"px; box-sizing: border-box; width: calc(100% / "+n+")} "+(s+=1!=h?".rtl "+f+":nth-child("+n+"n+1){clear: right}":" ")+"}"}),r.append('<style type="text/css" id="'+s+'" >'+u+"</style>"),e.addClass("grid-init")}}),this},n.getPesponsive=function(e){if(e.responsive){if(!e.slidesToShow)return e.responsive.reverse();var t=e.responsive,n=(Object.keys(t).length,[]);return i.each(t,function(i,e){var t={};t[e.breakpoint]=parseInt(e.settings.slidesToShow),n.push(t)}),n.reverse()}},n.sliderRender=function(e){if(e.hasClass("slick-initialized"))e.slick("refresh");else{var t=e.data(),n=e.find("img.lazyload");n.length&&n.each(function(e){i(this).data("lazy",i(this).data("src"))}),e.on("init",function(e,t){i("body").trigger("contentUpdated"),i(this).find(".external-video").on("click",function(e){if(e.preventDefault(),!t.hasClass("embed")){var t=i(this),n=t.find("img"),r=i(this).data("video");r=(r=r.replace("://vimeo.com/","://player.vimeo.com/video/")).replace("://www.youtube.com/watch?v=","://youtube.com/embed/");var a='<iframe class="iframe-video" src="'+(r+="?autoplay=1&badge=0")+'" width="'+n.width()+'" height="'+n.height()+'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';t.append(a).addClass("embed"),n.hide()}})});var r=e.slick(t);e.on("beforeChange",function(e,t,n,r){var a=i(this).find(".external-video");a.removeClass("embed").find("img").show(),a.find(".iframe-video").remove()}),r.on("click",".item",function(){e.slick("slickSetOption","autoplay",!1,!1)})}},n.init()},i.fn.gridSlider=function(e){return this.each(function(){if(void 0==i(this).data("gridSlider")){var t=new i.gridSlider(this,e);i(this).data("gridSlider",t)}})},i(document).ready(function(i){i(".grid-slider").not(".exception").each(function(){i(this).gridSlider()})}),i(document).on("contentUpdated",function(e){i(".grid-slider").not(".exception, .grid-init, .slick-initialized").each(function(){i(this).gridSlider()})}),i(document).on("Alothemes:SwitchRTL:reload",function(e){i(".grid-slider").not(".exception").each(function(){i("body").hasClass("rtl")?i(this).attr("dir","rtl").data("rtl",!0):i(this).attr("dir","ltr").data("rtl",!1),i(this).hasClass("slick-initialized")&&i(this).slick("unslick").slick(i(this).data())})}),i(document).on("shopify:section:unload shopify:section:load",function(e){i("#shopify-section-"+e.detail.sectionId).find(".grid-slider").not(".exception").each(function(){i(this).gridSlider()})})}(jQuery);