/*! * Muuri v0.3.0 * https://github.com/haltu/muuri * Copyright (c) 2015, Haltu Oy * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ !function(t,e){var i,n;if("function"==typeof define&&define.amd)define(function(r){return i=r.defined&&r.defined("velocity")?r("velocity"):void 0,n=r.defined&&r.defined("hammer")?r("hammer"):void 0,e(t,"Muuri",i,n)});else if("object"==typeof module&&module.exports){try{i=require("velocity-animate")}catch(t){}try{n=require("hammerjs")}catch(t){}module.exports=e(t,"Muuri",i,n)}else i=t.Velocity||t.jQuery.Velocity,n=t.Hammer,t.Muuri=e(t,"Muuri",i,n)}(this,function(t,e,i,n,r){"use strict";function o(e,i){var n,r,s,a,l=this;if(e=l._element=typeof e===lt?et.querySelectorAll(e)[0]:e,!et.body.contains(e))throw new ot("Container element must be an existing DOM element");n=l._settings=tt(o.defaultOptions,i),l._id=++_t,ht[l._id]=l,l._isDestroyed=!1,l._layout=null,l._emitter=new o.Emitter,l._setSortGroups(n.dragSortGroup),l._sortConnections=n.dragSortWith&&n.dragSortWith.length?[].concat(n.dragSortWith):null,l._itemShowHandler=typeof n.showAnimation===at?n.showAnimation(n.showDuration,n.showEasing,n.visibleStyles):U("show",n.showDuration,n.showEasing,n.visibleStyles),l._itemHideHandler=typeof n.hideAnimation===at?n.hideAnimation(n.hideDuration,n.hideEasing,n.hiddenStyles):U("hide",n.hideDuration,n.hideEasing,n.hiddenStyles),E(e,n.containerClass),l._items=[],r=n.items,typeof r===lt?Y(l._element.children).forEach(function(t){("*"===r||pt(t,r))&&l._items.push(new o.Item(l,t))}):(nt.isArray(r)||D(r))&&(l._items=Y(r).map(function(t){return new o.Item(l,t)})),a=n.layoutOnResize,a=!0===a?0:typeof a===dt?a:-1,a>=0&&(s=C(function(){l.refreshItems().layout()},a),l._resizeHandler=function(){s()},t.addEventListener("resize",l._resizeHandler)),n.layoutOnInit&&l.layout(!0)}function s(t,e){var i,n=this,r=t._settings;n._id=++_t,ft[n._id]=n,n._isDestroyed=!1,e.parentNode!==t._element&&t._element.appendChild(e),E(e,r.itemClass),i="none"===b(e,"display"),E(e,i?r.itemHiddenClass:r.itemVisibleClass),n._gridId=t._id,n._element=e,n._child=e.children[0],n._animate=new o.ItemAnimate(n,e),n._animateChild=new o.ItemAnimate(n,n._child),n._isDefaultAnimate=n._animate instanceof f,n._isActive=!i,n._isPositioning=!1,n._isHidden=i,n._isHiding=!1,n._isShowing=!1,n._visibilityQueue=[],n._layoutQueue=[],n._left=0,n._top=0,I(e,{left:"0",top:"0",transform:"translateX(0px) translateY(0px)",display:i?"none":"block"}),n._refreshDimensions()._refreshSortData(),i?t._itemHideHandler.start(n,!0):t._itemShowHandler.start(n,!0),n._migrate=new o.ItemMigrate(n),n._release=new o.ItemRelease(n),n._drag=r.dragEnabled?new o.ItemDrag(n):null}function a(t,e){e=e?e.concat():t.getItems("active"),t._refreshDimensions();var i=this,n=t._settings.layout,r=t._width-t._border.left-t._border.right-t._padding.left-t._padding.right,o=t._height-t._border.top-t._border.bottom-t._padding.top-t._padding.bottom,s=typeof n===at?n(e,r,o):l(e,r,o,v(n)?n:{});i.items=e,i.slots=s.slots,i.setWidth=s.setWidth||!1,i.setHeight=s.setHeight||!1,i.width=s.width,i.height=s.height}function l(t,e,i,n){var r,o,s,a,l=!!n.fillGaps,h=!!n.horizontal,f=!!n.alignRight,u=!!n.alignBottom,g={slots:{},width:h?0:e,height:h?i:0,setWidth:h,setHeight:!h},_=[];if(!t.length)return g;for(a=0;at.height&&(g.left>0&&(u[u.length]={left:0,top:t.height,width:g.left,height:1/0}),g.left+g.widtht.width&&(g.top>0&&(u[u.length]={left:t.width,top:0,width:1/0,height:g.top}),g.top+g.height0&&s.height>0&&(r&&s.topn?n:e<0?rt.max(i+e,0):e}function c(t,e,i){if(!(t.length<2)){var n,r=p(t,e),o=p(t,i);r!==o&&(n=t[r],t[r]=t[o],t[o]=n)}}function m(t,e,i){if(!(t.length<2)){var n=p(t,e),r=p(t,i);n!==r&&t.splice(r,0,t.splice(n,1)[0])}}function y(t){var e,i=[],n=t.length;if(n)for(i[0]=t[0],e=1;e0?function(o){n!==r&&(n=t.clearTimeout(n),"finish"===o&&e()),"cancel"!==o&&"finish"!==o&&(n=t.setTimeout(function(){n=r,e()},i))}:function(t){"cancel"!==t&&e()}}function b(e,i){return t.getComputedStyle(e,null).getPropertyValue("transform"===i?ct.styleName||i:i)}function A(t,e){return parseFloat(b(t,e))||0}function x(t,e){return parseFloat((b(t,"transform")||"").replace("matrix(","").split(",")["x"===e?4:5])||0}function I(t,e){var i,n,r,o=it.keys(e);for(r=0;r=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height}function F(t,e){var i=[];return L(t,e)?(t.lefte.left+e.width&&(i[i.length]={left:e.left+e.width,top:t.top,width:t.left+t.width-(e.left+e.width),height:t.height}),t.tope.top+e.height&&(i[i.length]={left:t.left,top:e.top+e.height,width:t.width,height:t.top+t.height-(e.top+e.height)}),i):[{left:t.left,top:t.top,width:t.width,height:t.height}]}function V(t){for(var e,i,n,r=t.length;r--;)for(i=t[r],e=t.length;e--;)if(n=t[e],r!==e&&z(i,n)){t.splice(r,1);break}return t}function W(t,e){return L(t,e)?(rt.min(t.left+t.width,e.left+e.width)-rt.max(t.left,e.left))*(rt.min(t.top+t.height,e.top+e.height)-rt.max(t.top,e.top))/(rt.min(t.width,e.width)*rt.min(t.height,e.height))*100:0}function B(t){var e,i={};for(e=0;es?1:0:sa?1:0))return d;return d}function j(t,e){var i,n,r,o=[],s=t.concat();for(r=0;r-1&&(o.push(i),s.splice(n,1));return nt.prototype.splice.apply(t,[0,t.length].concat(o).concat(s)),t}function T(t,e,i,n){var o,s,a=t.getItems(i),l=n||{},d=!0===l.instant,h=l.onFinish,f=l.layout?l.layout:l.layout===r,u=a.length,g="show"===e,_=g?yt:Dt,p=g?vt:wt,c=!1,m=[],y=[],v=[];for(s=0;s0;return{start:function(t,o,s){r&&n?o?((t._isDefaultAnimate?H:I)(t._child,n),s&&s()):t._animateChild.start(null,n,{duration:e,easing:i,onFinish:s}):s&&s()},stop:function(t){t._animateChild.stop()}}}function J(t,e,i){var n,r,o,s=null,a=e._getSortConnections(!0),l=-1;for(o=0;oi&&n>l&&(l=n,s=r);return s}function K(t,e,i){var n,r=t.splice(0,t.length);for(n=0;n-1&&l.splice(i,1);if(!l.length)return f;for(s=0;s-1?t:o._items.length+t,o._items[e]||null;for(i=null,r=0;r0?n:0;return e=t.getBoundingClientRect(),s._width=rt.round(e.width),s._height=rt.round(e.height),s._outerWidth=s._width+r.left+r.right,s._outerHeight=s._height+r.top+r.bottom,s},s.prototype._refreshSortData=function(){var t,e,i=this;return i._isDestroyed||(t={},e=i.getGrid()._settings.sortData,e&&it.keys(e).forEach(function(n){t[n]=e[n](i,i._element)}),i._sortData=t),i},s.prototype._layout=function(t,e){var n,r,o,s,a,l,d,h,f,u,g=this,_=g._element,p=g._isPositioning,c=g._migrate,m=g._release,y=m.isActive&&!1===m.isPositioningStarted;if(g._isDestroyed)return g;if(n=g.getGrid(),r=n._settings,o=y?r.dragReleaseDuration:r.layoutDuration,s=y?r.dragReleaseEasing:r.layoutEasing,a=!t&&!g._skipNextLayoutAnimation&&o>0,u=function(){g._isPositioning&&(g._isPositioning=!1,X(_,r.itemPositioningClass)),m.isActive&&m.stop(),c.isActive&&c.stop(),K(g._layoutQueue,!1,g)},p&&K(g._layoutQueue,!0,g),y&&(m.isPositioningStarted=!0),typeof e===at&&(g._layoutQueue[g._layoutQueue.length]=e),l=m.isActive?m.containerDiffX:c.isActive?c.containerDiffX:0,d=m.isActive?m.containerDiffY:c.isActive?c.containerDiffY:0,a){if(p&&g._isDefaultAnimate?(h=parseFloat(i.hook(_,"translateX"))-l,f=parseFloat(i.hook(_,"translateY"))-d):(h=x(_,"x")-l,f=x(_,"y")-d),g._left===h&&g._top===f)return g._stopLayout(),void u();p||(g._isPositioning=!0,E(_,r.itemPositioningClass)),g._animate.start({translateX:h+l+"px",translateY:f+d+"px"},{translateX:g._left+l,translateY:g._top+d},{duration:o,easing:s,onFinish:u})}else g._stopLayout(),g._skipNextLayoutAnimation=!1,m.isActive&&_.parentNode!==n._element&&c.isActive&&c.container!==n._element||I(_,{transform:"translateX("+(g._left+l)+"px) translateY("+(g._top+d)+"px)"}),u();return g},s.prototype._show=function(t,e){var i,n,r=this,o=r._element,s=r._visibilityQueue,a=typeof e===at?e:null;return r._isDestroyed?r:(i=r.getGrid(),n=i._settings,r._isShowing?t?(i._itemShowHandler.stop(r),K(s,!0,r),a&&(s[s.length]=a),i._itemShowHandler.start(r,t,function(){r._isShowing=!1,K(s,!1,r)})):a&&(s[s.length]=a):r._isHidden?(r._isHiding&&i._itemHideHandler.stop(r),r._isActive=r._isShowing=!0,r._isHidden=r._isHiding=!1,E(o,n.itemVisibleClass),X(o,n.itemHiddenClass),I(o,{display:"block"}),K(s,!0,r),a&&(s[s.length]=a),i._itemShowHandler.start(r,t,function(){r._isShowing=!1,K(s,!1,r)})):a&&a(!1,r),r)},s.prototype._hide=function(t,e){var i,n,r=this,o=r._element,s=r._visibilityQueue,a=typeof e===at?e:null;return r._isDestroyed?r:(i=r.getGrid(),n=i._settings,r._isHiding?t?(i._itemHideHandler.stop(r),K(s,!0,r),a&&(s[s.length]=a),i._itemHideHandler.start(r,t,function(){r._isHiding=!1,I(o,{display:"none"}),K(s,!1,r)})):a&&(s[s.length]=a):r._isHidden?a&&a(!1,r):(r._isShowing&&i._itemShowHandler.stop(r),r._isHidden=r._isHiding=!0,r._isActive=r._isShowing=!1,E(o,n.itemHiddenClass),X(o,n.itemVisibleClass),K(s,!0,r),typeof a===at&&(s[s.length]=a),i._itemHideHandler.start(r,t,function(){r._isHiding=!1,I(o,{display:"none"}),K(s,!1,r)})),r)},s.prototype._destroy=function(t){var e,i,n,o=this,s=o._element;return o._isDestroyed?o:(e=o.getGrid(),i=e._settings,n=e._items.indexOf(o),o._release.destroy(),o._migrate.destroy(),o._stopLayout(!0),e._itemShowHandler.stop(o),e._itemHideHandler.stop(o),o._drag&&o._drag.destroy(),o._animate.destroy(),o._animateChild.destroy(),s.removeAttribute("style"),o._child.removeAttribute("style"),K(o._visibilityQueue,!0,o),X(s,i.itemPositioningClass),X(s,i.itemDraggingClass),X(s,i.itemReleasingClass),X(s,i.itemClass),X(s,i.itemVisibleClass),X(s,i.itemHiddenClass),n>-1&&e._items.splice(n,1),t&&s.parentNode.removeChild(s),ft[o._id]=r,o._isActive=o._isPositioning=o._isHiding=o._isShowing=!1,o._isDestroyed=o._isHidden=!0,o)},h.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t]||[];return i[i.length]=e,this._events[t]=i,this},h.prototype.once=function(t,e){var i=this;return this.on(t,function n(){i.off(t,n),e.apply(null,arguments)})},h.prototype.off=function(t,e){if(this._isDestroyed)return this;for(var i=this._events[t]||[],n=i.length;n--;)e===i[n]&&i.splice(n,1);return this},h.prototype.emit=function(t,e,i,n){if(this._isDestroyed)return this;var r,o=this._events[t]||[],s=o.length,a=arguments.length-1;if(s)for(o=o.concat(),r=0;rc&&(e=o,c=r));return c=h&&{grid:g,index:e,action:f}},_.prototype.destroy=function(){var t=this;return t._isDestroyed||(t.stop(),t._hammer.destroy(),t.getItem()._element.removeEventListener("dragstart",$,!1),t._isDestroyed=!0),t},_.prototype.getItem=function(){return ft[this._itemId]||null},_.prototype.getGrid=function(){return ht[this._gridId]||null}, _.prototype.reset=function(){var t=this,e=t._data;return e.isActive=!1,e.container=null,e.containingBlock=null,e.startEvent=null,e.currentEvent=null,e.scrollers=[],e.left=0,e.top=0,e.gridX=0,e.gridY=0,e.elementClientX=0,e.elementClientY=0,e.containerDiffX=0,e.containerDiffY=0,t},_.prototype.checkOverlap=function(){var t,e,i,n,r,o=this,s=o.getItem(),a=o._sortPredicate(s,o._data.currentEvent);return v(a)&&typeof a.index===dt?(t=s.getGrid(),e=t._items.indexOf(s),i=a.grid||t,n=a.index,r="swap"===a.action?"swap":"move",t===i?(n=p(t._items,n),e!==n&&(("swap"===r?c:m)(t._items,e,n),t._emit("move",{item:s,fromIndex:e,toIndex:n,action:r}),t.layout())):(s._gridId=i._id,o._isMigrating=s._gridId!==o._gridId,t._items.splice(e,1),S(i._items,s,n),n=i._items.indexOf(s),s._sortData=null,t._emit("send",{item:s,fromGrid:t,fromIndex:e,toGrid:i,toIndex:n}),i._emit("receive",{item:s,fromGrid:t,fromIndex:e,toGrid:i,toIndex:n}),t.layout(),i.layout()),o):o},_.prototype.finishMigration=function(){var t,e,i,n=this,r=n.getItem(),s=r._release,a=r.getElement(),l=r.getGrid(),d=l.getElement(),h=l._settings,u=h.dragContainer||d,g=n.getGrid()._settings,_=a.parentNode;return n._isMigrating=!1,n.destroy(),r._animate.destroy(),r._animateChild.destroy(),X(a,g.itemClass),X(a,g.itemVisibleClass),X(a,g.itemHiddenClass),E(a,h.itemClass),E(a,h.itemVisibleClass),r._animate=new o.ItemAnimate(r,a),r._animateChild=new o.ItemAnimate(r,r._child),r._isDefaultAnimate=r._animate instanceof f,u!==_&&(u.appendChild(a),i=G(_,u,!0),t=x(a,"x")+i.left,e=x(a,"y")+i.top,I(a,{transform:"translateX("+t+"px) translateY("+e+"px)"})),r._refreshDimensions()._refreshSortData(),r._child.removeAttribute("style"),l._itemShowHandler.start(r,!0),r._drag=h.dragEnabled?new o.ItemDrag(r):null,i=G(u,d,!0),s.containerDiffX=i.left,s.containerDiffY=i.top,s.start(),n},_.prototype.stop=function(){var t,e,i,n=this,r=n._data;if(!r.isActive)return n;if(n._isMigrating)return void n.finishMigration(r.currentEvent);for(t=n.getItem()._element,e=n.getGrid(),i=0;i