;(function(window){'use strict';function extend(a,b){for(var key in b){if(b.hasOwnProperty(key)){a[key]=b[key];}} return a;} function debounce(func,wait,immediate){var timeout;return function(){var context=this,args=arguments;var later=function(){timeout=null;if(!immediate)func.apply(context,args);};var callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args);};};function createRandIntOrderedArray(minVal,maxVal,size){var arr=[];for(var i=0;i0;} function collect(){var ret={};var len=arguments.length;for(var i=0;i';} segPiecesHTML+='
';var top,left,width,height,clipTop,clipLeft,clipRight,clipBottom,pos=i<=positionsTotal-1?i:0,isRandom=this.options.positions==='random';top=isRandom?anime.random(0,100):this.options.positions[pos].top;left=isRandom?anime.random(0,100):this.options.positions[pos].left;width=isRandom?anime.random(0,100):this.options.positions[pos].width;height=isRandom?anime.random(0,100):this.options.positions[pos].height;if(!clipPath){clipTop=isRandom?top/100*this.dimensions.height:this.options.positions[pos].top/100*this.dimensions.height;clipLeft=isRandom?left/100*this.dimensions.width:this.options.positions[pos].left/100*this.dimensions.width;clipRight=isRandom?width/100*this.dimensions.width+clipLeft:this.options.positions[pos].width/100*this.dimensions.width+clipLeft;clipBottom=isRandom?height/100*this.dimensions.height+clipTop:this.options.positions[pos].height/100*this.dimensions.height+clipTop;} if(this.options.shadows){segPiecesHTML+='
';} segPiecesHTML+=clipPath?'
':'
';segPiecesHTML+='
' if(this.options.parallax){segPiecesHTML+='';}} segPieces.innerHTML=segPiecesHTML;this.el.innerHTML='';this.el.appendChild(segBgEl);this.el.appendChild(segPieces);};Segmenter.prototype._renderPiece=function(piece){var idx=this.pieces.indexOf(piece);var self=this;if(self.options.animation.translateZ!=undefined){if(typeof self.options.animation.translateZ==='object'){var randArr=createRandIntOrderedArray(self.options.animation.translateZ.min,self.options.animation.translateZ.max,self.options.pieces);piece.style.transform=piece.style.WebkitTransform='translateZ('+randArr[idx]+'px)';} else{piece.style.transform=piece.style.WebkitTransform='translateZ('+self.options.animation.translateZ+'px)';}} if(self.options.animation.translateY!=undefined){if(typeof self.options.animation.translateY==='object'){var randArr=createRandIntOrderedArray(self.options.animation.translateY.min,self.options.animation.translateY.max,self.options.pieces);piece.style.transform=piece.style.WebkitTransform='translateY('+randArr[idx]+'px)';} else{piece.style.transform=piece.style.WebkitTransform='translateY('+self.options.animation.translateY+'px)';}} if(self.options.animation.translateX!=undefined){if(typeof self.options.animation.translateX==='object'){var randArr=createRandIntOrderedArray(self.options.animation.translateX.min,self.options.animation.translateX.max,self.options.pieces);piece.style.transform=piece.style.WebkitTransform='translateX('+randArr[idx]+'px)';} else{piece.style.transform=piece.style.WebkitTransform='translateX('+self.options.animation.translateX+'px)';}} if(self.options.animation.opacity!=undefined){piece.style.opacity=self.options.animation.opacity;} if(self.options.shadows&&isObjEmpty(self.options.shadowsAnimation)){var shadowEl=piece.querySelector('.segmenter__shadow');shadowEl.style.opacity=self.options.shadowsAnimation.opacity!=undefined?self.options.shadowsAnimation.opacity:0;shadowEl.style.transform=shadowEl.style.WebkitTransform='translateX('+(self.options.shadowsAnimation.translateX!=undefined?self.options.shadowsAnimation.translateX:0)+'px) translateY('+(self.options.shadowsAnimation.translateY!=undefined?self.options.shadowsAnimation.translateY:0)+'px)';}};Segmenter.prototype.animate=function(){if(this.active){return false;} this.active=true;var self=this,animProps={targets:this.pieces,duration:this.options.animation.duration,delay:function(el,index){return(self.options.pieces-index-1)*self.options.animation.delay;},easing:this.options.animation.easing,begin:this.options.onAnimationStart,complete:this.options.onAnimationComplete};if(this.options.animation.translateZ!=undefined){var randArr=createRandIntOrderedArray(this.options.animation.translateZ.min,this.options.animation.translateZ.max,this.options.pieces);animProps.translateZ=typeof this.options.animation.translateZ==='object'?function(el,index){return randArr[index];}:this.options.animation.translateZ;} if(this.options.animation.translateX!=undefined){animProps.translateX=typeof this.options.animation.translateX==='object'?function(el,index){return anime.random(self.options.animation.translateX.min,self.options.animation.translateX.max);}:this.options.animation.translateX;} if(this.options.animation.translateY!=undefined){animProps.translateY=typeof this.options.animation.translateY==='object'?function(el,index){return anime.random(self.options.animation.translateY.min,self.options.animation.translateY.max);}:this.options.animation.translateY;} if(this.options.animation.opacity!=undefined){animProps.opacity=this.options.animation.opacity;} anime(animProps);if(this.options.shadows&&isObjEmpty(this.options.shadowsAnimation)){anime(collect({targets:this.el.querySelectorAll('.segmenter__shadow'),duration:this.options.animation.duration,delay:function(el,index){return(self.options.pieces-index-1)*self.options.animation.delay;},easing:this.options.animation.easing},this.options.shadowsAnimation));}};Segmenter.prototype._initEvents=function(){var self=this;this.debounceResize=debounce(function(ev){var positionsTotal=self.options.positions.length;self.dimensions={width:self.el.offsetWidth,height:self.el.offsetHeight};self.pieces.forEach(function(piece,position){var clipTop,clipLeft,clipRight,clipBottom,segmenterPiece=piece.querySelector('.segmenter__piece');if(self.options.positions==='random'){var randT=anime.random(0,100),randL=anime.random(0,100),randW=anime.random(0,100),randH=anime.random(0,100);clipTop=randT/100*self.dimensions.height;clipLeft=randL/100*self.dimensions.width;clipRight=randW/100*self.dimensions.width+clipLeft;clipBottom=randH/100*self.dimensions.height+clipTop;} else{var pos=position<=positionsTotal-1?position:0;clipTop=self.options.positions[pos].top/100*self.dimensions.height;clipLeft=self.options.positions[pos].left/100*self.dimensions.width;clipRight=self.options.positions[pos].width/100*self.dimensions.width+clipLeft;clipBottom=self.options.positions[pos].height/100*self.dimensions.height+clipTop;} segmenterPiece.style.clip='rect('+clipTop+'px,'+clipRight+'px,'+clipBottom+'px,'+clipLeft+'px)';});},10);window.addEventListener('resize',this.debounceResize);if(this.options.parallax){var arrRand=createRandIntOrderedArray(this.options.parallaxMovement.min,this.options.parallaxMovement.max,this.options.pieces);this.pieces.forEach(function(piece,pos){piece.setAttribute('data-parallax-translation',typeof self.options.parallaxMovement==='object'?arrRand[pos]:self.options.parallaxMovement);});this.mousemove=function(ev){if(!self.active){return false;} requestAnimationFrame(function(){self.pieces.forEach(function(piece){var t=piece.getAttribute('data-parallax-translation'),transX=t/(self.dimensions.width)*ev.clientX-t/2,transY=t/(self.dimensions.height)*ev.clientY-t/2;piece.parentNode.style.transform=piece.parentNode.style.WebkitTransform='translate3d('+transX+'px,'+transY+'px,0)';});});};window.addEventListener('mousemove',this.mousemove);this.handleOrientation=function(){if(!self.active){return false;} var y=event.gamma;y+=90;requestAnimationFrame(function(){self.pieces.forEach(function(piece){var t=piece.getAttribute('data-parallax-translation'),transX=t/(self.dimensions.width)*y-t/2,transY=t/(self.dimensions.height)*y-t/2;piece.parentNode.style.transform=piece.parentNode.style.WebkitTransform='translate3d('+transX+'px,'+transY+'px,0)';});});} window.addEventListener('deviceorientation',this.handleOrientation);}};window.Segmenter=Segmenter;})(window);