/*! * Muuri v0.5.3 * 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.3 * Copyright (c) 2016 Niklas Rämö * Released under the MIT license */ !function(t,e){var i;if("object"==typeof module&&module.exports){try{i=require("hammerjs")}catch(t){}module.exports=e("Muuri",i)}else"function"==typeof define&&define.amd?define(["hammerjs"],function(t){return e("Muuri",t)}):t.Muuri=e("Muuri",t.Hammer)}("undefined"!=typeof window?window:this,function(t,e,i){"use strict";function n(t,e){var i,r,s,o=this;if(J||(J=document.body,mt=P()),t=o._element=typeof t===tt?Z.querySelector(t):t,!J.contains(t))throw new q("Container element must be an existing DOM element");typeof(i=o._settings=function(t,e){var i=p({},t);return i=e?p(i,e):i,i.visibleStyles=(e||{}).visibleStyles||(t||{}).visibleStyles,i.hiddenStyles=(e||{}).hiddenStyles||(t||{}).hiddenStyles,i}(n.defaultOptions,e)).dragSort!==K&&(i.dragSort=!!i.dragSort),ft[o._id=++_t]=o,o._isDestroyed=!1,o._layout=null,o._emitter=new n.Emitter,o._itemShowHandler=M("show",i),o._itemHideHandler=M("hide",i),b(t,i.containerClass),o._items=[],typeof(r=i.items)===tt?x(o._element.children).forEach(function(t){("*"===r||pt(t,r))&&o._items.push(new n.Item(o,t))}):(j.isArray(r)||_(r))&&(o._items=x(r).map(function(t){return new n.Item(o,t)})),(s=!0===(s=i.layoutOnResize)?0:typeof s===et?s:-1)>=0&&V.addEventListener("resize",o._resizeHandler=m(function(){o.refreshItems().layout()},s)),i.layoutOnInit&&o.layout(!0)}function r(t,e){var i,r=t._settings;this._id=++_t,ut[this._id]=this,this._isDestroyed=!1,e.parentNode!==t._element&&t._element.appendChild(e),b(e,r.itemClass),b(e,(i="none"===v(e,"display"))?r.itemHiddenClass:r.itemVisibleClass),this._gridId=t._id,this._element=e,this._child=e.children[0],this._animate=new n.ItemAnimate(this,e),this._animateChild=new n.ItemAnimate(this,this._child),this._isActive=!i,this._isPositioning=!1,this._isHidden=i,this._isHiding=!1,this._isShowing=!1,this._visibilityQueue=[],this._layoutQueue=[],this._left=0,this._top=0,C(e,{left:"0",top:"0",transform:S(0,0),display:i?"none":"block"}),this._refreshDimensions()._refreshSortData(),i?t._itemHideHandler.start(this,!0):t._itemShowHandler.start(this,!0),this._migrate=new n.ItemMigrate(this),this._release=new n.ItemRelease(this),this._drag=r.dragEnabled?new n.ItemDrag(this):null}function s(){this._events={},this._isDestroyed=!1}function o(t,e){this._item=t,this._element=e,this._animation=null,this._propsTo=null,this._isDestroyed=!1}function a(t){this._itemId=t._id,this._isDestroyed=!1,this.isActive=!1,this.container=!1,this.containerDiffX=0,this.containerDiffY=0}function h(t){this._itemId=t._id,this._isDestroyed=!1,this.isActive=!1,this.isPositioningStarted=!1,this.containerDiffX=0,this.containerDiffY=0}function l(i){if(!e)throw new q("["+t+"] required dependency Hammer is not defined.");var n,r,s=this,o=i._element,a=i.getGrid(),h=a._settings,d=typeof h.dragStartPredicate===K?h.dragStartPredicate:l.defaultStartPredicate,f=at;s._itemId=i._id,s._gridId=a._id,s._hammer=n=new e.Manager(o),s._isDestroyed=!1,s._isMigrating=!1,s._data={},s._resolveStartPredicate=function(t){s._isDestroyed||f!==ht||(f=lt,s.onStart(t))},s._scrollListener=function(t){s.onScroll(t)},s._checkSortOverlap=m(function(){s._data.isActive&&s.checkOverlap()},h.dragSortInterval),s._sortPredicate=typeof h.dragSortPredicate===K?h.dragSortPredicate:l.defaultSortPredicate,s.reset(),n.add(new e.Pan({event:"drag",pointers:1,threshold:0,direction:e.DIRECTION_ALL})),n.add(new e.Press({event:"draginit",pointers:1,threshold:1e3,time:0})),c(h.dragHammerSettings)&&n.set(h.dragHammerSettings),n.on("draginit dragstart dragmove",function(t){f===at&&(f=ht),f===ht?!0===(r=d(s.getItem(),t))?(f=lt,s.onStart(t)):!1===r&&(f=dt):f===lt&&s._data.isActive&&s.onMove(t)}).on("dragend dragcancel draginitup",function(t){var e=f===lt;d(s.getItem(),t),f=at,e&&s._data.isActive&&s.onEnd(t)}),o.addEventListener("dragstart",T,!1)}function d(t,e,i){var n=t.length,r=W.max(0,i?n:n-1);return e>r?r:e<0?W.max(r+e+1,0):e}function f(t,e,i){if(!(t.length<2)){var n,r=d(t,e),s=d(t,i);r!==s&&(n=t[r],t[r]=t[s],t[s]=n)}}function u(t,e,i){if(!(t.length<2)){var n=d(t,e),r=d(t,i);n!==r&&t.splice(r,0,t.splice(n,1)[0])}}function c(t){return"object"==typeof t&&"[object Object]"===Q.prototype.toString.call(t)}function _(t){var e=Q.prototype.toString.call(t);return"[object HTMLCollection]"===e||"[object NodeList]"===e}function p(t,e){return Q.keys(e).forEach(function(i){var n=c(e[i]);c(t[i])&&n?(t[i]=p({},t[i]),t[i]=p(t[i],e[i])):t[i]=n?p({},e[i]):j.isArray(e[i])?e[i].concat():e[i]}),t}function g(t,e,i){var n=typeof i===et?i:-1;t.splice.apply(t,[n<0?t.length-n+1:n,0].concat(e))}function m(t,e){var n;return e>0?function(r){n!==i&&(n=V.clearTimeout(n),"finish"===r&&t()),"cancel"!==r&&"finish"!==r&&(n=V.setTimeout(function(){n=i,t()},e))}:function(e){"cancel"!==e&&t()}}function y(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}function v(t,e){return V.getComputedStyle(t,null).getPropertyValue("transform"===e?gt.styleName||e:e)}function D(t,e){return parseFloat(v(t,e))||0}function w(t,e){return parseFloat((v(t,"transform")||"").replace("matrix(","").split(",")["x"===e?4:5])||0}function S(t,e){return"translateX("+t+"px) translateY("+e+"px)"}function I(t,e){var i,n={},r=Q.keys(e);for(i=0;i0;return o=c(o)?o:null,{start:function(t,e,n){o?(it.cancel(rt,t._id),!a||e?(t._animateChild.isAnimating()?t._animateChild.stop(o):C(t._child,o),n&&n()):it.add(rt,t._id,function(){i=I(t._child,o)},function(){t._animateChild.start(i,o,{duration:r,easing:s,onFinish:n})})):n&&n()},stop:function(t,e){it.cancel(rt,t._id),t._animateChild.stop(e)}}}function N(t,e,i){var n,r=t.splice(0,t.length);for(n=0;n=i.left&&t=i.top&&e-1&&r.splice(l,1),i===st||i===ot?r.unshift(i+n):r.push(i+n),s[i+n]=[a,h],!e&&(e=o(t))},cancel:function(t,e){var n=r.indexOf(t+e);n>-1&&(r.splice(n,1),s[t+e]=i)}}}(),nt="layout",rt="visibility",st="move",ot="scroll",at=0,ht=1,lt=2,dt=3,ft={},ut={},ct=function(){},_t=0,pt=function(){var t=U.prototype,e=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector;return function(t,i){return e.call(t,i)}}(),gt=function(t){var e,n,r,s=t.charAt(0).toUpperCase()+t.slice(1),o=["","Webkit","Moz","O","ms"];for(r=0;r-1&&(r.splice(o,1),!r.length))return s;for(h=0;ho?1:0:oa?1:0))return l;return l}(e,i,o,t)||O(e,i,o,n||(n=Y(h)))});else{if(!j.isArray(t))return this;!function(t,e){var i,n,r,s=[],o=t.concat();for(r=0;r-1&&(s.push(i),o.splice(n,1));t.splice.apply(t,[0,t.length].concat(s).concat(o))}(r,t),o&&r.reverse()}return this._emit("sort",r.concat(),h),a&&this.layout("instant"===a,typeof a===K?a:i),this},n.prototype.move=function(t,e,n){if(this._isDestroyed||this._items.length<2)return this;var r,s,o=this._items,a=n||{},h=a.layout?a.layout:a.layout===i,l="swap"===a.action,d=l?"swap":"move",c=this._getItem(t),_=this._getItem(e);return c&&_&&c!==_&&(r=o.indexOf(c),s=o.indexOf(_),(l?f:u)(o,r,s),this._emit("move",{item:c,fromIndex:r,toIndex:s,action:d}),h&&this.layout("instant"===h,typeof h===K?h:i)),this},n.prototype.send=function(t,e,n,r){if(this._isDestroyed||e._isDestroyed||this===e||!(t=this._getItem(t)))return this;var s=e,o=r||{},a=o.appendTo||J,h=o.layoutSender?o.layoutSender:o.layoutSender===i,l=o.layoutReceiver?o.layoutReceiver:o.layoutReceiver===i;return t._migrate.start(s,n,a),t._migrate.isActive&&t.isActive()&&(h&&this.layout("instant"===h,typeof h===K?h:i),l&&s.layout("instant"===l,typeof l===K?l:i)),this},n.prototype.destroy=function(t){if(this._isDestroyed)return this;var e,n=this._element,r=this._items.concat();for(this._resizeHandler&&V.removeEventListener("resize",this._resizeHandler),e=0;e-1?t:i.length+t]||null;if(t instanceof r)return t._gridId===this._id?t:null;for(e=0;e0?t:0;return this},r.prototype._refreshSortData=function(){var t=this;if(t._isDestroyed)return t;var e={},i=t.getGrid()._settings.sortData;return i&&Q.keys(i).forEach(function(n){e[n]=i[n](t,t._element)}),t._sortData=e,t},r.prototype._layout=function(t,e){var i=this;if(i._isDestroyed)return i;var n,r,s,o,a,h,l=i._element,d=i._isPositioning,f=i._migrate,u=i._release,c=u.isActive&&!1===u.isPositioningStarted,_=i.getGrid()._settings,p=c?_.dragReleaseDuration:_.layoutDuration,g=c?_.dragReleaseEasing:_.layoutEasing,m=!t&&!i._skipNextLayoutAnimation&&p>0;return d&&N(i._layoutQueue,!0,i),c&&(u.isPositioningStarted=!0),typeof e===K&&i._layoutQueue.push(e),r=u.isActive?u.containerDiffX:f.isActive?f.containerDiffX:0,s=u.isActive?u.containerDiffY:f.isActive?f.containerDiffY:0,h={transform:S(i._left+r,i._top+s)},m?(i._isPositioning=!0,it.add(nt,i._id,function(){o=w(l,"x")-r,a=w(l,"y")-s},function(){if(i._left===o&&i._top===a)return d&&i._stopLayout(!1,h),i._isPositioning=!1,i._finishLayout();!d&&b(l,_.itemPositioningClass),i._animate.start({transform:S(o+r,a+s)},h,{duration:p,easing:g,onFinish:function(){i._finishLayout()}})}),i):(d&&it.cancel(nt,i._id),n=i._animate.isAnimating(),i._stopLayout(!1,h),!n&&C(l,h),i._skipNextLayoutAnimation=!1,i._finishLayout())},r.prototype._finishLayout=function(){return this._isDestroyed?this:(this._isPositioning&&(this._isPositioning=!1,A(this._element,this.getGrid()._settings.itemPositioningClass)),this._release.isActive&&this._release.stop(),this._migrate.isActive&&this._migrate.stop(),N(this._layoutQueue,!1,this),this)},r.prototype._stopLayout=function(t,e){return this._isDestroyed||!this._isPositioning?this:(it.cancel(nt,this._id),this._animate.stop(e),A(this._element,this.getGrid()._settings.itemPositioningClass),this._isPositioning=!1,t&&N(this._layoutQueue,!0,this),this)},r.prototype._show=function(t,e){var i=this;if(i._isDestroyed)return i;var n=i._element,r=i._visibilityQueue,s=typeof e===K?e:null,o=i.getGrid(),a=o._settings;return i._isShowing||i._isHidden?i._isShowing&&!t?(s&&r.push(s),i):(i._isShowing||(N(r,!0,i),A(n,a.itemHiddenClass),b(n,a.itemVisibleClass),!i._isHiding&&C(n,{display:"block"})),s&&r.push(s),i._isActive=i._isShowing=!0,i._isHiding=i._isHidden=!1,t?(o._itemShowHandler.stop(i,a.visibleStyles),i._isShowing=!1,N(r,!1,i)):o._itemShowHandler.start(i,t,function(){i._isHidden||(i._isShowing=!1,N(r,!1,i))}),i):(s&&s(!1,i),i)},r.prototype._hide=function(t,e){var i=this;if(i._isDestroyed)return i;var n=i._element,r=i._visibilityQueue,s=typeof e===K?e:null,o=i.getGrid(),a=o._settings;return!i._isHiding&&i._isHidden?(s&&s(!1,i),i):i._isHiding&&!t?(s&&r.push(s),i):(i._isHiding||(N(r,!0,i),b(n,a.itemHiddenClass),A(n,a.itemVisibleClass)),s&&r.push(s),i._isHidden=i._isHiding=!0,i._isActive=i._isShowing=!1,t?(o._itemHideHandler.stop(i,a.hiddenStyles),i._isHiding=!1,i._stopLayout(!0,{transform:S(0,0)}),C(n,{display:"none"}),N(r,!1,i)):o._itemHideHandler.start(i,t,function(){i._isHidden&&(i._isHiding=!1,i._stopLayout(!0,{transform:S(0,0)}),C(n,{display:"none"}),N(r,!1,i))}),i)},r.prototype._destroy=function(t){if(this._isDestroyed)return this;var e=this._element,n=this.getGrid(),r=n._settings,s=n._items.indexOf(this);return this._release.destroy(),this._migrate.destroy(),this._stopLayout(!0,{}),n._itemShowHandler.stop(this,{}),n._itemHideHandler.stop(this,{}),this._drag&&this._drag.destroy(),this._animate.destroy(),this._animateChild.destroy(),N(this._visibilityQueue,!0,this),e.removeAttribute("style"),this._child.removeAttribute("style"),A(e,r.itemPositioningClass),A(e,r.itemDraggingClass),A(e,r.itemReleasingClass),A(e,r.itemClass),A(e,r.itemVisibleClass),A(e,r.itemHiddenClass),s>-1&&n._items.splice(s,1),t&&e.parentNode.removeChild(e),ut[this._id]=i,this._isActive=this._isPositioning=this._isHiding=this._isShowing=!1,this._isDestroyed=this._isHidden=!0,this},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,s=this._events[t]||[],o=s.length,a=arguments.length-1;if(o)for(s=s.concat(),r=0;rn&&r>d&&(d=r,a=s));return a}(t,h,u,d),_=0,p=0,g=-1;if(!c)return!1;for(c===h?(u.left=a.gridX+t._margin.left,u.top=a.gridY+t._margin.top):(_=c._left+c._border.left,p=c._top+c._border.top),s=0;sg&&(e=s,g=r));return g=d&&{grid:c,index:e,action:f}},l.prototype.destroy=function(){return this._isDestroyed||(this.stop(),this._hammer.destroy(),this.getItem()._element.removeEventListener("dragstart",T,!1),this._isDestroyed=!0),this},l.prototype.getItem=function(){return ut[this._itemId]||null},l.prototype.getGrid=function(){return ft[this._gridId]||null},l.prototype.reset=function(){var t=this._data;return t.isActive=!1,t.container=null,t.containingBlock=null,t.startEvent=null,t.currentEvent=null,t.scrollers=[],t.left=0,t.top=0,t.gridX=0,t.gridY=0,t.elementClientX=0,t.elementClientY=0,t.containerDiffX=0,t.containerDiffY=0,this},l.prototype.bindScrollListeners=function(){var t,e=this.getGrid()._element,i=this._data.container,n=L(this.getItem()._element);for(i!==e&&(n=function(t){var e,i=[],n=t.length;if(n)for(i[0]=t[0],e=1;et.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&&o.height>.49&&(r&&o.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}]},B.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)},B.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},B.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&&B.isRectWithinRect(i,n)){t.splice(r,1);break}return t},B.sortRectsTopLeft=function(t,e){return t.top-e.top||t.left-e.left},B.sortRectsLeftTop=function(t,e){return t.left-e.left||t.top-e.top},n});