/*! * Muuri v0.5.0-dev * 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. */ /*! * muuriLayout v0.5.0-dev * Copyright (c) 2016 Niklas Rämö * Released under the MIT license */ !function(t,e){var i,n;if("object"==typeof module&&module.exports){try{i=require("velocity-animate")}catch(t){}try{n=require("hammerjs")}catch(t){}module.exports=e("Muuri",i,n)}else"function"==typeof define&&define.amd?define(["velocity-animate","hammerjs"],function(t,i){return e("Muuri",t,i)}):(i=t.Velocity||t.jQuery&&t.jQuery.Velocity,n=t.Hammer,t.Muuri=e("Muuri",i,n))}("undefined"!=typeof window?window:this,function(t,e,i,n){"use strict";function r(t,e){var i,n,o,s=this;if(st||(st=document.body,wt=X()),t=s._element=typeof t===lt?rt.querySelector(t):t,!st.contains(t))throw new it("Container element must be an existing DOM element");i=s._settings=Q(r.defaultOptions,e),pt[s._id=++yt]=s,s._isDestroyed=!1,s._layout=null,s._emitter=new r.Emitter,s._setSortGroups(i.dragSortGroup),s._sortConnections=i.dragSortWith&&i.dragSortWith.length?[].concat(i.dragSortWith):null,s._itemShowHandler=typeof i.showAnimation===at?i.showAnimation(i.showDuration,i.showEasing,i.visibleStyles):F("show",i.showDuration,i.showEasing,i.visibleStyles),s._itemHideHandler=typeof i.hideAnimation===at?i.hideAnimation(i.hideDuration,i.hideEasing,i.hiddenStyles):F("hide",i.hideDuration,i.hideEasing,i.hiddenStyles),I(t,i.containerClass),s._items=[],typeof(n=i.items)===lt?A(s._element.children).forEach(function(t){("*"===n||vt(t,n))&&s._items.push(new r.Item(s,t))}):(tt.isArray(n)||g(n))&&(s._items=A(n).map(function(t){return new r.Item(s,t)})),(o=!0===(o=i.layoutOnResize)?0:typeof o===dt?o:-1)>=0&&Z.addEventListener("resize",s._resizeHandler=v(function(){s.refreshItems().layout()},o)),i.layoutOnInit&&s.layout(!0)}function o(t,e){var i,n=this,o=t._settings;n._id=++yt,ct[n._id]=n,n._isDestroyed=!1,e.parentNode!==t._element&&t._element.appendChild(e),I(e,o.itemClass),I(e,(i="none"===D(e,"display"))?o.itemHiddenClass:o.itemVisibleClass),n._gridId=t._id,n._element=e,n._child=e.children[0],n._animate=new r.ItemAnimate(n,e),n._animateChild=new r.ItemAnimate(n,n._child),n._isDefaultAnimate=n._animate instanceof a,n._isActive=!i,n._isPositioning=!1,n._isHidden=i,n._isHiding=!1,n._isShowing=!1,n._layoutAnimateInitRead=null,n._layoutAnimateInitWrite=null,n._visibilityQueue=[],n._layoutQueue=[],n._left=0,n._top=0,b(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 r.ItemMigrate(n),n._release=new r.ItemRelease(n),n._drag=o.dragEnabled?new r.ItemDrag(n):null}function s(){this._events={},this._isDestroyed=!1}function a(e,i){this._item=e,this._element=i,this._id=t+"-"+ ++yt,this._callback=null,this._animateTo=null,this._isAnimating=!1,this._isDestroyed=!1}function l(t){var e=this;e._itemId=t._id,e._isDestroyed=!1,e.isActive=!1,e.container=!1,e.containerDiffX=0,e.containerDiffY=0}function d(t){var e=this;e._itemId=t._id,e._isDestroyed=!1,e.isActive=!1,e.isPositioningStarted=!1,e.containerDiffX=0,e.containerDiffY=0}function h(e){if(!i)throw new it("["+t+"] required dependency Hammer is not defined.");var n,r,o=this,s=e._element,a=e.getGrid(),l=a._settings,d=typeof l.dragStartPredicate===at?l.dragStartPredicate:h.defaultStartPredicate,f=ht;o._itemId=e._id,o._gridId=a._id,o._hammer=n=new i.Manager(s),o._isDestroyed=!1,o._isMigrating=!1,o._data={},o._resolveStartPredicate=function(t){o._isDestroyed||f!==ft||(f=ut,o.onStart(t))},o._scrollListener=function(t){o.onScroll(t)},o._checkSortOverlap=v(function(){o._data.isActive&&o.checkOverlap()},l.dragSortInterval),o._sortPredicate=typeof l.dragSortPredicate===at?l.dragSortPredicate:h.defaultSortPredicate,o.reset(),n.add(new i.Pan({event:"drag",pointers:1,threshold:0,direction:i.DIRECTION_ALL})),n.add(new i.Press({event:"draginit",pointers:1,threshold:1e3,time:0})),c(l.dragHammerSettings)&&n.set(l.dragHammerSettings),n.on("draginit dragstart dragmove",function(t){f===ht&&(f=ft),f===ft?!0===(r=d(o.getItem(),t))?(f=ut,o.onStart(t)):!1===r&&(f=_t):f===ut&&o._data.isActive&&o.onMove(t)}).on("dragend dragcancel draginitup",function(t){var e=f===ut;d(o.getItem(),t),f=ht,e&&o._data.isActive&&o.onEnd(t)}),s.addEventListener("dragstart",B,!1)}function f(t,e){var i=t.length,n=i-1;return e>n?n:e<0?et.max(i+e,0):e}function u(t,e,i){if(!(t.length<2)){var n,r=f(t,e),o=f(t,i);r!==o&&(n=t[r],t[r]=t[o],t[o]=n)}}function _(t,e,i){if(!(t.length<2)){var n=f(t,e),r=f(t,i);n!==r&&t.splice(r,0,t.splice(n,1)[0])}}function p(t){var e,i=[],n=t.length;if(n)for(i[0]=t[0],e=1;e0?function(r){i!==n&&(i=Z.clearTimeout(i),"finish"===r&&t()),"cancel"!==r&&"finish"!==r&&(i=Z.setTimeout(function(){i=n,t()},e))}:function(e){"cancel"!==e&&t()}}function D(t,e){return Z.getComputedStyle(t,null).getPropertyValue("transform"===e?Dt.styleName||e:e)}function w(t,e){return parseFloat(D(t,e))||0}function S(t,e){return parseFloat((D(t,"transform")||"").replace("matrix(","").split(",")["x"===e?4:5])||0}function b(t,e){var i,n,r,o=$.keys(e);for(r=0;rs?1:0:sa?1:0))return d;return d}function M(t,e){var i,n,r,o=[],s=t.concat();for(r=0;r-1&&(o.push(i),s.splice(n,1));return tt.prototype.splice.apply(t,[0,t.length].concat(o).concat(s)),t}function N(t,e,i){return i.width&&i.height&&t>=i.left&&t=i.top&&e0;return{start:function(t,o,s){r&&n?o?((t._isDefaultAnimate?x:b)(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 W(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 V(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:s._items.length+t,s._items[e]||null;for(i=null,r=0;r0?n:0;return s},o.prototype._refreshSortData=function(){var t,e,i=this;return i._isDestroyed||(t={},(e=i.getGrid()._settings.sortData)&&$.keys(e).forEach(function(n){t[n]=e[n](i,i._element)}),i._sortData=t),i},o.prototype._layout=function(t,e){var i,n,r,o,s,a,l,d,h,f=this,u=f._element,_=f._isPositioning,p=f._migrate,c=f._release,g=c.isActive&&!1===c.isPositioningStarted;if(f._isDestroyed)return f;if(i=f.getGrid(),n=i._settings,r=g?n.dragReleaseDuration:n.layoutDuration,o=g?n.dragReleaseEasing:n.layoutEasing,s=!t&&!f._skipNextLayoutAnimation&&r>0,_&&V(f._layoutQueue,!0,f),g&&(c.isPositioningStarted=!0),typeof e===at&&f._layoutQueue.push(e),a=c.isActive?c.containerDiffX:p.isActive?p.containerDiffX:0,l=c.isActive?c.containerDiffY:p.isActive?p.containerDiffY:0,s){if(d=S(u,"x")-a,h=S(u,"y")-l,f._left===d&&f._top===h)return void f._stopLayout()._finishLayout();_||(f._isPositioning=!0,I(u,n.itemPositioningClass)),f._animate.start({translateX:d+a+"px",translateY:h+l+"px"},{translateX:f._left+a+"px",translateY:f._top+l+"px"},{duration:r,easing:o,onFinish:function(){f._finishLayout()}})}else f._stopLayout(),f._skipNextLayoutAnimation=!1,b(u,{transform:"translateX("+(f._left+a)+"px) translateY("+(f._top+l)+"px)"}),f._finishLayout();return f},o.prototype._finishLayout=function(){var t=this;return t._isDestroyed?t:(t._isPositioning&&(t._isPositioning=!1,C(t._element,t.getGrid()._settings.itemPositioningClass)),t._release.isActive&&t._release.stop(),t._migrate.isActive&&t._migrate.stop(),V(t._layoutQueue,!1,t),t)},o.prototype._stopLayout=function(t){var e=this;return e._isDestroyed||!e._isPositioning?e:(e._animate.stop(),C(e._element,e.getGrid()._settings.itemPositioningClass),e._isPositioning=!1,t&&V(e._layoutQueue,!0,e),e)},o.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:r._isShowing||r._isHidden?(i=r.getGrid(),n=i._settings,r._isShowing?(a&&s.push(a),t&&i._itemShowHandler.stop(r)):(r._isHidden&&i._itemHideHandler.stop(r),V(s,!0,r),r._isActive=r._isShowing=!0,r._isHiding=r._isHidden=!1,a&&s.push(a),b(o,{display:"block"}),C(o,n.itemHiddenClass),I(o,n.itemVisibleClass)),i._itemShowHandler.start(r,t,function(){r._isShowing=!1,V(s,!1,r)}),r):(a&&a(!1,r),r)},o.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&&r._isHidden?(a&&a(!1,r),r):(r._isHiding?(a&&s.push(a),t&&i._itemHideHandler.stop(r)):(r._isShowing&&i._itemShowHandler.stop(r),V(s,!0,r),r._isHidden=r._isHiding=!0,r._isActive=r._isShowing=!1,a&&s.push(a),I(o,n.itemHiddenClass),C(o,n.itemVisibleClass)),i._itemHideHandler.start(r,t,function(){r._isHiding=!1,r._stopLayout(!0),b(o,{display:"none"}),V(s,!1,r)}),r))},o.prototype._destroy=function(t){var e,i,r,o=this,s=o._element;return o._isDestroyed?o:(e=o.getGrid(),i=e._settings,r=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"),V(o._visibilityQueue,!0,o),C(s,i.itemPositioningClass),C(s,i.itemDraggingClass),C(s,i.itemReleasingClass),C(s,i.itemClass),C(s,i.itemVisibleClass),C(s,i.itemHiddenClass),r>-1&&e._items.splice(r,1),t&&s.parentNode.removeChild(s),ct[o._id]=n,o._isActive=o._isPositioning=o._isHiding=o._isShowing=!1,o._isDestroyed=o._isHidden=!0,o)},s.prototype.on=function(t,e){if(this._isDestroyed)return this;var i=this._events[t]||[];return i.push(e),this._events[t]=i,this},s.prototype.once=function(t,e){var i=this;return this.on(t,function n(){i.off(t,n),e.apply(null,arguments)})},s.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},s.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;rg&&(e=o,g=r));return g=h&&{grid:_,index:e,action:f}},h.prototype.destroy=function(){var t=this;return t._isDestroyed||(t.stop(),t._hammer.destroy(),t.getItem()._element.removeEventListener("dragstart",B,!1),t._isDestroyed=!0),t},h.prototype.getItem=function(){return ct[this._itemId]||null},h.prototype.getGrid=function(){return pt[this._gridId]||null},h.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},h.prototype.bindScrollListeners=function(){var t,e=this,i=e.getGrid()._element,n=e._data.container,r=R(e.getItem()._element);for(n!==i&&(r=p(r.concat(i).concat(R(i)))),t=0;tt.height&&(u.left>0&&f.push({left:0,top:t.height,width:u.left,height:1/0}),u.left+u.widtht.width&&(u.top>0&&f.push({left:t.width,top:0,width:1/0,height:u.top}),u.top+u.height.49&&s.height>.49&&(r&&s.tope.left+e.width&&i.push({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.push({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}]},U.doRectsOverlap=function(t,e){return!(t.left+t.width<=e.left||e.left+e.width<=t.left||t.top+t.height<=e.top||e.top+e.height<=t.top)},U.isRectWithinRect=function(t,e){return t.left>=e.left&&t.top>=e.top&&t.left+t.width<=e.left+e.width&&t.top+t.height<=e.top+e.height},U.purgeRects=function(t){for(var e,i,n,r=t.length;r--;)for(i=t[r],e=t.length;e--;)if(n=t[e],r!==e&&U.isRectWithinRect(i,n)){t.splice(r,1);break}return t},U.sortRectsTopLeft=function(t,e){return t.top-e.top||t.left-e.left},U.sortRectsLeftTop=function(t,e){return t.left-e.left||t.top-e.top},r});