
/*
	* LayerSlider Add-On: Origami Slide Transition
	*
	* (c) 2011-2025 George Krupa, John Gera & Kreatura Media
	*
	* LayerSlider home:		https://layerslider.com/
	* Licensing:			https://layerslider.com/licensing/
*/



;(function(a){window._layerSlider.plugins.origami=function(b){var c=this;c.pluginData={name:"Origami Slide Transition Add-On for LayerSlider",version:"1.8",requiredLSVersion:"8.1.0",authorName:"Kreatura",releaseDate:"2025. 12. 02."},c.pluginDefaults={opacity:.25,maxTiles:4},c.init=function(){c.extendLayerSlider()},c.extendLayerSlider=function(){b.transitions.slide.origami={start:function(){b.slider.ceilRatio=Math.ceil(b.slider.width/b.slider.height),this.blocksNum=b.slider.ceilRatio>c.pluginDefaults.maxTiles?c.pluginDefaults.maxTiles:b.slider.ceilRatio,this.blocksNum=Math.floor(Math.random()*this.blocksNum)+1,this.addBlocks()},getDirection:function(a){for(var b=this.lastDir;this.lastDir==b;)b=1<this.blocksNum?0===a?["right","top","right","bottom"][Math.floor(4*Math.random())]:a==this.blocksNum-1?["left","top","left","bottom"][Math.floor(4*Math.random())]:["top","bottom"][Math.floor(2*Math.random())]:["left","top","right","bottom"][Math.floor(4*Math.random())];return this.lastDir=b,b},addBlocks:function(){for(var a=0==b.slider.width%2?b.slider.width:b.slider.width+1,c=0==a/this.blocksNum%2?a/this.blocksNum:a/this.blocksNum-a/this.blocksNum%2,d=0==b.slider.height%2?b.slider.height:b.slider.height+1,e=0,f=0;f<this.blocksNum;f++){var g=this.blocksNum-Math.abs(Math.floor(this.blocksNum/2)-f)-Math.floor(this.blocksNum/2),h=this.getDirection(f),i=c;0!=a/this.blocksNum%2&&0==f%2&&(a-c*this.blocksNum)/2<this.blocksNum&&(i+=2),f==this.blocksNum-1&&e+i!==a&&(i=a-e),f==this.blocksNum-1&&a!==b.slider.width&&(e-=1);var j=b.transitions.slide.origami.createBlock("ls-origami-"+h,i,d,e,0).data({direction:h});j.css({zIndex:g}),this.appendTiles(j,e,h,f),e+=i}b.transitions.slide.start()},createBlock:function(c,d,e,f,g){var h=a("<div>").addClass("ls-origami-block "+c).css({width:d,height:e,left:f,top:g}).appendTo(b.transitions.slide.$wrapper);return h},appendTiles:function(c,d,e,f){b.transitions.slide.$wrapper.prependTo(b.slider.$layersWrapper);var g;"left"===e||"right"===e?g={width:c.width()/2}:"top"===e||"bottom"===e?g={height:c.height()/2}:void 0;var h=a("<div>").css(g).addClass("ls-origami-tile ls-origami-cur").appendTo(c),i=a("<div>").css(g).addClass("ls-origami-tile ls-origami-cur").appendTo(h),j=a("<div>").css(g).addClass("ls-origami-tile ls-origami-next").appendTo(i),k=a("<div>").css(g).addClass("ls-origami-tile ls-origami-next").appendTo(j);c.find(".ls-origami-tile").each(function(){var e=a(this).hasClass("ls-origami-next")?"next":"current",f=a("<div>").addClass("ls-origami-image-holder").appendTo(a(this));if(b.slides[e].data.$background){var g,h,i=a(this).parent();switch(c.data("direction")){case"left":switch(e){case"current":for(g=a(this).position().left;!i.is(".ls-origami-block");)g+=i.position().left,i=i.parent();break;case"next":for(g=0;!i.is(".ls-origami-cur");)g+=i.position().left,i=i.parent();}g=-d-g;break;case"right":switch(e){case"current":for(g=-a(this).position().left;!i.is(".ls-origami-block");)g-=i.position().left,i=i.parent();break;case"next":for(g=a(this).position().left;!i.is(".ls-origami-cur");)g-=i.position().left,i=i.parent();}g=-d+g;break;case"top":switch(e){case"current":for(h=-a(this).position().top;!i.is(".ls-origami-block");)h-=i.position().top,i=i.parent();break;case"next":for(h=0;!i.is(".ls-origami-cur");)h-=i.position().top,i=i.parent();}g=-d;break;case"bottom":switch(e){case"current":for(h=-a(this).position().top;!i.is(".ls-origami-block");)h-=i.position().top,i=i.parent();break;case"next":for(h=a(this).position().top;!i.is(".ls-origami-cur");)h-=i.position().top,i=i.parent();}g=-d;}var j,k,l=b.o.playByScroll&&"up"===b.device.scroll.direction?"to":"from",m="current"===e?b.transitions.curSlide:b.transitions.nextSlide,n=m.data.$background.data(b.defaults.init.dataKey),o=n.kenBurns[l],q=!!m.data.$background&&b.functions.getURL(m.data.$background),r=a(),r=a("<ls-grad>").appendTo(f),s=a("<img>").appendTo(r).attr("src",q).css({width:n.responsive.width,height:n.responsive.height,"-webkit-filter":n.responsive.filter,filter:n.responsive.filter,outline:"1px solid transparent"});r.css({width:b.slider.width+"px",height:b.slider.height+"px",left:g,top:h,backgroundImage:m.data.backgroundGradient||"none"});"current"===e?(j=n.responsive.kbRotation+n.responsive.kbScale,k="translateX("+n.responsive.x+"px) translateY("+n.responsive.y+"px) "):"next"===e?(j="rotate("+o.rotation+"deg) scale("+o.scale+")",k="translateX("+n.responsive.x+"px) translateY("+n.responsive.y+"px) "):void 0;s.css({transform:k}),r.css({transform:j}),"transparent"===m.data.backgroundColor||m.data.$backgroundVideo.length||f.css("background-color",m.data.backgroundColor),b.slider.$slideBGColorWrapper.css("background-color","transparent"),a("<div>").addClass("ls-light").appendTo(f)}}),this.setTransition(c,e,h,i,j,k,f)},setTransition:function(a,d,e,f,g,h){var i=a.find(".ls-light").addClass("ls-black"),j=e.find("> .ls-origami-image-holder > div"),k=f.find("> .ls-origami-image-holder > div"),l=g.find("> .ls-origami-image-holder > div"),m=h.find("> .ls-origami-image-holder > div"),n=b.gsap.Cubic.easeInOut,p=c.pluginDefaults.opacity,o=1.5*p;"left"===d?b.timelines._slideTransition.to(e[0],2,{ease:n,rotationY:89},0).to(f[0],2,{ease:n,rotationY:-180},0).fromTo(g[0],2,{rotationY:130},{ease:n,rotationY:91},0).fromTo(h[0],2,{rotationY:90},{ease:n,rotationY:0},1):"right"===d?b.timelines._slideTransition.to(e[0],2,{ease:n,rotationY:-89},0).to(f[0],2,{ease:n,rotationY:180},0).fromTo(g[0],2,{rotationY:-130},{ease:n,rotationY:-91},0).fromTo(h[0],2,{rotationY:-90},{ease:n,rotationY:0},1):"top"===d?b.timelines._slideTransition.to(e[0],2,{ease:n,rotationX:-89},0).to(f[0],2,{ease:n,rotationX:180},0).fromTo(g[0],2,{rotationX:-130},{ease:n,rotationX:-91},0).fromTo(h[0],2,{rotationX:-90},{ease:n,rotationX:0},1):"bottom"===d?b.timelines._slideTransition.to(e[0],2,{ease:n,rotationX:89},0).to(f[0],2,{ease:n,rotationX:-180},0).fromTo(g[0],2,{rotationX:130},{ease:n,rotationX:91},0).fromTo(h[0],2,{rotationX:90},{ease:n,rotationX:0},1):void 0;j[0]&&b.timelines._slideTransition.fromTo(j[0],2,{opacity:0},{ease:n,opacity:1-o},0),k[0]&&b.timelines._slideTransition.fromTo(k[0],2,{opacity:0},{ease:n,opacity:1-p},0),l[0]&&b.timelines._slideTransition.fromTo(l[0],2,{opacity:1-o},{ease:n,opacity:0},0),m[0]&&b.timelines._slideTransition.fromTo(m[0],2,{opacity:1-o},{ease:n,opacity:0},1)}},b.transitions.slide.select.slideTransitionType=function(){b.slides.next.data.transitionorigami&&b.browser.supports3D?(b.transitions.nextSlide.data.transition3d||b.transitions.nextSlide.data.transition2d)&&1===Math.floor(2*Math.random())+1?b.transitions.slide.normal.select.transitionType():b.transitions.slide.origami.start():b.transitions.slide.normal.select.transitionType()}}}})(jQuery,void 0);