-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflagstone-2.0.0.min.js
8 lines (6 loc) · 5.06 KB
/
flagstone-2.0.0.min.js
1
2
3
4
5
6
7
8
/*
FlagstoneJS v2.0.0
(c) 2015 Depth Development. http://depthdev.com
License: Apache 2.0
*/
function FLAGSTONE(t){var s=function(t){for(var s=[],e=document.querySelectorAll(t),i=0,a=e.length;a>i;i++)s[i]=e[i];return s.length>1?s:s[0]},e=this,i=t||{};this.areaStr=i.area||"[flagstones]",this.area=s(this.areaStr),this.areaMargin=i.margin||0===i.margin?i.margin:i.areaMargin||0===i.areaMargin?i.areaMargin:10,this.areaWidth=0,this.areaHeight=0,this.minWidth=i.minWidth||280,this.maxColumns=i.maxColumns||1920,this.calcColumns=0,this.columns=0,this.flagstonesStr=i.flagstones||"[flagstone]",this.flagstones=s(this.flagstonesStr),this.flagstonesMargin=i.margin||0===i.margin?i.margin:i.flagstonesMargin||0===i.flagstonesMargin?i.flagstonesMargin:10,this.flagstoneWidth=this.areaWidth/this.columns-this.flagstonesMargin*(this.columns+1)/this.columns,this.flagstoneHeights=[],this.direction=i.direction?i.direction.toLowerCase():"left",this.random=i.random?(this.flagstones.sort(function(){return.5-Math.random()}),!0):!1,this.spaceFrequency=i.spaceFrequency||.4,this.spaceGenerator=function(){for(var t=0,s=this.flagstones.length;s>t;t++)Math.random()<this.spaceFrequency&&this.flagstones.splice(t,0,!1)},this.space=i.space?(this.spaceGenerator(),!0):!1,this.duration=i.duration/1e3||0,this.resizeDelay=i.resizeDelay||0===i.resizeDelay?i.resizeDelay:250,this.square=i.square||!1,this.hide=function(){this.area.className=this.area.className+" flagstones-hidden"},this.custom=i.custom||function(){return!1},this.run=function(){for(var t=[this.columns],s=0,i=this.flagstoneHeights.length;i>s;s++){if(s<this.columns)if(this.flagstones[s]){var a=this.flagstones[s].style.cssText.replace(/.*width\:\s?(\d+).+/,"$1");this.flagstones[s].style="",this.flagstones[s].style.cssText="width:"+a+"px;"+(this.square?"height:"+a+"px;":"")+"top:"+this.areaMargin+"px;"+this.direction+":"+(this.flagstoneWidth*s+(s?this.flagstonesMargin*s+this.areaMargin:this.areaMargin))+"px;",t[s]=this.flagstoneHeights[s]+this.areaMargin,this.custom(s,this.flagstones[s])}else this.columns>1&&(t[s]=this.flagstoneWidth+this.areaMargin);else{var n=Math.min.apply(null,t),r=t.indexOf(n);if(this.flagstones[s]){var a=this.flagstones[s].style.cssText.replace(/.*width\:\s?(\d+).+/,"$1");this.flagstones[s].style="",this.flagstones[s].style.cssText="width:"+a+"px;"+(this.square?"height:"+a+"px;":"")+"top:"+(n+this.flagstonesMargin)+"px;"+this.direction+":"+(this.flagstoneWidth*r+(r?this.flagstonesMargin*r+this.areaMargin:this.areaMargin))+"px;",t[r]+=this.flagstoneHeights[s]+this.flagstonesMargin,this.custom(s,this.flagstones[s])}else this.columns>1&&(t[r]+=this.flagstoneWidth+this.flagstonesMargin)}this.area.style.height=(Math.max.apply(null,t)||this.flagstoneHeights[0]+this.areaMargin)+this.areaMargin+"px"}setTimeout(function(){e.area.className=e.area.className.replace(/\s?flagstones\-hidden/,"")},0)},this.resetDelay1,this.resetDelay2,this.resetDelay3,this.reset=function(){e.areaWidth=e.area.outerWidth||e.area.offsetWidth,e.areaWidth<e.minWidth+(this.areaMargin?2*e.areaMargin:0)&&(e.areaWidth=e.minWidth),e.calcColumns=Math.floor(e.areaWidth/e.minWidth),e.columns=e.calcColumns>e.maxColumns?e.maxColumns:e.calcColumns,e.flagstoneWidth=e.areaWidth/e.columns-(e.flagstonesMargin*(e.columns-1)+2*e.areaMargin)/e.columns,e.flagstoneHeights=[];for(var t=0,s=e.flagstones.length;s>t;t++)e.flagstones[t]&&(e.flagstones[t].style.width=e.flagstoneWidth+"px"),e.flagstoneHeights.push(e.square||!e.flagstones[t]?e.flagstoneWidth:e.flagstones[t].outerHeight||e.flagstones[t].offsetHeight);e.run()},this.hardReset=function(){e.hide(),setTimeout(function(){e.flagstones=s(e.flagstonesStr),e.random&&e.flagstones.sort(function(){return.5-Math.random()}),e.space&&e.spaceGenerator(),e.reset()},0)},this.resets=function(){clearTimeout(e.resetDelay1),clearTimeout(e.resetDelay2),clearTimeout(e.resetDelay3),e.resetDelay1=setTimeout(e.reset.bind(e),e.resizeDelay),e.resetDelay2=setTimeout(e.reset.bind(e),1e3*e.duration+e.resizeDelay),e.resetDelay3=setTimeout(e.reset.bind(e),2e3*e.duration+e.resizeDelay)},this.init=function(){this.hide();var t=this.areaStr+"{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;min-width:"+(this.minWidth+2*this.flagstonesMargin)+"px;}"+this.flagstonesStr+"{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;top:0px;"+this.direction+":0px;}"+this.areaStr+".flagstones-hidden{visibility:hidden;}</style>"+this.areaStr+"{-webkit-transition-duration:"+e.duration+"s;-moz-transition-duration:"+e.duration+"s;-ms-transition-duration:"+e.duration+"s;-o-transition-duration:"+e.duration+"s;transition-duration:"+e.duration+"s;}"+this.flagstonesStr+"{-webkit-transition-duration:"+e.duration+"s;-moz-transition-duration:"+e.duration+"s;-ms-transition-duration:"+e.duration+"s;-o-transition-duration:"+e.duration+"s;transition-duration:"+e.duration+"s;}",i=document.createElement("style");i.type="text/css",i.appendChild(document.createTextNode(t)),s("head").appendChild(i),setTimeout(e.reset,0),window.addEventListener("load",e.resets),window.addEventListener("resize",e.resets)},this.init()}