-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflagstone-1.3.0-jquery.min.js
7 lines (6 loc) · 4.92 KB
/
flagstone-1.3.0-jquery.min.js
1
2
3
4
5
6
7
/*
FlagstoneJS v1.3.0-jquery
(c) 2014 Depth Development. http://depthdev.com
License: Apache 2.0
*/
function FLAGSTONE(t){var i=this,s=t||{};this.areaStr=s.area||"[flagstones]",this.area=$(this.areaStr),this.areaMargin=s.margin||0===s.margin?s.margin:s.areaMargin||0===s.areaMargin?s.areaMargin:10,this.areaWidth=this.area.outerWidth(),this.areaHeight=this.area.outerHeight(),this.minWidth=s.minWidth||280,this.maxColumns=s.maxColumns||1920,this.calcColumns=Math.floor(this.areaWidth/this.minWidth),this.columns=this.calcColumns>this.maxColumns?this.maxColumns:this.calcColumns,this.margin=s.margin||0===s.margin?s.margin:10,this.flagstonesStr=s.flagstones||"[flagstone]",this.flagstones=$(this.flagstonesStr),this.flagstonesMargin=s.margin||0===s.margin?s.margin:s.flagstonesMargin||0===s.flagstonesMargin?s.flagstonesMargin:10,this.flagstoneHeights=[],this.flagstoneWidth=this.areaWidth/this.columns-this.margin*(this.columns+1)/this.columns,this.direction=s.direction?s.direction.toLowerCase():"left",this.duration=s.duration/1e3||0,this.jqueryAnimation=s.jqueryAnimation,this.resizeDelay=s.resizeDelay||0,this.hide=function(){this.area.addClass("flagstones-hidden")},this.run=function(){for(var t=new Array(this.columns),s=0,a=this.flagstoneHeights.length;a>s;s++){if(s<this.columns)this.jqueryAnimation?this.flagstones.eq(s).animate({top:this.areaMargin+"px",left:"right"===this.direction?"auto":this.flagstoneWidth*s+(s?this.flagstonesMargin*s+this.areaMargin:this.areaMargin)+"px",right:"left"===this.direction?"auto":this.flagstoneWidth*s+(s?this.flagstonesMargin*s+this.areaMargin:this.areaMargin)+"px"},1e3*this.duration):this.flagstones.eq(s).css({top:this.areaMargin+"px",left:"right"===this.direction?"auto":this.flagstoneWidth*s+(s?this.flagstonesMargin*s+this.areaMargin:this.areaMargin)+"px",right:"left"===this.direction?"auto":this.flagstoneWidth*s+(s?this.flagstonesMargin*s+this.areaMargin:this.areaMargin)+"px"}),t[s]=this.flagstoneHeights[s]+this.areaMargin;else{var e=Math.min.apply(null,t),n=t.indexOf(e);this.jqueryAnimation?this.flagstones.eq(s).animate({top:e+this.flagstonesMargin+"px",left:"right"===this.direction?"auto":this.flagstoneWidth*n+(n?this.flagstonesMargin*n+this.areaMargin:this.areaMargin)+"px",right:"left"===this.direction?"auto":this.flagstoneWidth*n+(n?this.flagstonesMargin*n+this.areaMargin:this.areaMargin)+"px"},1e3*this.duration):this.flagstones.eq(s).css({top:e+this.flagstonesMargin+"px",left:"right"===this.direction?"auto":this.flagstoneWidth*n+(n?this.flagstonesMargin*n+this.areaMargin:this.areaMargin)+"px",right:"left"===this.direction?"auto":this.flagstoneWidth*n+(n?this.flagstonesMargin*n+this.areaMargin:this.areaMargin)+"px"}),t[n]+=this.flagstoneHeights[s]+this.flagstonesMargin}this.area.css("height",(Math.max.apply(null,t)||this.flagstoneHeights[0]+this.areaMargin)+this.areaMargin+"px")}setTimeout(function(){i.area.removeClass("flagstones-hidden")},0)},this.resetDelay1,this.resetDelay2,this.resetDelay3,this.reset=function(){for(i.areaWidth=i.area.outerWidth(),i.areaWidth<i.minWidth+(this.areaMargin?2*i.areaMargin:0)&&(i.areaWidth=i.minWidth),i.calcColumns=Math.floor(i.areaWidth/i.minWidth),i.columns=i.calcColumns>i.maxColumns?i.maxColumns:i.calcColumns,i.flagstoneWidth=i.areaWidth/i.columns-(i.flagstonesMargin*(i.columns-1)+2*i.areaMargin)/i.columns;i.flagstoneHeights.length>0;)i.flagstoneHeights.pop();i.flagstones.each(function(){var t=$(this);i.jqueryAnimation?t.animate({width:i.flagstoneWidth+"px"},1e3*i.duration):t.css("width",i.flagstoneWidth+"px"),i.flagstoneHeights.push(t.outerHeight())}),i.run()},this.hardReset=function(){i.hide(),setTimeout(function(){i.flagstones=$(i.flagstonesStr),i.reset()},0)},this.resets=function(){clearTimeout(i.resetDelay1),clearTimeout(i.resetDelay2),clearTimeout(i.resetDelay3),i.resetDelay1=setTimeout(i.reset.bind(i),i.resizeDelay),i.resetDelay2=setTimeout(i.reset.bind(i),1e3*i.duration+i.resizeDelay),i.resetDelay3=setTimeout(i.reset.bind(i),2e3*i.duration+i.resizeDelay)},this.init=function(){this.hide();var t=$("head");t.append("<style>"+this.areaStr+"{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;min-width:"+(this.minWidth+2*this.margin)+"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.jqueryAnimation||t.append("<style>"+this.areaStr+"{-webkit-transition-duration:"+i.duration+"s;-moz-transition-duration:"+i.duration+"s;-ms-transition-duration:"+i.duration+"s;-o-transition-duration:"+i.duration+"s;transition-duration:"+i.duration+"s;}"+this.flagstonesStr+"{-webkit-transition-duration:"+i.duration+"s;-moz-transition-duration:"+i.duration+"s;-ms-transition-duration:"+i.duration+"s;-o-transition-duration:"+i.duration+"s;transition-duration:"+i.duration+"s;}</style>"),setTimeout(i.reset,0),$(window).on("load",i.resets),$(window).on("resize",i.resets)},this.init()}