-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflagstone-2.1.3.min.js
7 lines (6 loc) · 3.24 KB
/
flagstone-2.1.3.min.js
1
2
3
4
5
6
7
/*
FlagstoneJS v2.1.3
(c) 2015-2016 Depth Development. http://depthdev.com
License: MIT
*/
function Flagstone(t){var e=function(t){return document.querySelector(t)},i=function(t){for(var e=[],i=document.querySelectorAll(t),n=0,s=i.length;s>n;n++)e[n]=i[n];return e},n=t||{},s=n.area||"[flagstones]",o=e(s),r=n.margin||0===n.margin?n.margin:n.areaMargin||0===n.areaMargin?n.areaMargin:10,a=0,d=n.minWidth||280,l=n.maxColumns||1920,h=0,u=0,c=n.flagstones||"[flagstone]",f=i(c),m=n.margin||0===n.margin?n.margin:n.flagstonesMargin||0===n.flagstonesMargin?n.flagstonesMargin:10,g=a/u-m*(u+1)/u,b=[],p=n.direction?n.direction.toLowerCase():"left",x=n.random?(f.sort(function(){return.5-Math.random()}),!0):!1,y=n.spaceFrequency||.4,v=function(){for(var t=0,e=f.length;e>t;t++)Math.random()<y&&f.splice(t,0,!1)},z=n.space?(v(),!0):!1,T=n.duration/1e3||0,M=n.resizeDelay||0===n.resizeDelay?n.resizeDelay:250,w=n.square||!1;this.hide=function(){o.className=o.className+" flagstones-hidden"};var N,k,q,C=n.custom||function(){return!1},D=function(){for(var t=[u],e=0,i=b.length;i>e;e++){if(u>e)if(f[e]){var n=f[e].style.cssText.replace(/.*width\:\s?(\d+).+/,"$1");f[e].style.cssText="width:"+n+"px;"+(w?"height:"+n+"px;":"")+"top:"+r+"px;"+p+":"+(g*e+(e?m*e+r:r))+"px;",t[e]=b[e]+r,C(e,f[e])}else u>1&&(t[e]=g+r);else{var s=Math.min.apply(null,t),a=t.indexOf(s);if(f[e]){var n=f[e].style.cssText.replace(/.*width\:\s?(\d+).+/,"$1");f[e].style.cssText="width:"+n+"px;"+(w?"height:"+n+"px;":"")+"top:"+(s+m)+"px;"+p+":"+(g*a+(a?m*a+r:r))+"px;",t[a]+=b[e]+m,C(e,f[e])}else u>1&&(t[a]+=g+m)}o.style.height=(Math.max.apply(null,t)||b[0]+r)+r+"px"}setTimeout(function(){o.className=o.className.replace(/\s?flagstones\-hidden/g,"")}.bind(this),0)};this.reset=function(){if(!f.length)return!1;a=o.outerWidth||o.offsetWidth,d+(r?2*r:0)>a&&(a=d),h=Math.floor(a/d),u=h>l?l:h,g=a/u-(m*(u-1)+2*r)/u,b=[];for(var t=0,e=f.length;e>t;t++)f[t]&&(f[t].style.width=g+"px"),b.push(w||!f[t]?g:f[t].outerHeight||f[t].offsetHeight);D()}.bind(this),this.hardReset=function(){this.hide(),setTimeout(function(){f=i(c),x&&f.sort(function(){return.5-Math.random()}),z&&v(),this.reset()}.bind(this),0)}.bind(this);var E=function(){clearTimeout(N),clearTimeout(k),clearTimeout(q),N=setTimeout(this.reset.bind(this),M),k=setTimeout(this.reset.bind(this),1e3*T+M),q=setTimeout(this.reset.bind(this),2e3*T+M)}.bind(this);(function(){if(this.hide,!e("#flagstone-styles")){var t=s+"{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;min-width:"+(d+2*m)+"px;}"+c+"{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;top:0px;"+p+":0px;}"+s+".flagstones-hidden{visibility:hidden;}"+s+"{-webkit-transition-duration:"+T+"s;-moz-transition-duration:"+T+"s;-ms-transition-duration:"+T+"s;-o-transition-duration:"+T+"s;transition-duration:"+T+"s;}"+c+"{-webkit-transition-duration:"+T+"s;-moz-transition-duration:"+T+"s;-ms-transition-duration:"+T+"s;-o-transition-duration:"+T+"s;transition-duration:"+T+"s;}",i=document.createElement("style");i.type="text/css",i.id="flagstone-styles",i.appendChild(document.createTextNode(t)),e("head").appendChild(i)}setTimeout(this.reset,0),addEventListener("load",E.bind(this)),addEventListener("resize",E.bind(this))}).bind(this)()}