-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflagstone-3.8.0.min.js
6 lines (6 loc) · 12.6 KB
/
flagstone-3.8.0.min.js
1
2
3
4
5
6
/*
FlagstoneJS v3.8.0
(c) 2015-2017 Depth Development. http://depthdev.com
License: MIT
*/
!function(e,t){"use strict";e.flagstone=function(n,r){function a(n,r){function a(){for(var e=0,t=C.length;e<t;e++)Math.random()<H&&C.splice(e,0,!1)}function o(){E.style.visibility="hidden"}function s(){E.style.visibility="visible"}function i(){var t=[k],n=0,r=M.length;for(B=[];n<r;n++){if(n<k)C[n]?(C[n].style.top=y+"px",C[n].style[I]=O*n+(n?A*n+y:y)+"px",Z&&(C[n].style.height=C[n].style.width),t[n]=M[n]+y,ie(C[n],n),B.push([C[n]])):k>1&&(t[n]=O+y);else{var a=Math.min.apply(null,t),o=t.indexOf(a);C[n]?(C[n].style.top=a+A+"px",C[n].style[I]=O*o+(o?A*o+y:y)+"px",Z&&(C[n].style.height=C[n].style.width),t[o]+=M[n]+A,ie(C[n],n),B[o].push(C[n])):k>1&&(t[o]+=O+A)}b=(Math.max.apply(null,t)||M[0]+y)+y,E.style.height=b+"px"}e.setTimeout(s)}function l(t){if(C.length){T=E.offsetWidth,T<x+(y?2*y:0)&&(T=x),w=Math.floor(T/x),k=w>D?D:w,O=T/k-(A*(k-1)+2*y)/k,M=[];for(var n=0,r=C.length;n<r;n++)C[n]&&(C[n].style.width=O+"px",C[n].style.marginTop="0px"),M.push(Z||!C[n]?O:C[n].offsetHeight);T===E.offsetWidth||t?i():l(!0),t||e.setTimeout(function(){l(!0)},R)}}function g(){var t=Date.now(),n=E.getElementsByTagName("img");n.length&&!function(){var r=e.setInterval(function(){for(var a=[],o=0,s=n.length;o<s;o++)a[o]=n[o].naturalHeight;(a.indexOf(0)===-1||t+G<Date.now())&&(e.clearInterval(r),e.setTimeout(function(){l(!0)}))},J)}()}function d(t){if("keydown"!==t.type||13===t.keyCode||32===t.keyCode){for(var n=t.target;n&&!n.classList.contains(F);)n=n.parentElement;E.removeChild(n),e.MutationObserver||!le&&!ge||fe()}}function c(t){"keydown"===t.type&&13!==t.keyCode&&32!==t.keyCode||e.setTimeout(l,$)}function f(t){function n(){for(var t=0,n=B.length,r=0,a=0;t<n&&!g;t++)for(r=0,a=B[t].length;r<a;r++)g&&(i.push(B[t][r]),l.push(e.parseInt(B[t][r].style.marginTop,10)||0)),B[t][r]===o&&(g=!0)}function r(){for(var t=0,n=k,a=[];t<n;t++){var o=B[t][B[t].length-1],s=e.parseInt(o.style.top,10)+(e.parseInt(o.style.marginTop,10)||0)+o.offsetHeight+y;a.push(s)}var i=Math.max.apply(null,a);E.style.height=i+"px",te=e[(ne?"request":"cancel")+"AnimationFrame"](r)}function a(){function t(){for(var r=o.offsetHeight+s,g=r-a,d=0;d<n;d++)i[d].style.marginTop=g+l[d]+"px";ae=e[(oe?"request":"cancel")+"AnimationFrame"](t)}var n=i.length,a=e.parseInt(i[0].style.top,10)-A+l[0];oe=!0,ae=e.requestAnimationFrame(t),se=e.setTimeout(function(){oe=!1,e.cancelAnimationFrame(ae)},ee),ne=!0,te=e.requestAnimationFrame(r),re=e.setTimeout(function(){ne=!1,e.cancelAnimationFrame(te)},ee)}for(var o=t;o&&!o.classList.contains(F);)o=o.parentElement;var s=e.parseInt(o.style.top,10)+(e.parseInt(o.style.marginTop,10)||0),i=[],l=[],g=!1;return n(),ne=!1,e.cancelAnimationFrame(te),e.clearTimeout(re),oe=!1,e.cancelAnimationFrame(ae),e.clearTimeout(se),i.length?void a():(ne=!0,te=e.requestAnimationFrame(r),void(re=e.setTimeout(function(){ne=!1,e.cancelAnimationFrame(te)},ee)))}function m(e){"keydown"===e.type&&13!==e.keyCode&&32!==e.keyCode||f(e.target)}function v(){e.clearTimeout(de),de=e.setTimeout(l,Y)}function u(){e.clearTimeout(ce),ce=e.setTimeout(fe)}function h(){e.removeEventListener("resize",v),t.head.removeChild(t.getElementById("flagstone-"+p+"-styles"))}function S(e){e.margin||0===e.margin?(y=e.margin,A=e.margin):(y=e.bedPadding||y,A=e.stonesMargin||A),x=e.minWidth||x,D=e.maxColumns||D,K=e.dragAndDrop===!0||e.dragAndDrop===!1?e.dragAndDrop:K,V=e.dropCallback||V,ie=e.callback||ie,fe()}var p=e.flagstone.index,L=r||{},E=n||t.getElementsByClassName("flagstone")[0],y=L.margin||0===L.margin?L.margin:L.bedPadding||0===L.bedPadding?L.bedPadding:10,T=0,b=0,x=L.minWidth||280,D=L.maxColumns||5,w=0,k=0,C=[],A=L.margin||0===L.margin?L.margin:L.stonesMargin||0===L.stonesMargin?L.stonesMargin:10,O=T/k-A*(k+1)/k,M=[],B=[],F="flagstone-"+p+"-bed__stone",z=L.flow,I=L.direction?L.direction.toLowerCase():"left",P=L.assignReverseZIndexes,q=L.random,H=L.spaceFrequency||.4,N=L.space,R=L.animationDuration||0,W=L.animationDuration/1e3,_=L.animationTimingFunction||"linear",X=L.heightAnimationDuration||0,Q=L.heightAnimationDuration/1e3,j=L.heightAnimationTimingFunction||"linear",Y=L.resizeDelay||0===L.resizeDelay?L.resizeDelay:250,Z=L.square,G=L.imagesLoadedQueryDuration||2500,J=L.imagesLoadedQueryFrequency||100,K=L.dragAndDrop,U=L.dragAndDropAutoDelay,V=L.dropCallback||function(){return!0},$=L.eventResetDelay||0,ee=L.eventResizeHeightDuration||0,te=null,ne=!1,re=null,ae=null,oe=!1,se=null,ie=L.callback||function(){},le=L.watch!==!1,ge=L.watchAll,de=null,ce=null,fe=null,me={targetElem:null,dragStone:null,targetStone:null,targetStoneOverLeft:0,autoDropTimer:null,autoDrop:function(){me.targetStone.classList.contains(F)&&(me.targetStoneOverLeft?me.dragStone!==me.targetStone.previousElementSibling&&(me.targetStone.parentElement.insertBefore(me.dragStone,me.targetStone),me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.remove("flagstone-dragover")):me.dragStone!==me.targetStone.nextElementSibling&&(me.targetStone.parentElement.insertBefore(me.dragStone,me.targetStone.nextElementSibling),me.targetStone.classList.remove("flagstone-right"),me.targetStone.classList.remove("flagstone-dragover")),e.clearTimeout(me.autoDropTimer),me.autoDropTimer=e.setTimeout(me.autoDrop,U))},clear:function(){me.dragStone&&(me.dragStone.classList.remove("flagstone-drag"),me.dragStone=null),me.targetStone&&(me.targetStoneOverLeft=0,me.targetStone.classList.remove("flagstone-dragover"),me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.remove("flagstone-right"),me.targetStone=null),E.classList.remove("flagstone-dragover")},getTargetElem:function(e){for(me.targetElem=e.target instanceof HTMLElement?e.target:e.target.parentElement;me.targetElem&&!me.targetElem.classList.contains("flagstone-drag-handle");)me.targetElem=me.targetElem.parentElement;if(me.targetElem)for(me.dragStone=me.targetElem;me.dragStone&&!me.dragStone.classList.contains(F);)me.dragStone=me.dragStone.parentElement},mouseDown:function(e){me.getTargetElem(e)},dragStart:function(e){return!!me.targetElem&&(me.dragStone.classList.add("flagstone-drag"),void(e.dataTransfer&&e.dataTransfer.setData("text",this.id)))},touchStart:function(e){me.getTargetElem(e),me.dragStart(e)},dragEnter:function(t){t.preventDefault(),t.stopPropagation(),this!==me.dragStone&&this!==me.targetStone&&this!==E&&(e.clearTimeout(me.autoDropTimer),me.autoDropTimer=e.setTimeout(me.autoDrop,U))},touchMove:function(e){if(!me.dragStone)return!1;e.preventDefault(),e.stopPropagation();for(var n=t.elementFromPoint(e.touches[0].clientX,e.touches[0].clientY),r=n;r&&!r.classList.contains(F);)r=r.parentElement;r?(E.classList.remove("flagstone-dragover"),me.targetStoneOverLeft=r.getBoundingClientRect().left+r.offsetWidth/2>e.touches[0].clientX,me.targetStone&&me.targetStone!==r&&(me.targetStone.classList.remove("flagstone-dragover"),me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.remove("flagstone-right")),me.targetStone=r,me.targetStone.classList.contains("flagstone-lock")||(me.targetStone.classList.add("flagstone-dragover"),me.targetStoneOverLeft?(me.targetStone.classList.remove("flagstone-right"),me.targetStone.classList.add("flagstone-left")):(me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.add("flagstone-right")))):n===E&&(me.targetStone.classList.remove("flagstone-dragover"),me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.remove("flagstone-right"),E.classList.add("flagstone-dragover"),me.targetStone=E)},dragOver:function(e){return!!me.dragStone&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",void(this!==me.dragStone&&this.classList.contains(F)?(me.targetStone=this,me.targetStone.classList.add("flagstone-dragover"),me.targetStoneOverLeft=this.getBoundingClientRect().left+this.offsetWidth/2>e.clientX,me.targetStoneOverLeft?(me.targetStone.classList.remove("flagstone-right"),me.targetStone.classList.add("flagstone-left")):(me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.add("flagstone-right")),this.classList.remove("flagstone-dragover"),me.targetStone!==E&&E.classList.remove("flagstone-dragover")):this===E&&this.classList.add("flagstone-dragover")))},dragEnd:function(){me.clear()},touchEnd:function(){me.dragStone&&me.targetStone&&!me.targetStone.classList.contains("flagstone-lock")&&V(me.dropStone,me.targetStone)&&(me.targetStone===E?E.appendChild(me.dragStone):me.targetStoneOverLeft?E.insertBefore(me.dragStone,me.targetStone):E.insertBefore(me.dragStone,me.targetStone.nextElementSibling)),me.clear()},dragLeave:function(){me.targetStone&&(me.targetStone.classList.remove("flagstone-dragover"),me.targetStone.classList.remove("flagstone-left"),me.targetStone.classList.remove("flagstone-right"),E.classList.remove("flagstone-dragover"))},drop:function(t){if(!me.dragStone)return!1;if(t.stopPropagation(),e.clearTimeout(me.autoDropTimer),me.dragStone!==this&&(this.classList.contains(F)||this===E)){if(me.targetStone=this,me.targetStone===E){if(!V(me.dragStone,me.targetStone))return me.clear(),!1;me.targetStone.appendChild(me.dragStone)}else if(me.targetStoneOverLeft){if(!V(me.dragStone,me.targetStone))return me.clear(),!1;me.targetStone.parentElement.insertBefore(me.dragStone,me.targetStone)}else{if(!V(me.dragStone,me.targetStone.nextElementSibling))return me.clear(),!1;me.targetStone.parentElement.insertBefore(me.dragStone,me.targetStone.nextElementSibling)}me.clear(),e.MutationObserver||!le&&!ge||fe()}return!1}};return fe=function(){C=Array.prototype.slice.call(E.children);for(var t=0,n=C.length;t<n;t++)C[t].classList.add(F),P&&(C[t].style.zIndex=n-t);for(t=0;t<n;t++)C[t].setAttribute("draggable","false"),C[t].removeEventListener("mousedown",me.mouseDown),C[t].removeEventListener("dragstart",me.dragStart),C[t].removeEventListener("touchstart",me.touchStart),C[t].removeEventListener("touchmove",me.touchMove),C[t].removeEventListener("dragover",me.dragOver),C[t].removeEventListener("dragleave",me.dragLeave),C[t].removeEventListener("dragend",me.dragEnd),C[t].removeEventListener("touchend",me.touchEnd),C[t].removeEventListener("drop",me.drop),C[t].removeEventListener("touchend",me.drop),C[t].removeEventListener("dragenter",me.dragEnter);if(E.removeEventListener("dragover",me.dragOver),E.removeEventListener("drop",me.drop),K){for(t=0;t<n;t++)C[t].classList.contains("flagstone-lock")||(C[t].setAttribute("draggable","true"),C[t].addEventListener("mousedown",me.mouseDown),C[t].addEventListener("dragstart",me.dragStart),C[t].addEventListener("touchstart",me.touchStart),C[t].addEventListener("touchmove",me.touchMove),C[t].addEventListener("dragover",me.dragOver),C[t].addEventListener("dragleave",me.dragLeave),C[t].addEventListener("dragend",me.dragEnd),C[t].addEventListener("touchend",me.touchEnd),C[t].addEventListener("drop",me.drop),C[t].addEventListener("touchend",me.drop),U&&C[t].addEventListener("dragenter",me.dragEnter),C[t].getElementsByClassName("flagstone-drag-handle").length||C[t].classList.add("flagstone-drag-handle"));E.addEventListener("dragover",me.dragOver),E.addEventListener("drop",me.drop)}(q||N)&&(q&&C.sort(function(){return.5-Math.random()}),N&&a());var r=E.getElementsByClassName("flagstone-remove");for(t=0,n=r.length;t<n;t++)r[t].removeEventListener("click",d),r[t].addEventListener("click",d),r[t].removeEventListener("keydown",d),r[t].addEventListener("keydown",d);for(r=E.getElementsByClassName("flagstone-reset"),t=0,n=r.length;t<n;t++)r[t].removeEventListener("click",c),r[t].addEventListener("click",c),r[t].removeEventListener("keydown",c),r[t].addEventListener("keydown",c);for(r=E.getElementsByClassName("flagstone-resize-height"),t=0,n=r.length;t<n;t++)r[t].removeEventListener("click",m),r[t].addEventListener("click",m),r[t].removeEventListener("keydown",m),r[t].addEventListener("keydown",m);l(),R&&e.setTimeout(g,R),e.setTimeout(function(){l(!0)},R)},function(){if(o(),E.classList.add("flagstone-"+p+"-bed"),!t.getElementById("flagstone-"+p+"-styles")){var n=".flagstone-"+p+"-bed{box-sizing:border-box;list-style-type:none;overflow:hidden;position:relative;min-width:"+(x+2*y)+"px;}",r=".flagstone-"+p+"-bed__stone{box-sizing:border-box;position:absolute;top:0px;"+I+":0px;margin:0;}",a=".flagstone-"+p+"-bed__stone{transition:top "+W+"s "+_+","+I+" "+W+"s "+_+(z?",width "+W+"s "+_:"")+(X?",height "+Q+"s "+j:"")+";}",s=n+r+a,i=t.createElement("style");i.type="text/css",i.id="flagstone-"+p+"-styles",i.appendChild(t.createTextNode(s)),t.head.appendChild(i)}if(fe(),e.removeEventListener("resize",v),e.addEventListener("resize",v),(le||ge)&&e.MutationObserver){var l=new MutationObserver(u);l.observe(E,{childList:!0,subtree:ge})}}(),{adjust:S,destroy:h,resizeHeight:f,hide:o,reset:v,hardReset:fe}}return e.flagstone.index++,new a(n,r)},e.flagstone.index=-1}(window,document);