From b6191f201f7745710ff1ba32125db2dd5c2ec977 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Thu, 18 Jun 2015 08:49:35 +1000 Subject: [PATCH 01/31] Adding draggable & resizable properties per widget, and preventing drag event if draggable turned off for widget --- dist/angular-gridster.min.js | 2 +- src/angular-gridster.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index e6fa53d7..19e0f356 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -5,4 +5,4 @@ * @version: 0.13.4 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.$element.css(this.gridster.isMobile?{marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}:{margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;nq+e?(c=E-q,A=e-c):q+s+e>b&&(c=b-q-s,A=e-c),C>r+g?(d=C-r,B=g-d):r+t+g>D&&(d=D-r-t,B=g-d),q+=c,r+=d,f.css({top:r+"px",left:q+"px"}),o(a),!0}function m(a){return!f.hasClass("gridster-item-moving")||f.hasClass("gridster-item-resizing")?!1:(A=B=0,p(a),!0)}function n(a){f.addClass("gridster-item-moving"),h.movingItem=i,h.updateHeight(i.sizeY),g.$apply(function(){h.draggable&&h.draggable.start&&h.draggable.start(a,f,j)})}function o(a){var b=i.row,c=i.col,e=h.draggable&&h.draggable.drag,k=h.draggable.scrollSensitivity,l=h.draggable.scrollSpeed,m=h.pixelsToRows(r),n=h.pixelsToColumns(q),o=h.getItems(m,n,i.sizeX,i.sizeY,i),p=0!==o.length;if(h.swapping===!0&&p){var s=h.getBoundingBox(o),t=s.sizeX===i.sizeX&&s.sizeY===i.sizeY,u=s.row===b,v=s.col===c,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)h.swapItems(i,o[0]);else if(x)return}else if(s.sizeX<=i.sizeX&&s.sizeY<=i.sizeY&&x)for(var y=i.row<=m?i.row:m+i.sizeY,z=i.col<=n?i.col:n+i.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var E=o[C],G=h.getItems(E.row+A,E.col+B,E.sizeX,E.sizeY,i);0===G.length&&h.putItem(E,E.row+A,E.col+B)}}h.pushing===!1&&p||(i.row=m,i.col=n),a.pageY-F.body.scrollTopb;++b)J[b].disable();J=[],h.draggable&&h.draggable.handle?(I=a.element(f[0].querySelectorAll(h.draggable.handle)),0===I.length&&(I=f)):I=f;for(var d=0,g=I.length;g>d;++d)J[d]=new e(I[d],k,l,m),J[d].enable();H=!0})},this.disable=function(){H!==!1&&c(function(){for(var a=0,b=J.length;b>a;++a)J[a].disable();J=[],H=!1})},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return f}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0)),(e.pushing!==!1||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var u=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||u)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;nq+e?(c=E-q,A=e-c):q+s+e>b&&(c=b-q-s,A=e-c),C>r+g?(d=C-r,B=g-d):r+t+g>D&&(d=D-r-t,B=g-d),q+=c,r+=d,f.css({top:r+"px",left:q+"px"}),o(a),!0}function m(a){return!f.hasClass("gridster-item-moving")||f.hasClass("gridster-item-resizing")?!1:(A=B=0,p(a),!0)}function n(a){f.addClass("gridster-item-moving"),h.movingItem=i,h.updateHeight(i.sizeY),g.$apply(function(){h.draggable&&h.draggable.start&&h.draggable.start(a,f,j)})}function o(a){var b=i.row,c=i.col,e=h.draggable&&h.draggable.drag,k=h.draggable.scrollSensitivity,l=h.draggable.scrollSpeed,m=h.pixelsToRows(r),n=h.pixelsToColumns(q),o=h.getItems(m,n,i.sizeX,i.sizeY,i),p=0!==o.length;if(h.swapping===!0&&p){var s=h.getBoundingBox(o),t=s.sizeX===i.sizeX&&s.sizeY===i.sizeY,u=s.row===b,v=s.col===c,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)h.swapItems(i,o[0]);else if(x)return}else if(s.sizeX<=i.sizeX&&s.sizeY<=i.sizeY&&x)for(var y=i.row<=m?i.row:m+i.sizeY,z=i.col<=n?i.col:n+i.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var E=o[C],G=h.getItems(E.row+A,E.col+B,E.sizeX,E.sizeY,i);0===G.length&&h.putItem(E,E.row+A,E.col+B)}}h.pushing===!1&&p||(i.row=m,i.col=n),a.pageY-F.body.scrollTopb;++b)J[b].disable();J=[],h.draggable&&h.draggable.handle?(I=a.element(f[0].querySelectorAll(h.draggable.handle)),0===I.length&&(I=f)):I=f;for(var d=0,g=I.length;g>d;++d)J[d]=new e(I[d],k,l,m),J[d].enable();H=!0})},this.disable=function(){H!==!1&&c(function(){for(var a=0,b=J.length;b>a;++a)J[a].disable();J=[],H=!1})},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return f}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0)),(e.pushing!==!1||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var u=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||u)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file diff --git a/src/angular-gridster.js b/src/angular-gridster.js index bf7bce8b..878a6ff9 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1358,6 +1358,11 @@ return false; } + // if draggable turned off for individual widget + if (!$target.draggable) { + return false; + } + switch (e.which) { case 1: // left mouse button @@ -2001,7 +2006,9 @@ minSizeX: 0, minSizeY: 0, maxSizeX: null, - maxSizeY: null + maxSizeY: null, + draggable: true, + resizable: true }; $optionsGetter.assign(scope, options); } @@ -2013,7 +2020,7 @@ $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], $getters = {}; var expressions = []; From 6c8cdcaf4ce9cd6f10369e80d02a051f1e0f0d6a Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 10:12:31 +1000 Subject: [PATCH 02/31] Adding draggable & resizable properties per widget --- dist/angular-gridster.min.css | 2 +- src/angular-gridster.js | 65 +++++++++++++++++++++++++++++++---- src/angular-gridster.less | 4 +++ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/dist/angular-gridster.min.css b/dist/angular-gridster.min.css index 9a92b6f4..38f1b6e4 100644 --- a/dist/angular-gridster.min.css +++ b/dist/angular-gridster.min.css @@ -1 +1 @@ -.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2;-webkit-transition:width .2s, height .3s;-moz-transition:width .2s, height .3s;-o-transition:width .2s, height .3s;transition:width .2s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-item.gridster-item-moving{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc} \ No newline at end of file +.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2;-webkit-transition:width .2s, height .3s;-moz-transition:width .2s, height .3s;-o-transition:width .2s, height .3s;transition:width .2s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-item.gridster-item-moving{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc}.action-not-allowed{cursor:not-allowed !important} \ No newline at end of file diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 878a6ff9..f7bc4294 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1134,6 +1134,7 @@ } else { document.addEventListener('mousemove', doEvent, false); document.addEventListener('mouseup', doEvent, false); + document.addEventListener('dragend', doEvent, false); } } } else if (theEvtObj.type.match(/move$/i)) { @@ -1177,12 +1178,13 @@ // nothing is required for the iOS touch model because capture is implied on touchstart if (target.msReleasePointerCapture) { target.msReleasePointerCapture(pointerId); - } else if (theEvtObj.type === 'mouseup' && numberOfKeys(lastXYById) === 0) { + } else if ((theEvtObj.type === 'mouseup' || theEvtObj.type === 'dragend') && numberOfKeys(lastXYById) === 0) { if (useSetReleaseCapture) { target.releaseCapture(); } else { document.removeEventListener('mousemove', doEvent, false); document.removeEventListener('mouseup', doEvent, false); + document.removeEventListener('dragend', doEvent, false); } } } @@ -1245,6 +1247,7 @@ target.addEventListener('mousemove', doEvent, false); target.addEventListener('mouseup', doEvent, false); + target.addEventListener('dragend', doEvent, false); } } else if (target.attachEvent && target.setCapture) { // legacy IE mode - mouse with capture @@ -1264,6 +1267,11 @@ window.event.returnValue = false; return false; }); + target.attachEvent('dragend', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); } }; @@ -1301,6 +1309,7 @@ target.removeEventListener('mousemove', doEvent, false); target.removeEventListener('mouseup', doEvent, false); + target.removeEventListener('dragend', doEvent, false); } } else if (target.detachEvent && target.setCapture) { // legacy IE mode - mouse with capture @@ -1308,6 +1317,7 @@ target.detachEvent('onmousedown'); target.detachEvent('onmousemove'); target.detachEvent('onmouseup'); + target.detachEvent('ondragend'); } }; @@ -1337,10 +1347,17 @@ var inputTags = ['select', 'input', 'textarea', 'button']; function mouseDown(e) { + if (inputTags.indexOf(e.target.nodeName.toLowerCase()) !== -1) { return false; } + // if draggable turned off for individual widget + if (itemOptions.draggable === false) { + angular.element(document).find('body').addClass('action-not-allowed'); + return false; + } + var $target = angular.element(e.target); // exit, if a resize handle was hit @@ -1358,11 +1375,6 @@ return false; } - // if draggable turned off for individual widget - if (!$target.draggable) { - return false; - } - switch (e.which) { case 1: // left mouse button @@ -1441,6 +1453,12 @@ } function mouseUp(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + angular.element(document).find('body').removeClass('action-not-allowed'); + return false; + } + if (!$el.hasClass('gridster-item-moving') || $el.hasClass('gridster-item-resizing')) { return false; } @@ -1624,6 +1642,10 @@ this.destroy = function() { this.disable(); }; + + this.updateDraggable = function(draggable) { + itemOptions.draggable = draggable; + }; } return GridsterDraggable; @@ -1661,6 +1683,13 @@ var savedDraggable; function mouseDown(e) { + + // if resize has been individually turned off for this widget + if (itemOptions.resizable === false) { + angular.element(document).find('body').addClass('action-not-allowed'); + return false; + } + switch (e.which) { case 1: // left mouse button @@ -1716,6 +1745,11 @@ } function mouseMove(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + return false; + } + var maxLeft = gridster.curWidth - 1; // Get the current mouse position. @@ -1791,6 +1825,12 @@ } function mouseUp(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + angular.element(document).find('body').removeClass('action-not-allowed'); + return false; + } + // restore draggable setting to its original state if (gridster.draggable.enabled !== savedDraggable) { gridster.draggable.enabled = savedDraggable; @@ -1941,6 +1981,10 @@ handles[c].destroy(); } }; + + this.updateResizable = function(resizable) { + itemOptions.resizable = resizable; + }; } return GridsterResizable; }]) @@ -1990,6 +2034,7 @@ item = controllers[1]; scope.gridster = gridster; + scope.myGridsterItem = scope.$eval(attrs.gridsterItem); // bind the item's position properties // options can be an object specified by gridster-item="object" @@ -2126,6 +2171,14 @@ updateDraggable(); }); + // need to dynamically update draggable/resizable of individual gridster item if properties change + scope.$watch("myGridsterItem.draggable", function(newVal) { + draggable.updateDraggable(newVal); + }, true); + scope.$watch("myGridsterItem.resizable", function(newVal) { + resizable.updateResizable(newVal); + }, true); + function whichTransitionEvent() { var el = document.createElement('div'); var transitions = { diff --git a/src/angular-gridster.less b/src/angular-gridster.less index 626cd06a..d85f92ac 100644 --- a/src/angular-gridster.less +++ b/src/angular-gridster.less @@ -170,4 +170,8 @@ .gridster .gridster-item:hover .handle-se { border-color: transparent transparent #ccc; +} + +.action-not-allowed { + cursor: not-allowed !important; } \ No newline at end of file From 35d2cf27b78e9ed8694ab8ee52adefdf06f0318d Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 10:14:00 +1000 Subject: [PATCH 03/31] Updating version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd31790d..9663fa50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.4", + "version": "0.13.5", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", From 8ddc28b74aaddf47ffee35d1e265504cfcd93e89 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 11:48:06 +1000 Subject: [PATCH 04/31] Removing module loading --- src/angular-gridster.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index f7bc4294..d5b3181c 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1,19 +1,4 @@ -/*global define:true*/ -(function(root, factory) { - - 'use strict'; - - if (typeof define === 'function' && define.amd) { - // AMD - define(['angular'], factory); - } else if (typeof exports === 'object') { - // CommonJS - module.exports = factory(require('angular')); - } else { - // Browser, nothing "exported". Only registered as a module with angular. - factory(root.angular); - } -}(this, function(angular) { +(function(angular) { 'use strict'; @@ -2234,4 +2219,4 @@ ; -})); +})(angular); From 674e2f64fcff22403c8fe3631e9cb84a4e648653 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 12:08:48 +1000 Subject: [PATCH 05/31] Version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 04907f8e..b5353fe1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.4", + "version": "0.13.5", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", From 862b040897e6196e0657edcb142144be6d2ab224 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Fri, 3 Jul 2015 19:43:59 +1000 Subject: [PATCH 06/31] Adding support for setting height of gridster to screen's height --- src/angular-gridster.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index d5b3181c..382c9946 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -636,6 +636,12 @@ if (typeof gridster.rowHeight === 'string') { if (gridster.rowHeight === 'match') { gridster.curRowHeight = Math.round(gridster.curColWidth); + } else if (gridster.rowHeight.indexOf('screen-height') !== -1) { + var body = document.getElementsByTagName('body')[0], + screenHeight = body.clientHeight; + var split = gridster.rowHeight.split("screen-height"); + var additional = split.length > 1 ? parseInt(split[1].replace(/\s/g, "")) : 0; + gridster.curRowHeight = (screenHeight + additional) / gridster.minRows; } else if (gridster.rowHeight.indexOf('*') !== -1) { gridster.curRowHeight = Math.round(gridster.curColWidth * gridster.rowHeight.replace('*', '').replace(' ', '')); } else if (gridster.rowHeight.indexOf('/') !== -1) { @@ -1459,7 +1465,7 @@ $el.addClass('gridster-item-moving'); gridster.movingItem = item; - gridster.updateHeight(item.sizeY); + //gridster.updateHeight(item.sizeY); scope.$apply(function() { if (gridster.draggable && gridster.draggable.start) { gridster.draggable.start(event, $el, itemOptions); From 916f5d17d5b15f5bad55a387c718b68dc40daadb Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 6 Jul 2015 21:14:17 +1000 Subject: [PATCH 07/31] Elder item's positions are respected over newer item's, so that newer item is positioned only where it can be fitted in. Code is pretty rough, needs tidying up, etc. --- src/angular-gridster.js | 148 ++++++++++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 37 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 382c9946..aecfcffd 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -173,8 +173,25 @@ for (var h = 0; h < sizeY; ++h) { for (var w = 0; w < sizeX; ++w) { var item = this.getItem(row + h, column + w, excludeItems); - if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && items.indexOf(item) === -1) { - items.push(item); + if (item) + { + //console.log("item " + item.id + " found at row " + String(row + h) + " col " + String(column + w)); + if(!excludeItems || excludeItems.indexOf(item) === -1) + { + //console.log("not in exclude items"); + for (var i = 0, len = items.length, foundItem = false; i < len; i++) + { + if (items[i].id === item.id) { + foundItem = true; + break; + } + } + + if (foundItem === false) { + //console.log("not in items"); + items.push(item); + } + } } } } @@ -293,7 +310,7 @@ * @param {Number} column (Optional) Specifies the items column index * @param {Array} ignoreItems */ - this.putItem = function(item, row, column, ignoreItems) { + this.putItem = function(item, row, column, ignoreItems, noPush) { // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; @@ -330,12 +347,19 @@ item.oldRow = item.row = row; item.oldColumn = item.col = column; - this.moveOverlappingItems(item, ignoreItems); + if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); + + if (item.row >= 19 || item.col >= 19) { + this.removeItem(item); + return; + } + + console.log("putItem " + item.row + ", " + item.col); - if (!this.grid[row]) { - this.grid[row] = []; + if (!this.grid[item.row]) { + this.grid[item.row] = []; } - this.grid[row][column] = item; + this.grid[item.row][item.col] = item; if (this.movingItem === item) { this.floatItemUp(item); @@ -368,23 +392,44 @@ * @param {Array} ignoreItems */ this.moveOverlappingItems = function(item, ignoreItems) { - // don't move item, so ignore it - if (!ignoreItems) { - ignoreItems = [item]; - } else if (ignoreItems.indexOf(item) === -1) { - ignoreItems = ignoreItems.slice(0); - ignoreItems.push(item); - } - - // get the items in the space occupied by the item's coordinates - var overlappingItems = this.getItems( - item.row, - item.col, - item.sizeX, - item.sizeY, - ignoreItems - ); - this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + + if (this.pushing === false) + { + ignoreItems = this.getItems(0, 0, 20, 20, [item]); + + console.log("no pushing, " + ignoreItems.length + " not to be moved"); + // get the items in the space occupied by the item's coordinates + var overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY); + + if (overlappingItems.length > 0) + { + this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); + } + } + else + { + // don't move item, so ignore it + if (!ignoreItems) { + ignoreItems = [item]; + } else if (ignoreItems.indexOf(item) === -1) { + ignoreItems = ignoreItems.slice(0); + ignoreItems.push(item); + } + + // get the items in the space occupied by the item's coordinates + var overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY, + ignoreItems + ); + this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + } }; /** @@ -415,12 +460,39 @@ } } - // move each item down from the top row in its column to the row - for (i = 0, l = items.length; i < l; ++i) { - item = items[i]; - var rowsToMove = newRow - topRows[item.col]; - this.moveItemDown(item, item.row + rowsToMove, ignoreItems); - ignoreItems.push(item); + //calculate next free position to place item + if (this.pushing === false) + { + var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + while (overlap.length > 0) { + + if (item.row == 19 && item.col == 19) { + console.log("NO FREE SPACE LEFT"); + return; + } + + if (item.row < 19) item.row++; + else { + item.row = 0; + item.col++; + } + + overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + } + + console.log("put item at row " + item.row); + this.putItem(item, item.row, item.col, ignoreItems, true); + } + else + { + + // move each item down from the top row in its column to the row + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var rowsToMove = newRow - topRows[item.col]; + this.moveItemDown(item, item.row + rowsToMove, ignoreItems); + ignoreItems.push(item); + } } }; @@ -437,9 +509,10 @@ } while (item.row < newRow) { ++item.row; - this.moveOverlappingItems(item, ignoreItems); + if (this.pushing === true) this.moveOverlappingItems(item, ignoreItems); } - this.putItem(item, item.row, item.col, ignoreItems); + console.log("put item at row " + item.row); + this.putItem(item, item.row, item.col, ignoreItems, true); }; /** @@ -1330,7 +1403,7 @@ mOffY = 0, minTop = 0, - maxTop = 9999, + maxTop = (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]), minLeft = 0, realdocument = $document[0]; @@ -1465,7 +1538,7 @@ $el.addClass('gridster-item-moving'); gridster.movingItem = item; - //gridster.updateHeight(item.sizeY); + gridster.updateHeight(item.sizeY); scope.$apply(function() { if (gridster.draggable && gridster.draggable.start) { gridster.draggable.start(event, $el, itemOptions); @@ -2044,7 +2117,8 @@ maxSizeX: null, maxSizeY: null, draggable: true, - resizable: true + resizable: true, + id: null }; $optionsGetter.assign(scope, options); } @@ -2056,7 +2130,7 @@ $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'id'], $getters = {}; var expressions = []; @@ -2131,7 +2205,7 @@ } if (changedX || changedY) { - item.gridster.moveOverlappingItems(item); + item.gridster.moveOverlappingItems(item, [], true); gridster.layoutChanged(); scope.$broadcast('gridster-item-resized', item); } From 0d4adfd64e665057a6297a322af35c8a939866dc Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 18:18:57 +1000 Subject: [PATCH 08/31] More work on locking a portlet into place --- src/angular-gridster.js | 78 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index aecfcffd..7ca7bf32 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -39,8 +39,8 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', - function(gridsterConfig, $timeout) { + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$scope', + function(gridsterConfig, $timeout, $scope) { var gridster = this; @@ -149,7 +149,9 @@ } } } - throw new Error('Unable to place item!'); + console.warn('Unable to place item!'); + + }; /** @@ -237,27 +239,6 @@ }; }; - - /** - * Removes an item from the grid - * - * @param {Object} item - */ - this.removeItem = function(item) { - for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { - var columns = this.grid[rowIndex]; - if (!columns) { - continue; - } - var index = columns.indexOf(item); - if (index !== -1) { - columns[index] = null; - break; - } - } - this.layoutChanged(); - }; - /** * Returns the item at a specified coordinate * @@ -350,7 +331,7 @@ if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); if (item.row >= 19 || item.col >= 19) { - this.removeItem(item); + item.removeItem(); return; } @@ -395,7 +376,7 @@ if (this.pushing === false) { - ignoreItems = this.getItems(0, 0, 20, 20, [item]); + ignoreItems = ignoreItems || this.getItems(0, 0, 20, 20, [item]); console.log("no pushing, " + ignoreItems.length + " not to be moved"); // get the items in the space occupied by the item's coordinates @@ -477,7 +458,10 @@ item.col++; } - overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + if (item.row + item.sizeY < 20 && item.col + item.sizeX < 20) { + overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + } + } console.log("put item at row " + item.row); @@ -868,7 +852,7 @@ } ]) - .controller('GridsterItemCtrl', function() { + .controller('GridsterItemCtrl', ['$scope', '$rootScope', function($scope, $rootScope) { this.$element = null; this.gridster = null; this.row = null; @@ -1056,7 +1040,22 @@ return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); }; - }) + this.removeItem = function() { + for (var rowIndex = 0, l = this.gridster.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.gridster.grid[rowIndex]; + if (!columns) { + continue; + } + var index = columns.indexOf(this); + if (index !== -1) { + columns[index] = null; + break; + } + } + this.gridster.layoutChanged(); + $rootScope.$broadcast('gridster-item-removed', this); + }; + }]) .factory('GridsterTouch', [function() { return function GridsterTouch(target, startEvent, moveEvent, endEvent) { @@ -1963,8 +1962,8 @@ gridster.movingItem = null; item.setPosition(item.row, item.col); - item.setSizeY(item.sizeY); - item.setSizeX(item.sizeX); + item.setSizeY(Math.min(gridster.maxRows - item.row, item.sizeY)); + item.setSizeX(Math.min(gridster.columns - item.col, item.sizeX)); scope.$apply(function() { if (gridster.resizable && gridster.resizable.stop) { @@ -2118,7 +2117,7 @@ maxSizeY: null, draggable: true, resizable: true, - id: null + onremove: null }; $optionsGetter.assign(scope, options); } @@ -2127,10 +2126,11 @@ } item.init($el, gridster); + if (optionsKey.id) item.id = optionsKey.id; $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'id'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'onremove'], $getters = {}; var expressions = []; @@ -2204,10 +2204,12 @@ $getters.sizeY.assign(scope, item.sizeY); } - if (changedX || changedY) { - item.gridster.moveOverlappingItems(item, [], true); - gridster.layoutChanged(); - scope.$broadcast('gridster-item-resized', item); + if (this.pushing === true) { + if (changedX || changedY) { + item.gridster.moveOverlappingItems(item, [], true); + gridster.layoutChanged(); + scope.$broadcast('gridster-item-resized', item); + } } } @@ -2276,7 +2278,7 @@ } catch (e) {} try { - gridster.removeItem(item); + item.removeItem(); } catch (e) {} try { From 0e4f4f84e10af7ee3c7ceba368abefd830dc59bb Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 19:11:00 +1000 Subject: [PATCH 09/31] Cleaning up --- src/angular-gridster.js | 157 +++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 84 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 7ca7bf32..f1965bd4 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -10,9 +10,10 @@ pushing: true, // whether to push other items out of the way floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size + locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns - rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. + rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. margins: [10, 10], // margins in between grid items outerMargin: true, isMobile: false, // toggle mobile view @@ -39,8 +40,8 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$scope', - function(gridsterConfig, $timeout, $scope) { + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$rootScope', + function(gridsterConfig, $timeout, $rootScope) { var gridster = this; @@ -175,25 +176,8 @@ for (var h = 0; h < sizeY; ++h) { for (var w = 0; w < sizeX; ++w) { var item = this.getItem(row + h, column + w, excludeItems); - if (item) - { - //console.log("item " + item.id + " found at row " + String(row + h) + " col " + String(column + w)); - if(!excludeItems || excludeItems.indexOf(item) === -1) - { - //console.log("not in exclude items"); - for (var i = 0, len = items.length, foundItem = false; i < len; i++) - { - if (items[i].id === item.id) { - foundItem = true; - break; - } - } - - if (foundItem === false) { - //console.log("not in items"); - items.push(item); - } - } + if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && items.indexOf(item) === -1) { + items.push(item); } } } @@ -239,6 +223,27 @@ }; }; + /** + * Removes an item from the grid + * + * @param {Object} item + */ + this.removeItem = function(item) { + for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.grid[rowIndex]; + if (!columns) { + continue; + } + var index = columns.indexOf(item); + if (index !== -1) { + columns[index] = null; + break; + } + } + this.layoutChanged(); + $rootScope.$broadcast('gridster-item-removed', item); + }; + /** * Returns the item at a specified coordinate * @@ -290,8 +295,9 @@ * @param {Number} row (Optional) Specifies the items row index * @param {Number} column (Optional) Specifies the items column index * @param {Array} ignoreItems + * @param {Boolean} leaveOverlapping (Optional) if true indicates that we don't want moveOverlappingItems() to be called */ - this.putItem = function(item, row, column, ignoreItems, noPush) { + this.putItem = function(item, row, column, ignoreItems, leaveOverlapping) { // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; @@ -328,15 +334,16 @@ item.oldRow = item.row = row; item.oldColumn = item.col = column; - if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); + if (leaveOverlapping !== true) { + this.moveOverlappingItems(item, ignoreItems); + } - if (item.row >= 19 || item.col >= 19) { - item.removeItem(); + // if have tried to find space for item but there is no room left + if (item.row >= this.maxRows - 1 || item.col >= this.columns - 1) { + this.removeItem(item); return; } - console.log("putItem " + item.row + ", " + item.col); - if (!this.grid[item.row]) { this.grid[item.row] = []; } @@ -374,11 +381,10 @@ */ this.moveOverlappingItems = function(item, ignoreItems) { - if (this.pushing === false) + if (this.locking === true) { - ignoreItems = ignoreItems || this.getItems(0, 0, 20, 20, [item]); + ignoreItems = ignoreItems || this.getItems(0, 0, this.columns, this.maxRows, [item]); - console.log("no pushing, " + ignoreItems.length + " not to be moved"); // get the items in the space occupied by the item's coordinates var overlappingItems = this.getItems( item.row, @@ -386,13 +392,11 @@ item.sizeX, item.sizeY); - if (overlappingItems.length > 0) - { + // move this item down if it overlaps any + if (overlappingItems.length > 0) { this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); } - } - else - { + } else { // don't move item, so ignore it if (!ignoreItems) { ignoreItems = [item]; @@ -442,34 +446,30 @@ } //calculate next free position to place item - if (this.pushing === false) - { + if (this.locking === true) { var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); while (overlap.length > 0) { - if (item.row == 19 && item.col == 19) { - console.log("NO FREE SPACE LEFT"); + if (item.row == this.maxRows - 1 && item.col == this.columns - 1) { + console.warn("Unable to place item!"); return; } - if (item.row < 19) item.row++; - else { + if (item.row < 19) { + ++item.row; + } else { item.row = 0; - item.col++; + ++item.col; } - if (item.row + item.sizeY < 20 && item.col + item.sizeX < 20) { + if (item.row + item.sizeY < this.maxRows && item.col + item.sizeX < this.columns) { overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); } - } - console.log("put item at row " + item.row); this.putItem(item, item.row, item.col, ignoreItems, true); - } - else - { + } else { // move each item down from the top row in its column to the row for (i = 0, l = items.length; i < l; ++i) { item = items[i]; @@ -493,10 +493,11 @@ } while (item.row < newRow) { ++item.row; - if (this.pushing === true) this.moveOverlappingItems(item, ignoreItems); + if (!this.locking) { + this.moveOverlappingItems(item, ignoreItems); + } } - console.log("put item at row " + item.row); - this.putItem(item, item.row, item.col, ignoreItems, true); + this.putItem(item, item.row, item.col, ignoreItems, this.locking); }; /** @@ -604,6 +605,14 @@ return Math.round(pixels / this.curColWidth); }; + + /** + * Returns current height in pixels of gridster component + * @returns {*} + */ + this.calcGridsterHeight = function() { + return (this.gridHeight * this.curRowHeight) + (this.outerMargin ? this.margins[0] : -this.margins[0]); + } } ]) @@ -771,7 +780,7 @@ }, true); function updateHeight() { - $elem.css('height', (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]) + 'px'); + $elem.css('height', gridster.calcGridsterHeight() + 'px'); } scope.$watch(function() { @@ -852,7 +861,7 @@ } ]) - .controller('GridsterItemCtrl', ['$scope', '$rootScope', function($scope, $rootScope) { + .controller('GridsterItemCtrl', function() { this.$element = null; this.gridster = null; this.row = null; @@ -1039,23 +1048,7 @@ this.getElementSizeY = function() { return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); }; - - this.removeItem = function() { - for (var rowIndex = 0, l = this.gridster.grid.length; rowIndex < l; ++rowIndex) { - var columns = this.gridster.grid[rowIndex]; - if (!columns) { - continue; - } - var index = columns.indexOf(this); - if (index !== -1) { - columns[index] = null; - break; - } - } - this.gridster.layoutChanged(); - $rootScope.$broadcast('gridster-item-removed', this); - }; - }]) + }) .factory('GridsterTouch', [function() { return function GridsterTouch(target, startEvent, moveEvent, endEvent) { @@ -1402,7 +1395,7 @@ mOffY = 0, minTop = 0, - maxTop = (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]), + maxTop = gridster.calcGridsterHeight(), minLeft = 0, realdocument = $document[0]; @@ -1962,7 +1955,7 @@ gridster.movingItem = null; item.setPosition(item.row, item.col); - item.setSizeY(Math.min(gridster.maxRows - item.row, item.sizeY)); + item.setSizeY(Math.min(gridster.curRowHeight - item.row, item.sizeY)); item.setSizeX(Math.min(gridster.columns - item.col, item.sizeX)); scope.$apply(function() { @@ -2116,8 +2109,7 @@ maxSizeX: null, maxSizeY: null, draggable: true, - resizable: true, - onremove: null + resizable: true }; $optionsGetter.assign(scope, options); } @@ -2126,11 +2118,10 @@ } item.init($el, gridster); - if (optionsKey.id) item.id = optionsKey.id; $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'onremove'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], $getters = {}; var expressions = []; @@ -2204,12 +2195,10 @@ $getters.sizeY.assign(scope, item.sizeY); } - if (this.pushing === true) { - if (changedX || changedY) { - item.gridster.moveOverlappingItems(item, [], true); - gridster.layoutChanged(); - scope.$broadcast('gridster-item-resized', item); - } + if (!gridster.locking && (changedX || changedY)) { + gridster.moveOverlappingItems(item); + gridster.layoutChanged(); + scope.$broadcast('gridster-item-resized', item); } } @@ -2278,7 +2267,7 @@ } catch (e) {} try { - item.removeItem(); + gridster.removeItem(item); } catch (e) {} try { From 8e0d93f6c3a3468ee35cdb0edf917812d463370e Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 20:26:45 +1000 Subject: [PATCH 10/31] Dispatch event when no space to add a widget. Check all space, not just space after portlet. Don't dispatch gridster-item-removed event on destroy --- src/angular-gridster.js | 43 +++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index f1965bd4..6262c41d 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -150,9 +150,9 @@ } } } - console.warn('Unable to place item!'); - + console.warn('Unable to place item!'); + $rootScope.$broadcast("gridster-item-not-added", item); }; /** @@ -241,7 +241,6 @@ } } this.layoutChanged(); - $rootScope.$broadcast('gridster-item-removed', item); }; /** @@ -341,6 +340,7 @@ // if have tried to find space for item but there is no room left if (item.row >= this.maxRows - 1 || item.col >= this.columns - 1) { this.removeItem(item); + $rootScope.$broadcast('gridster-item-removed', item); return; } @@ -447,19 +447,38 @@ //calculate next free position to place item if (this.locking === true) { + var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); - while (overlap.length > 0) { + var maxRow = this.maxRows - 1, + maxCol = this.columns - 1, + startRow = item.row, + startCol = item.col, + restarted = false; - if (item.row == this.maxRows - 1 && item.col == this.columns - 1) { - console.warn("Unable to place item!"); - return; - } + while (overlap.length > 0) { - if (item.row < 19) { - ++item.row; + if (item.row == maxRow && item.col == maxCol) { + // if checked all space after item, now check space before it + if (!restarted) { + restarted = true; + item.col = 0; + item.row = 0; + maxRow = startRow; + maxCol = startCol; + } else { + console.warn("Unable to place item!"); + $rootScope.$broadcast("gridster-item-not-added", item); + item.col = this.columns - 1; + item.row = this.maxRows - 1; + return; + } } else { - item.row = 0; - ++item.col; + if (item.row < maxRow) { + ++item.row; + } else { + item.row = 0; + ++item.col; + } } if (item.row + item.sizeY < this.maxRows && item.col + item.sizeX < this.columns) { From 51f643454d3fdeaa5151633ed7e6896aa5e36e73 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 02:20:37 +1000 Subject: [PATCH 11/31] Fixed issues with locking conflicting with pushing, swapping, floating --- src/angular-gridster.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 6262c41d..67f62f07 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -11,6 +11,7 @@ floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way + // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. @@ -151,7 +152,6 @@ } } - console.warn('Unable to place item!'); $rootScope.$broadcast("gridster-item-not-added", item); }; @@ -466,7 +466,6 @@ maxRow = startRow; maxCol = startCol; } else { - console.warn("Unable to place item!"); $rootScope.$broadcast("gridster-item-not-added", item); item.col = this.columns - 1; item.row = this.maxRows - 1; @@ -523,7 +522,7 @@ * Moves all items up as much as possible */ this.floatItemsUp = function() { - if (this.floating === false) { + if (this.floating === false || this.locking === true) { return; } for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { @@ -546,7 +545,7 @@ * @param {Object} item The item to move */ this.floatItemUp = function(item) { - if (this.floating === false) { + if (this.floating === false || this.locking === true) { return; } var colIndex = item.col, @@ -1570,7 +1569,7 @@ var itemsInTheWay = gridster.getItems(row, col, item.sizeX, item.sizeY, item); var hasItemsInTheWay = itemsInTheWay.length !== 0; - if (gridster.swapping === true && hasItemsInTheWay) { + if (gridster.swapping === true && hasItemsInTheWay && !gridster.locking) { var boundingBoxItem = gridster.getBoundingBox(itemsInTheWay), sameSize = boundingBoxItem.sizeX === item.sizeX && boundingBoxItem.sizeY === item.sizeY, sameRow = boundingBoxItem.row === oldRow, @@ -1608,7 +1607,7 @@ } } - if (gridster.pushing !== false || !hasItemsInTheWay) { + if ((gridster.pushing !== false && !gridster.locking) || !hasItemsInTheWay) { item.row = row; item.col = col; } @@ -1638,7 +1637,7 @@ $el.removeClass('gridster-item-moving'); var row = gridster.pixelsToRows(elmY); var col = gridster.pixelsToColumns(elmX); - if (gridster.pushing !== false || gridster.getItems(row, col, item.sizeX, item.sizeY, item).length === 0) { + if ((gridster.pushing !== false && !gridster.locking) || gridster.getItems(row, col, item.sizeX, item.sizeY, item).length === 0) { item.row = row; item.col = col; } @@ -1950,7 +1949,7 @@ sizeY = gridster.pixelsToRows(elmH, true); } - if (gridster.pushing !== false || gridster.getItems(row, col, sizeX, sizeY, item).length === 0) { + if ((gridster.pushing !== false && !gridster.locking) || gridster.getItems(row, col, sizeX, sizeY, item).length === 0) { item.row = row; item.col = col; item.sizeX = sizeX; From bda4b437d447f203c4c3271554083d43ec2f680b Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 18:32:32 +1000 Subject: [PATCH 12/31] Update version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index b5353fe1..72f0f478 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "version": "0.13.6", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/package.json b/package.json index 9663fa50..d451c8a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "version": "0.13.6", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", From fa4b9b36ea8211470fc6ce341cb7f3f45ef9f796 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 18:33:27 +1000 Subject: [PATCH 13/31] Update version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 72f0f478..d6fc1147 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.6", + "version": "0.13.7", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/package.json b/package.json index d451c8a0..5ea0d13b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.6", + "version": "0.13.7", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", From 4d1db07f11a90f2c2611e280c41ad5598bcb436e Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Thu, 18 Jun 2015 08:49:35 +1000 Subject: [PATCH 14/31] Adding draggable & resizable properties per widget, and preventing drag event if draggable turned off for widget --- dist/angular-gridster.min.js | 2 +- src/angular-gridster.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index b1e4ed40..f9fe943e 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -5,4 +5,4 @@ * @version: 0.13.5 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.$element.css(this.gridster.isMobile?{marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}:{margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(a){return!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(a),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}g.pushing===!1&&r||(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;!u||e.pushing===!1&&0!==e.getItems(n,m,s,t,f).length||(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.$element.css(this.gridster.isMobile?{marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}:{margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(a){return!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(a),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}g.pushing===!1&&r||(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;!u||e.pushing===!1&&0!==e.getItems(n,m,s,t,f).length||(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 174f49c5..619a7c44 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1366,6 +1366,11 @@ return false; } + // if draggable turned off for individual widget + if (!$target.draggable) { + return false; + } + switch (e.which) { case 1: // left mouse button @@ -2011,7 +2016,9 @@ minSizeX: 0, minSizeY: 0, maxSizeX: null, - maxSizeY: null + maxSizeY: null, + draggable: true, + resizable: true }; $optionsGetter.assign(scope, options); } @@ -2023,7 +2030,7 @@ $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], $getters = {}; var expressions = []; From 141d13fa89389618f668c69824435c6355a88a91 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 10:12:31 +1000 Subject: [PATCH 15/31] Adding draggable & resizable properties per widget --- src/angular-gridster.js | 65 +++++++++++++++++++++++++++++++++++---- src/angular-gridster.less | 4 +++ 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 619a7c44..39716d91 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1142,6 +1142,7 @@ } else { document.addEventListener('mousemove', doEvent, false); document.addEventListener('mouseup', doEvent, false); + document.addEventListener('dragend', doEvent, false); } } } else if (theEvtObj.type.match(/move$/i)) { @@ -1185,12 +1186,13 @@ // nothing is required for the iOS touch model because capture is implied on touchstart if (target.msReleasePointerCapture) { target.msReleasePointerCapture(pointerId); - } else if (theEvtObj.type === 'mouseup' && numberOfKeys(lastXYById) === 0) { + } else if ((theEvtObj.type === 'mouseup' || theEvtObj.type === 'dragend') && numberOfKeys(lastXYById) === 0) { if (useSetReleaseCapture) { target.releaseCapture(); } else { document.removeEventListener('mousemove', doEvent, false); document.removeEventListener('mouseup', doEvent, false); + document.removeEventListener('dragend', doEvent, false); } } } @@ -1253,6 +1255,7 @@ target.addEventListener('mousemove', doEvent, false); target.addEventListener('mouseup', doEvent, false); + target.addEventListener('dragend', doEvent, false); } } else if (target.attachEvent && target.setCapture) { // legacy IE mode - mouse with capture @@ -1272,6 +1275,11 @@ window.event.returnValue = false; return false; }); + target.attachEvent('dragend', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); } }; @@ -1309,6 +1317,7 @@ target.removeEventListener('mousemove', doEvent, false); target.removeEventListener('mouseup', doEvent, false); + target.removeEventListener('dragend', doEvent, false); } } else if (target.detachEvent && target.setCapture) { // legacy IE mode - mouse with capture @@ -1316,6 +1325,7 @@ target.detachEvent('onmousedown'); target.detachEvent('onmousemove'); target.detachEvent('onmouseup'); + target.detachEvent('ondragend'); } }; @@ -1345,10 +1355,17 @@ var inputTags = ['select', 'input', 'textarea', 'button']; function mouseDown(e) { + if (inputTags.indexOf(e.target.nodeName.toLowerCase()) !== -1) { return false; } + // if draggable turned off for individual widget + if (itemOptions.draggable === false) { + angular.element(document).find('body').addClass('action-not-allowed'); + return false; + } + var $target = angular.element(e.target); // exit, if a resize handle was hit @@ -1366,11 +1383,6 @@ return false; } - // if draggable turned off for individual widget - if (!$target.draggable) { - return false; - } - switch (e.which) { case 1: // left mouse button @@ -1449,6 +1461,12 @@ } function mouseUp(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + angular.element(document).find('body').removeClass('action-not-allowed'); + return false; + } + if (!$el.hasClass('gridster-item-moving') || $el.hasClass('gridster-item-resizing')) { return false; } @@ -1632,6 +1650,10 @@ this.destroy = function() { this.disable(); }; + + this.updateDraggable = function(draggable) { + itemOptions.draggable = draggable; + }; } return GridsterDraggable; @@ -1669,6 +1691,13 @@ var savedDraggable; function mouseDown(e) { + + // if resize has been individually turned off for this widget + if (itemOptions.resizable === false) { + angular.element(document).find('body').addClass('action-not-allowed'); + return false; + } + switch (e.which) { case 1: // left mouse button @@ -1724,6 +1753,11 @@ } function mouseMove(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + return false; + } + var maxLeft = gridster.curWidth - 1; // Get the current mouse position. @@ -1799,6 +1833,12 @@ } function mouseUp(e) { + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + angular.element(document).find('body').removeClass('action-not-allowed'); + return false; + } + // restore draggable setting to its original state if (gridster.draggable.enabled !== savedDraggable) { gridster.draggable.enabled = savedDraggable; @@ -1951,6 +1991,10 @@ handles[c].destroy(); } }; + + this.updateResizable = function(resizable) { + itemOptions.resizable = resizable; + }; } return GridsterResizable; }]) @@ -2000,6 +2044,7 @@ item = controllers[1]; scope.gridster = gridster; + scope.myGridsterItem = scope.$eval(attrs.gridsterItem); // bind the item's position properties // options can be an object specified by gridster-item="object" @@ -2136,6 +2181,14 @@ updateDraggable(); }); + // need to dynamically update draggable/resizable of individual gridster item if properties change + scope.$watch("myGridsterItem.draggable", function(newVal) { + draggable.updateDraggable(newVal); + }, true); + scope.$watch("myGridsterItem.resizable", function(newVal) { + resizable.updateResizable(newVal); + }, true); + function whichTransitionEvent() { var el = document.createElement('div'); var transitions = { diff --git a/src/angular-gridster.less b/src/angular-gridster.less index e8160dd2..dd48f4ec 100644 --- a/src/angular-gridster.less +++ b/src/angular-gridster.less @@ -164,4 +164,8 @@ .gridster .gridster-item:hover .handle-se { border-color: transparent transparent #ccc; +} + +.action-not-allowed { + cursor: not-allowed !important; } \ No newline at end of file From 1def7bd708571e02ad4b413b1e11f3453ff6a1f2 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 22 Jun 2015 11:48:06 +1000 Subject: [PATCH 16/31] Removing module loading --- src/angular-gridster.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 39716d91..387cb5d9 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1,19 +1,4 @@ -/*global define:true*/ -(function(root, factory) { - - 'use strict'; - - if (typeof define === 'function' && define.amd) { - // AMD - define(['angular'], factory); - } else if (typeof exports === 'object') { - // CommonJS - module.exports = factory(require('angular')); - } else { - // Browser, nothing "exported". Only registered as a module with angular. - factory(root.angular); - } -}(this, function(angular) { +(function(angular) { 'use strict'; @@ -2244,4 +2229,4 @@ ; -})); +})(angular); From c3692ea346fd53bcb01b8f90e9872aa0dfd7109f Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Fri, 3 Jul 2015 19:43:59 +1000 Subject: [PATCH 17/31] Adding support for setting height of gridster to screen's height --- src/angular-gridster.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 387cb5d9..5c1c7540 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -644,6 +644,12 @@ if (typeof gridster.rowHeight === 'string') { if (gridster.rowHeight === 'match') { gridster.curRowHeight = Math.round(gridster.curColWidth); + } else if (gridster.rowHeight.indexOf('screen-height') !== -1) { + var body = document.getElementsByTagName('body')[0], + screenHeight = body.clientHeight; + var split = gridster.rowHeight.split("screen-height"); + var additional = split.length > 1 ? parseInt(split[1].replace(/\s/g, "")) : 0; + gridster.curRowHeight = (screenHeight + additional) / gridster.minRows; } else if (gridster.rowHeight.indexOf('*') !== -1) { gridster.curRowHeight = Math.round(gridster.curColWidth * gridster.rowHeight.replace('*', '').replace(' ', '')); } else if (gridster.rowHeight.indexOf('/') !== -1) { @@ -1467,7 +1473,7 @@ $el.addClass('gridster-item-moving'); gridster.movingItem = item; - gridster.updateHeight(item.sizeY); + //gridster.updateHeight(item.sizeY); scope.$apply(function() { if (gridster.draggable && gridster.draggable.start) { gridster.draggable.start(event, $el, itemOptions); From 1312f13ab9ae527102cc950cd186959a2fee37f1 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 6 Jul 2015 21:14:17 +1000 Subject: [PATCH 18/31] Elder item's positions are respected over newer item's, so that newer item is positioned only where it can be fitted in. Code is pretty rough, needs tidying up, etc. --- src/angular-gridster.js | 148 ++++++++++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 37 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 5c1c7540..236d28c5 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -173,8 +173,25 @@ for (var h = 0; h < sizeY; ++h) { for (var w = 0; w < sizeX; ++w) { var item = this.getItem(row + h, column + w, excludeItems); - if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && items.indexOf(item) === -1) { - items.push(item); + if (item) + { + //console.log("item " + item.id + " found at row " + String(row + h) + " col " + String(column + w)); + if(!excludeItems || excludeItems.indexOf(item) === -1) + { + //console.log("not in exclude items"); + for (var i = 0, len = items.length, foundItem = false; i < len; i++) + { + if (items[i].id === item.id) { + foundItem = true; + break; + } + } + + if (foundItem === false) { + //console.log("not in items"); + items.push(item); + } + } } } } @@ -293,7 +310,7 @@ * @param {Number} column (Optional) Specifies the items column index * @param {Array} ignoreItems */ - this.putItem = function(item, row, column, ignoreItems) { + this.putItem = function(item, row, column, ignoreItems, noPush) { // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; @@ -330,12 +347,19 @@ item.oldRow = item.row = row; item.oldColumn = item.col = column; - this.moveOverlappingItems(item, ignoreItems); + if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); + + if (item.row >= 19 || item.col >= 19) { + this.removeItem(item); + return; + } + + console.log("putItem " + item.row + ", " + item.col); - if (!this.grid[row]) { - this.grid[row] = []; + if (!this.grid[item.row]) { + this.grid[item.row] = []; } - this.grid[row][column] = item; + this.grid[item.row][item.col] = item; if (this.movingItem === item) { this.floatItemUp(item); @@ -368,23 +392,44 @@ * @param {Array} ignoreItems */ this.moveOverlappingItems = function(item, ignoreItems) { - // don't move item, so ignore it - if (!ignoreItems) { - ignoreItems = [item]; - } else if (ignoreItems.indexOf(item) === -1) { - ignoreItems = ignoreItems.slice(0); - ignoreItems.push(item); - } - - // get the items in the space occupied by the item's coordinates - var overlappingItems = this.getItems( - item.row, - item.col, - item.sizeX, - item.sizeY, - ignoreItems - ); - this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + + if (this.pushing === false) + { + ignoreItems = this.getItems(0, 0, 20, 20, [item]); + + console.log("no pushing, " + ignoreItems.length + " not to be moved"); + // get the items in the space occupied by the item's coordinates + var overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY); + + if (overlappingItems.length > 0) + { + this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); + } + } + else + { + // don't move item, so ignore it + if (!ignoreItems) { + ignoreItems = [item]; + } else if (ignoreItems.indexOf(item) === -1) { + ignoreItems = ignoreItems.slice(0); + ignoreItems.push(item); + } + + // get the items in the space occupied by the item's coordinates + var overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY, + ignoreItems + ); + this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + } }; /** @@ -415,12 +460,39 @@ } } - // move each item down from the top row in its column to the row - for (i = 0, l = items.length; i < l; ++i) { - item = items[i]; - var rowsToMove = newRow - topRows[item.col]; - this.moveItemDown(item, item.row + rowsToMove, ignoreItems); - ignoreItems.push(item); + //calculate next free position to place item + if (this.pushing === false) + { + var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + while (overlap.length > 0) { + + if (item.row == 19 && item.col == 19) { + console.log("NO FREE SPACE LEFT"); + return; + } + + if (item.row < 19) item.row++; + else { + item.row = 0; + item.col++; + } + + overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + } + + console.log("put item at row " + item.row); + this.putItem(item, item.row, item.col, ignoreItems, true); + } + else + { + + // move each item down from the top row in its column to the row + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var rowsToMove = newRow - topRows[item.col]; + this.moveItemDown(item, item.row + rowsToMove, ignoreItems); + ignoreItems.push(item); + } } }; @@ -437,9 +509,10 @@ } while (item.row < newRow) { ++item.row; - this.moveOverlappingItems(item, ignoreItems); + if (this.pushing === true) this.moveOverlappingItems(item, ignoreItems); } - this.putItem(item, item.row, item.col, ignoreItems); + console.log("put item at row " + item.row); + this.putItem(item, item.row, item.col, ignoreItems, true); }; /** @@ -1338,7 +1411,7 @@ mOffY = 0, minTop = 0, - maxTop = 9999, + maxTop = (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]), minLeft = 0, realdocument = $document[0]; @@ -1473,7 +1546,7 @@ $el.addClass('gridster-item-moving'); gridster.movingItem = item; - //gridster.updateHeight(item.sizeY); + gridster.updateHeight(item.sizeY); scope.$apply(function() { if (gridster.draggable && gridster.draggable.start) { gridster.draggable.start(event, $el, itemOptions); @@ -2054,7 +2127,8 @@ maxSizeX: null, maxSizeY: null, draggable: true, - resizable: true + resizable: true, + id: null }; $optionsGetter.assign(scope, options); } @@ -2066,7 +2140,7 @@ $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'id'], $getters = {}; var expressions = []; @@ -2141,7 +2215,7 @@ } if (changedX || changedY) { - item.gridster.moveOverlappingItems(item); + item.gridster.moveOverlappingItems(item, [], true); gridster.layoutChanged(); scope.$broadcast('gridster-item-resized', item); } From 34eb7bb6032d987f803459e0d85ef207ff1ec005 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 18:18:57 +1000 Subject: [PATCH 19/31] More work on locking a portlet into place --- src/angular-gridster.js | 78 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 236d28c5..f8aa5690 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -39,8 +39,8 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', - function(gridsterConfig, $timeout) { + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$scope', + function(gridsterConfig, $timeout, $scope) { var gridster = this; @@ -149,7 +149,9 @@ } } } - throw new Error('Unable to place item!'); + console.warn('Unable to place item!'); + + }; /** @@ -237,27 +239,6 @@ }; }; - - /** - * Removes an item from the grid - * - * @param {Object} item - */ - this.removeItem = function(item) { - for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { - var columns = this.grid[rowIndex]; - if (!columns) { - continue; - } - var index = columns.indexOf(item); - if (index !== -1) { - columns[index] = null; - break; - } - } - this.layoutChanged(); - }; - /** * Returns the item at a specified coordinate * @@ -350,7 +331,7 @@ if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); if (item.row >= 19 || item.col >= 19) { - this.removeItem(item); + item.removeItem(); return; } @@ -395,7 +376,7 @@ if (this.pushing === false) { - ignoreItems = this.getItems(0, 0, 20, 20, [item]); + ignoreItems = ignoreItems || this.getItems(0, 0, 20, 20, [item]); console.log("no pushing, " + ignoreItems.length + " not to be moved"); // get the items in the space occupied by the item's coordinates @@ -477,7 +458,10 @@ item.col++; } - overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + if (item.row + item.sizeY < 20 && item.col + item.sizeX < 20) { + overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); + } + } console.log("put item at row " + item.row); @@ -876,7 +860,7 @@ } ]) - .controller('GridsterItemCtrl', function() { + .controller('GridsterItemCtrl', ['$scope', '$rootScope', function($scope, $rootScope) { this.$element = null; this.gridster = null; this.row = null; @@ -1064,7 +1048,22 @@ return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); }; - }) + this.removeItem = function() { + for (var rowIndex = 0, l = this.gridster.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.gridster.grid[rowIndex]; + if (!columns) { + continue; + } + var index = columns.indexOf(this); + if (index !== -1) { + columns[index] = null; + break; + } + } + this.gridster.layoutChanged(); + $rootScope.$broadcast('gridster-item-removed', this); + }; + }]) .factory('GridsterTouch', [function() { return function GridsterTouch(target, startEvent, moveEvent, endEvent) { @@ -1973,8 +1972,8 @@ gridster.movingItem = null; item.setPosition(item.row, item.col); - item.setSizeY(item.sizeY); - item.setSizeX(item.sizeX); + item.setSizeY(Math.min(gridster.maxRows - item.row, item.sizeY)); + item.setSizeX(Math.min(gridster.columns - item.col, item.sizeX)); scope.$apply(function() { if (gridster.resizable && gridster.resizable.stop) { @@ -2128,7 +2127,7 @@ maxSizeY: null, draggable: true, resizable: true, - id: null + onremove: null }; $optionsGetter.assign(scope, options); } @@ -2137,10 +2136,11 @@ } item.init($el, gridster); + if (optionsKey.id) item.id = optionsKey.id; $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'id'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'onremove'], $getters = {}; var expressions = []; @@ -2214,10 +2214,12 @@ $getters.sizeY.assign(scope, item.sizeY); } - if (changedX || changedY) { - item.gridster.moveOverlappingItems(item, [], true); - gridster.layoutChanged(); - scope.$broadcast('gridster-item-resized', item); + if (this.pushing === true) { + if (changedX || changedY) { + item.gridster.moveOverlappingItems(item, [], true); + gridster.layoutChanged(); + scope.$broadcast('gridster-item-resized', item); + } } } @@ -2286,7 +2288,7 @@ } catch (e) {} try { - gridster.removeItem(item); + item.removeItem(); } catch (e) {} try { From 40c42c631c8563824f1a0137c2d7e2bf7875b0b6 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 19:11:00 +1000 Subject: [PATCH 20/31] Cleaning up --- src/angular-gridster.js | 157 +++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 84 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index f8aa5690..2d5fceb4 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -10,9 +10,10 @@ pushing: true, // whether to push other items out of the way floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size + locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns - rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. + rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. margins: [10, 10], // margins in between grid items outerMargin: true, isMobile: false, // toggle mobile view @@ -39,8 +40,8 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$scope', - function(gridsterConfig, $timeout, $scope) { + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$rootScope', + function(gridsterConfig, $timeout, $rootScope) { var gridster = this; @@ -175,25 +176,8 @@ for (var h = 0; h < sizeY; ++h) { for (var w = 0; w < sizeX; ++w) { var item = this.getItem(row + h, column + w, excludeItems); - if (item) - { - //console.log("item " + item.id + " found at row " + String(row + h) + " col " + String(column + w)); - if(!excludeItems || excludeItems.indexOf(item) === -1) - { - //console.log("not in exclude items"); - for (var i = 0, len = items.length, foundItem = false; i < len; i++) - { - if (items[i].id === item.id) { - foundItem = true; - break; - } - } - - if (foundItem === false) { - //console.log("not in items"); - items.push(item); - } - } + if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && items.indexOf(item) === -1) { + items.push(item); } } } @@ -239,6 +223,27 @@ }; }; + /** + * Removes an item from the grid + * + * @param {Object} item + */ + this.removeItem = function(item) { + for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.grid[rowIndex]; + if (!columns) { + continue; + } + var index = columns.indexOf(item); + if (index !== -1) { + columns[index] = null; + break; + } + } + this.layoutChanged(); + $rootScope.$broadcast('gridster-item-removed', item); + }; + /** * Returns the item at a specified coordinate * @@ -290,8 +295,9 @@ * @param {Number} row (Optional) Specifies the items row index * @param {Number} column (Optional) Specifies the items column index * @param {Array} ignoreItems + * @param {Boolean} leaveOverlapping (Optional) if true indicates that we don't want moveOverlappingItems() to be called */ - this.putItem = function(item, row, column, ignoreItems, noPush) { + this.putItem = function(item, row, column, ignoreItems, leaveOverlapping) { // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; @@ -328,15 +334,16 @@ item.oldRow = item.row = row; item.oldColumn = item.col = column; - if (noPush !== true) this.moveOverlappingItems(item, ignoreItems); + if (leaveOverlapping !== true) { + this.moveOverlappingItems(item, ignoreItems); + } - if (item.row >= 19 || item.col >= 19) { - item.removeItem(); + // if have tried to find space for item but there is no room left + if (item.row >= this.maxRows - 1 || item.col >= this.columns - 1) { + this.removeItem(item); return; } - console.log("putItem " + item.row + ", " + item.col); - if (!this.grid[item.row]) { this.grid[item.row] = []; } @@ -374,11 +381,10 @@ */ this.moveOverlappingItems = function(item, ignoreItems) { - if (this.pushing === false) + if (this.locking === true) { - ignoreItems = ignoreItems || this.getItems(0, 0, 20, 20, [item]); + ignoreItems = ignoreItems || this.getItems(0, 0, this.columns, this.maxRows, [item]); - console.log("no pushing, " + ignoreItems.length + " not to be moved"); // get the items in the space occupied by the item's coordinates var overlappingItems = this.getItems( item.row, @@ -386,13 +392,11 @@ item.sizeX, item.sizeY); - if (overlappingItems.length > 0) - { + // move this item down if it overlaps any + if (overlappingItems.length > 0) { this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); } - } - else - { + } else { // don't move item, so ignore it if (!ignoreItems) { ignoreItems = [item]; @@ -442,34 +446,30 @@ } //calculate next free position to place item - if (this.pushing === false) - { + if (this.locking === true) { var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); while (overlap.length > 0) { - if (item.row == 19 && item.col == 19) { - console.log("NO FREE SPACE LEFT"); + if (item.row == this.maxRows - 1 && item.col == this.columns - 1) { + console.warn("Unable to place item!"); return; } - if (item.row < 19) item.row++; - else { + if (item.row < 19) { + ++item.row; + } else { item.row = 0; - item.col++; + ++item.col; } - if (item.row + item.sizeY < 20 && item.col + item.sizeX < 20) { + if (item.row + item.sizeY < this.maxRows && item.col + item.sizeX < this.columns) { overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); } - } - console.log("put item at row " + item.row); this.putItem(item, item.row, item.col, ignoreItems, true); - } - else - { + } else { // move each item down from the top row in its column to the row for (i = 0, l = items.length; i < l; ++i) { item = items[i]; @@ -493,10 +493,11 @@ } while (item.row < newRow) { ++item.row; - if (this.pushing === true) this.moveOverlappingItems(item, ignoreItems); + if (!this.locking) { + this.moveOverlappingItems(item, ignoreItems); + } } - console.log("put item at row " + item.row); - this.putItem(item, item.row, item.col, ignoreItems, true); + this.putItem(item, item.row, item.col, ignoreItems, this.locking); }; /** @@ -612,6 +613,14 @@ return Math.round(pixels / this.curColWidth); }; + + /** + * Returns current height in pixels of gridster component + * @returns {*} + */ + this.calcGridsterHeight = function() { + return (this.gridHeight * this.curRowHeight) + (this.outerMargin ? this.margins[0] : -this.margins[0]); + } } ]) @@ -779,7 +788,7 @@ }, true); function updateHeight() { - $elem.css('height', (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]) + 'px'); + $elem.css('height', gridster.calcGridsterHeight() + 'px'); } scope.$watch(function() { @@ -860,7 +869,7 @@ } ]) - .controller('GridsterItemCtrl', ['$scope', '$rootScope', function($scope, $rootScope) { + .controller('GridsterItemCtrl', function() { this.$element = null; this.gridster = null; this.row = null; @@ -1047,23 +1056,7 @@ this.getElementSizeY = function() { return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); }; - - this.removeItem = function() { - for (var rowIndex = 0, l = this.gridster.grid.length; rowIndex < l; ++rowIndex) { - var columns = this.gridster.grid[rowIndex]; - if (!columns) { - continue; - } - var index = columns.indexOf(this); - if (index !== -1) { - columns[index] = null; - break; - } - } - this.gridster.layoutChanged(); - $rootScope.$broadcast('gridster-item-removed', this); - }; - }]) + }) .factory('GridsterTouch', [function() { return function GridsterTouch(target, startEvent, moveEvent, endEvent) { @@ -1410,7 +1403,7 @@ mOffY = 0, minTop = 0, - maxTop = (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]), + maxTop = gridster.calcGridsterHeight(), minLeft = 0, realdocument = $document[0]; @@ -1972,7 +1965,7 @@ gridster.movingItem = null; item.setPosition(item.row, item.col); - item.setSizeY(Math.min(gridster.maxRows - item.row, item.sizeY)); + item.setSizeY(Math.min(gridster.curRowHeight - item.row, item.sizeY)); item.setSizeX(Math.min(gridster.columns - item.col, item.sizeX)); scope.$apply(function() { @@ -2126,8 +2119,7 @@ maxSizeX: null, maxSizeY: null, draggable: true, - resizable: true, - onremove: null + resizable: true }; $optionsGetter.assign(scope, options); } @@ -2136,11 +2128,10 @@ } item.init($el, gridster); - if (optionsKey.id) item.id = optionsKey.id; $el.addClass('gridster-item'); - var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable', 'onremove'], + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col', 'draggable', 'resizable'], $getters = {}; var expressions = []; @@ -2214,12 +2205,10 @@ $getters.sizeY.assign(scope, item.sizeY); } - if (this.pushing === true) { - if (changedX || changedY) { - item.gridster.moveOverlappingItems(item, [], true); - gridster.layoutChanged(); - scope.$broadcast('gridster-item-resized', item); - } + if (!gridster.locking && (changedX || changedY)) { + gridster.moveOverlappingItems(item); + gridster.layoutChanged(); + scope.$broadcast('gridster-item-resized', item); } } @@ -2288,7 +2277,7 @@ } catch (e) {} try { - item.removeItem(); + gridster.removeItem(item); } catch (e) {} try { From 13882515857f9bdaab99984a99d0f25df63daeb1 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Tue, 7 Jul 2015 20:26:45 +1000 Subject: [PATCH 21/31] Dispatch event when no space to add a widget. Check all space, not just space after portlet. Don't dispatch gridster-item-removed event on destroy --- src/angular-gridster.js | 43 +++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 2d5fceb4..8af8e504 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -150,9 +150,9 @@ } } } - console.warn('Unable to place item!'); - + console.warn('Unable to place item!'); + $rootScope.$broadcast("gridster-item-not-added", item); }; /** @@ -241,7 +241,6 @@ } } this.layoutChanged(); - $rootScope.$broadcast('gridster-item-removed', item); }; /** @@ -341,6 +340,7 @@ // if have tried to find space for item but there is no room left if (item.row >= this.maxRows - 1 || item.col >= this.columns - 1) { this.removeItem(item); + $rootScope.$broadcast('gridster-item-removed', item); return; } @@ -447,19 +447,38 @@ //calculate next free position to place item if (this.locking === true) { + var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); - while (overlap.length > 0) { + var maxRow = this.maxRows - 1, + maxCol = this.columns - 1, + startRow = item.row, + startCol = item.col, + restarted = false; - if (item.row == this.maxRows - 1 && item.col == this.columns - 1) { - console.warn("Unable to place item!"); - return; - } + while (overlap.length > 0) { - if (item.row < 19) { - ++item.row; + if (item.row == maxRow && item.col == maxCol) { + // if checked all space after item, now check space before it + if (!restarted) { + restarted = true; + item.col = 0; + item.row = 0; + maxRow = startRow; + maxCol = startCol; + } else { + console.warn("Unable to place item!"); + $rootScope.$broadcast("gridster-item-not-added", item); + item.col = this.columns - 1; + item.row = this.maxRows - 1; + return; + } } else { - item.row = 0; - ++item.col; + if (item.row < maxRow) { + ++item.row; + } else { + item.row = 0; + ++item.col; + } } if (item.row + item.sizeY < this.maxRows && item.col + item.sizeX < this.columns) { From 0ddce637b9f8f0afafc85e231151c7205ec71bce Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 02:20:37 +1000 Subject: [PATCH 22/31] Fixed issues with locking conflicting with pushing, swapping, floating --- src/angular-gridster.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 8af8e504..76995f39 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -11,6 +11,7 @@ floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way + // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. @@ -151,7 +152,6 @@ } } - console.warn('Unable to place item!'); $rootScope.$broadcast("gridster-item-not-added", item); }; @@ -466,7 +466,6 @@ maxRow = startRow; maxCol = startCol; } else { - console.warn("Unable to place item!"); $rootScope.$broadcast("gridster-item-not-added", item); item.col = this.columns - 1; item.row = this.maxRows - 1; @@ -523,7 +522,7 @@ * Moves all items up as much as possible */ this.floatItemsUp = function() { - if (this.floating === false) { + if (this.floating === false || this.locking === true) { return; } for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { @@ -546,7 +545,7 @@ * @param {Object} item The item to move */ this.floatItemUp = function(item) { - if (this.floating === false) { + if (this.floating === false || this.locking === true) { return; } var colIndex = item.col, @@ -1578,7 +1577,7 @@ var itemsInTheWay = gridster.getItems(row, col, item.sizeX, item.sizeY, item); var hasItemsInTheWay = itemsInTheWay.length !== 0; - if (gridster.swapping === true && hasItemsInTheWay) { + if (gridster.swapping === true && hasItemsInTheWay && !gridster.locking) { var boundingBoxItem = gridster.getBoundingBox(itemsInTheWay), sameSize = boundingBoxItem.sizeX === item.sizeX && boundingBoxItem.sizeY === item.sizeY, sameRow = boundingBoxItem.row === oldRow, @@ -1616,7 +1615,7 @@ } } - if (gridster.pushing !== false || !hasItemsInTheWay) { + if ((gridster.pushing !== false && !gridster.locking) || !hasItemsInTheWay) { item.row = row; item.col = col; } @@ -1646,7 +1645,7 @@ $el.removeClass('gridster-item-moving'); var row = gridster.pixelsToRows(elmY); var col = gridster.pixelsToColumns(elmX); - if (gridster.pushing !== false || gridster.getItems(row, col, item.sizeX, item.sizeY, item).length === 0) { + if ((gridster.pushing !== false && !gridster.locking) || gridster.getItems(row, col, item.sizeX, item.sizeY, item).length === 0) { item.row = row; item.col = col; } @@ -1958,9 +1957,8 @@ sizeY = gridster.pixelsToRows(elmH, true); } - var canOccupy = row > -1 && col > -1 && sizeX + col <= gridster.columns && sizeY + row <= gridster.maxRows; - if (canOccupy && (gridster.pushing !== false || gridster.getItems(row, col, sizeX, sizeY, item).length === 0)) { + if (canOccupy && ((gridster.pushing !== false && !gridster.locking) || gridster.getItems(row, col, sizeX, sizeY, item).length === 0)) { item.row = row; item.col = col; item.sizeX = sizeX; From 60b95209440a535b249262a164cee958e2dbb58d Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 18:32:32 +1000 Subject: [PATCH 23/31] Update version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index b5353fe1..72f0f478 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "version": "0.13.6", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/package.json b/package.json index 9663fa50..d451c8a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "version": "0.13.6", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", From c7fe44c6b845fb3fa8fdd7c8978bc8f75486c0d7 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 8 Jul 2015 18:33:27 +1000 Subject: [PATCH 24/31] Update version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 72f0f478..d6fc1147 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.6", + "version": "0.13.7", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/package.json b/package.json index d451c8a0..5ea0d13b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.6", + "version": "0.13.7", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", From 5d1e0c86397eb86cd494135ac78d9f9e79ce5863 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 15 Jul 2015 16:05:06 +1000 Subject: [PATCH 25/31] Fixing JSHint warnings --- dist/angular-gridster.min.css | 2 +- dist/angular-gridster.min.js | 4 ++-- src/angular-gridster.js | 27 +++++++++++++-------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/dist/angular-gridster.min.css b/dist/angular-gridster.min.css index fe09e1ba..3d5d58e9 100644 --- a/dist/angular-gridster.min.css +++ b/dist/angular-gridster.min.css @@ -1 +1 @@ -.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2}.gridster-loaded .gridster-item.gridster-item-moving,.gridster-loaded .gridster-preview-holder{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block;z-index:5}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc} \ No newline at end of file +.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2}.gridster-loaded .gridster-item.gridster-item-moving,.gridster-loaded .gridster-preview-holder{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block;z-index:5}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc}.action-not-allowed{cursor:not-allowed !important} \ No newline at end of file diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index f9fe943e..f15e757e 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -2,7 +2,7 @@ * angular-gridster * http://manifestwebdesign.github.io/angular-gridster * - * @version: 0.13.5 + * @version: 0.13.7 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.$element.css(this.gridster.isMobile?{marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}:{margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(a){return!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(a),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}g.pushing===!1&&r||(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;!u||e.pushing===!1&&0!==e.getItems(n,m,s,t,f).length||(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); +!function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var e,f,g,h={};for(f=0,g=a.length;g>f;++f){e=a[f];var i=h[e.col];("undefined"==typeof i||e.row0;){if(e.row===k&&e.col===l){if(o)return d.$broadcast("gridster-item-not-added",e),e.col=this.columns-1,void(e.row=this.maxRows-1);o=!0,e.col=0,e.row=0,k=m,l=n}else e.rowf;++f){e=a[f];var p=b-h[e.col];this.moveItemDown(e,e.row+p,c),c.push(e)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}(angular); \ No newline at end of file diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 76995f39..187d7241 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -11,7 +11,7 @@ floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way - // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect + // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. @@ -152,7 +152,7 @@ } } - $rootScope.$broadcast("gridster-item-not-added", item); + $rootScope.$broadcast('gridster-item-not-added', item); }; /** @@ -380,13 +380,12 @@ * @param {Array} ignoreItems */ this.moveOverlappingItems = function(item, ignoreItems) { - - if (this.locking === true) - { + var overlappingItems; + if (this.locking === true) { ignoreItems = ignoreItems || this.getItems(0, 0, this.columns, this.maxRows, [item]); // get the items in the space occupied by the item's coordinates - var overlappingItems = this.getItems( + overlappingItems = this.getItems( item.row, item.col, item.sizeX, @@ -406,7 +405,7 @@ } // get the items in the space occupied by the item's coordinates - var overlappingItems = this.getItems( + overlappingItems = this.getItems( item.row, item.col, item.sizeX, @@ -457,7 +456,7 @@ while (overlap.length > 0) { - if (item.row == maxRow && item.col == maxCol) { + if (item.row === maxRow && item.col === maxCol) { // if checked all space after item, now check space before it if (!restarted) { restarted = true; @@ -466,7 +465,7 @@ maxRow = startRow; maxCol = startCol; } else { - $rootScope.$broadcast("gridster-item-not-added", item); + $rootScope.$broadcast('gridster-item-not-added', item); item.col = this.columns - 1; item.row = this.maxRows - 1; return; @@ -638,7 +637,7 @@ */ this.calcGridsterHeight = function() { return (this.gridHeight * this.curRowHeight) + (this.outerMargin ? this.margins[0] : -this.margins[0]); - } + }; } ]) @@ -731,8 +730,8 @@ } else if (gridster.rowHeight.indexOf('screen-height') !== -1) { var body = document.getElementsByTagName('body')[0], screenHeight = body.clientHeight; - var split = gridster.rowHeight.split("screen-height"); - var additional = split.length > 1 ? parseInt(split[1].replace(/\s/g, "")) : 0; + var split = gridster.rowHeight.split('screen-height'); + var additional = split.length > 1 ? parseInt(split[1].replace(/\s/g, '')) : 0; gridster.curRowHeight = (screenHeight + additional) / gridster.minRows; } else if (gridster.rowHeight.indexOf('*') !== -1) { gridster.curRowHeight = Math.round(gridster.curColWidth * gridster.rowHeight.replace('*', '').replace(' ', '')); @@ -2255,10 +2254,10 @@ }); // need to dynamically update draggable/resizable of individual gridster item if properties change - scope.$watch("myGridsterItem.draggable", function(newVal) { + scope.$watch('myGridsterItem.draggable', function(newVal) { draggable.updateDraggable(newVal); }, true); - scope.$watch("myGridsterItem.resizable", function(newVal) { + scope.$watch('myGridsterItem.resizable', function(newVal) { resizable.updateResizable(newVal); }, true); From ee6e911f7663da09419dd170c010633729db3ede Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Wed, 15 Jul 2015 16:11:05 +1000 Subject: [PATCH 26/31] Merge in & version number --- bower.json | 2 +- dist/angular-gridster.min.css | 2 +- dist/angular-gridster.min.js | 4 ++-- package.json | 2 +- src/angular-gridster.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index d6fc1147..d28ebcdd 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.7", + "version": "0.13.8", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/dist/angular-gridster.min.css b/dist/angular-gridster.min.css index 38f1b6e4..3d5d58e9 100644 --- a/dist/angular-gridster.min.css +++ b/dist/angular-gridster.min.css @@ -1 +1 @@ -.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2;-webkit-transition:width .2s, height .3s;-moz-transition:width .2s, height .3s;-o-transition:width .2s, height .3s;transition:width .2s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-item.gridster-item-moving{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc}.action-not-allowed{cursor:not-allowed !important} \ No newline at end of file +.gridster{position:relative;margin:auto;height:0}.gridster>ul{margin:0;list-style:none;padding:0}.gridster-item{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;list-style:none;z-index:2;position:absolute;display:none}.gridster-loaded{-webkit-transition:height .3s;-moz-transition:height .3s;-o-transition:height .3s;transition:height .3s}.gridster-loaded .gridster-item{display:block;position:absolute;-webkit-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-moz-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-o-transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;transition:opacity .3s, left .3s, top .3s, width .3s, height .3s;-webkit-transition-delay:50ms;-moz-transition-delay:50ms;-o-transition-delay:50ms;transition-delay:50ms}.gridster-loaded .gridster-preview-holder{display:none;z-index:1;position:absolute;background-color:#ddd;border-color:#fff;opacity:0.2}.gridster-loaded .gridster-item.gridster-item-moving,.gridster-loaded .gridster-preview-holder{-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.gridster-mobile{height:auto !important}.gridster-mobile .gridster-item{height:auto;position:static;float:none}.gridster-item.ng-leave.ng-leave-active{opacity:0}.gridster-item.ng-enter{opacity:1}.gridster-item-moving{z-index:3}.gridster-item-resizable-handler{position:absolute;font-size:1px;display:block;z-index:5}.handle-se{cursor:se-resize;width:0;height:0;right:1px;bottom:1px;border-style:solid;border-width:0 0 12px 12px;border-color:transparent}.handle-ne{cursor:ne-resize;width:12px;height:12px;right:1px;top:1px}.handle-nw{cursor:nw-resize;width:12px;height:12px;left:1px;top:1px}.handle-sw{cursor:sw-resize;width:12px;height:12px;left:1px;bottom:1px}.handle-e{cursor:e-resize;width:12px;bottom:0;right:1px;top:0}.handle-s{cursor:s-resize;height:12px;right:0;bottom:1px;left:0}.handle-n{cursor:n-resize;height:12px;right:0;top:1px;left:0}.handle-w{cursor:w-resize;width:12px;left:1px;top:0;bottom:0}.gridster .gridster-item:hover .gridster-box{border:1.5px solid #B3B2B3}.gridster .gridster-item:hover .handle-se{border-color:transparent transparent #ccc}.action-not-allowed{cursor:not-allowed !important} \ No newline at end of file diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index 017ce78d..e2db0ea5 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -2,7 +2,7 @@ * angular-gridster * http://manifestwebdesign.github.io/angular-gridster * - * @version: 0.13.7 + * @version: 0.13.8 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout",function(b,c){var d=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var e=!1;this.layoutChanged=function(){e||(e=!0,c(function(){e=!1,d.loaded&&d.floatItemsUp(),d.updateHeight(d.movingItem?d.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,d){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var e=a.oldRow===b&&a.oldColumn===c,f=this.grid[b]&&this.grid[b][c]===a;if(e&&f)return a.row=b,void(a.col=c);var g=this.grid[a.oldRow];g&&g[a.oldColumn]===a&&delete g[a.oldColumn]}a.oldRow=a.row=b,a.oldColumn=a.col=c,this.moveOverlappingItems(a,d),this.grid[b]||(this.grid[b]=[]),this.grid[b][c]=a,this.movingItem===a&&this.floatItemUp(a),this.layoutChanged()},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a];var c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b);this.moveItemsDown(c,a.row+a.sizeY,b)},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var d,e,f,g={};for(e=0,f=a.length;f>e;++e){d=a[e];var h=g[d.col];("undefined"==typeof h||d.rowe;++e){d=a[e];var i=b-g[d.col];this.moveItemDown(d,d.row+i,c),c.push(d)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){"auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight&&("match"===i.rowHeight?i.curRowHeight=Math.round(i.curColWidth):-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")))),i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var b=0,c=i.grid.length;c>b;++b){var d=i.grid[b];if(d)for(var e=0,f=d.length;f>e;++e)if(d[e]){var h=d[e];h.setElementPosition(),h.setElementSizeY(),h.setElementSizeX()}}k()}}function k(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;nq+e?(c=E-q,A=e-c):q+s+e>b&&(c=b-q-s,A=e-c),C>r+g?(d=C-r,B=g-d):r+t+g>D&&(d=D-r-t,B=g-d),q+=c,r+=d,f.css({top:r+"px",left:q+"px"}),o(a),!0}function m(a){return!f.hasClass("gridster-item-moving")||f.hasClass("gridster-item-resizing")?!1:(A=B=0,p(a),!0)}function n(a){f.addClass("gridster-item-moving"),h.movingItem=i,h.updateHeight(i.sizeY),g.$apply(function(){h.draggable&&h.draggable.start&&h.draggable.start(a,f,j)})}function o(a){var b=i.row,c=i.col,e=h.draggable&&h.draggable.drag,k=h.draggable.scrollSensitivity,l=h.draggable.scrollSpeed,m=h.pixelsToRows(r),n=h.pixelsToColumns(q),o=h.getItems(m,n,i.sizeX,i.sizeY,i),p=0!==o.length;if(h.swapping===!0&&p){var s=h.getBoundingBox(o),t=s.sizeX===i.sizeX&&s.sizeY===i.sizeY,u=s.row===b,v=s.col===c,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)h.swapItems(i,o[0]);else if(x)return}else if(s.sizeX<=i.sizeX&&s.sizeY<=i.sizeY&&x)for(var y=i.row<=m?i.row:m+i.sizeY,z=i.col<=n?i.col:n+i.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var E=o[C],G=h.getItems(E.row+A,E.col+B,E.sizeX,E.sizeY,i);0===G.length&&h.putItem(E,E.row+A,E.col+B)}}h.pushing===!1&&p||(i.row=m,i.col=n),a.pageY-F.body.scrollTopb;++b)J[b].disable();J=[],h.draggable&&h.draggable.handle?(I=a.element(f[0].querySelectorAll(h.draggable.handle)),0===I.length&&(I=f)):I=f;for(var d=0,g=I.length;g>d;++d)J[d]=new e(I[d],k,l,m),J[d].enable();H=!0})},this.disable=function(){H!==!1&&c(function(){for(var a=0,b=J.length;b>a;++a)J[a].disable();J=[],H=!1})},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()}}return f}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(a){switch(a.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=a.pageX,A=a.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(a),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(a){var b=e.curWidth-1;x=a.pageX,y=a.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d;return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=F-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hb&&(d=b-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(a),!0}function l(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(a),!0}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0)),(e.pushing!==!1||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var u=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||u)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(f.sizeY),f.setSizeX(f.sizeX),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),(a||b)&&(o.gridster.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()});var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var e,f,g,h={};for(f=0,g=a.length;g>f;++f){e=a[f];var i=h[e.col];("undefined"==typeof i||e.row0;){if(e.row===k&&e.col===l){if(o)return d.$broadcast("gridster-item-not-added",e),e.col=this.columns-1,void(e.row=this.maxRows-1);o=!0,e.col=0,e.row=0,k=m,l=n}else e.rowf;++f){e=a[f];var p=b-h[e.col];this.moveItemDown(e,e.row+p,c),c.push(e)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 5ea0d13b..25eead18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.7", + "version": "0.13.8", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", diff --git a/src/angular-gridster.js b/src/angular-gridster.js index b0fbdc86..187d7241 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -11,7 +11,7 @@ floating: true, // whether to automatically float items up so they stack swapping: false, // whether or not to have items switch places instead of push down if they are the same size locking: false, // whether an item added to the grid earlier will have priority position and any items added later will have to find space around them rather than pushing them out the way - // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect + // !important if locking is set to true it will override pushing, floating & swapping and setting these values to true will have no effect width: 'auto', // width of the grid. "auto" will expand the grid to its parent container colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, 'screen-height' matches viewport height and can specify +/- px value ie. 'screen-height - 120px', a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. From 584a55706e8070bfee88d7aa2ab520270c40ef23 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Fri, 17 Jul 2015 09:23:56 +1000 Subject: [PATCH 27/31] Reworking UMD structure to work with gulp, bower & browserify --- dist/angular-gridster.min.js | 2 +- src/angular-gridster.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index e2db0ea5..d7999962 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -5,4 +5,4 @@ * @version: 0.13.8 * @license: MIT */ -!function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var e,f,g,h={};for(f=0,g=a.length;g>f;++f){e=a[f];var i=h[e.col];("undefined"==typeof i||e.row0;){if(e.row===k&&e.col===l){if(o)return d.$broadcast("gridster-item-not-added",e),e.col=this.columns-1,void(e.row=this.maxRows-1);o=!0,e.col=0,e.row=0,k=m,l=n}else e.rowf;++f){e=a[f];var p=b-h[e.col];this.moveItemDown(e,e.row+p,c),c.push(e)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}(angular); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var e,f,g,h={};for(f=0,g=a.length;g>f;++f){e=a[f];var i=h[e.col];("undefined"==typeof i||e.row0;){if(e.row===k&&e.col===l){if(o)return d.$broadcast("gridster-item-not-added",e),e.col=this.columns-1,void(e.row=this.maxRows-1);o=!0,e.col=0,e.row=0,k=m,l=n}else e.rowf;++f){e=a[f];var p=b-h[e.col];this.moveItemDown(e,e.row+p,c),c.push(e)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 187d7241..46df8f9c 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -1,4 +1,20 @@ -(function(angular) { +/*global define:true*/ +(function(root, factory) { + + 'use strict'; + + if (typeof define === 'function' && define.amd) { + // AMD + define(['angular'], factory); + } else if (typeof exports === 'object') { + // CommonJS + require('angular'); + module.exports = factory(angular); + } else { + // Browser, nothing "exported". Only registered as a module with angular. + factory(root.angular); + } +}(this, function(angular) { 'use strict'; @@ -2316,4 +2332,4 @@ ; -})(angular); +})); From 932b41d666fba48ca07e758c697bfaedf0bc2c41 Mon Sep 17 00:00:00 2001 From: Heather Roberts Date: Mon, 19 Oct 2015 17:37:20 +1000 Subject: [PATCH 28/31] Fixing problems with gridster-item-not-added event. Dispatch event when item added successfully. If an item doesn't fit, now shrink it down and try to fit it in. --- bower.json | 2 +- package.json | 2 +- src/angular-gridster.js | 101 +++++++++++++++++++++++++++------------- 3 files changed, 71 insertions(+), 34 deletions(-) diff --git a/bower.json b/bower.json index d28ebcdd..b7b0015b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.8", + "version": "0.13.9", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/package.json b/package.json index 25eead18..ded8388d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.8", + "version": "0.13.9", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 46df8f9c..78552783 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -168,7 +168,18 @@ } } - $rootScope.$broadcast('gridster-item-not-added', item); + // if item couldn't be added, shrink it until it can fit somewhere + if (item.sizeX > gridster.minSizeX || gridster.sizeY > gridster.minSizeY) { + if (item.sizeX > item.sizeY || item.sizeY === gridster.minSizeY) { + item.sizeX--; + } else { + item.sizeY--; + } + this.autoSetItemPosition(item); + } else { + // no space left at all + $rootScope.$broadcast('gridster-item-not-added', item); + } }; /** @@ -365,6 +376,8 @@ } this.grid[item.row][item.col] = item; + $rootScope.$broadcast('gridster-item-added', item); + if (this.movingItem === item) { this.floatItemUp(item); } @@ -443,6 +456,9 @@ if (!items || items.length === 0) { return; } + + var that = this; + items.sort(function(a, b) { return a.row - b.row; }); @@ -463,42 +479,63 @@ //calculate next free position to place item if (this.locking === true) { - var overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); - var maxRow = this.maxRows - 1, - maxCol = this.columns - 1, - startRow = item.row, - startCol = item.col, - restarted = false; - - while (overlap.length > 0) { - - if (item.row === maxRow && item.col === maxCol) { - // if checked all space after item, now check space before it - if (!restarted) { - restarted = true; - item.col = 0; - item.row = 0; - maxRow = startRow; - maxCol = startCol; + var noSpace = false; + + var fitItem = function() { + var overlap = that.getItems(item.row, item.col, item.sizeX, item.sizeY); + var maxRow = that.maxRows - 1, + maxCol = that.columns - 1, + startRow = item.row, + startCol = item.col, + restarted = false; + + while (overlap.length > 0) { + if (item.row === maxRow && item.col === maxCol) { + // if checked all space after item, now check space before it + if (!restarted) { + restarted = true; + item.col = 0; + item.row = 0; + maxRow = startRow; + maxCol = startCol; + } else { + // if item couldn't be added, shrink it until it can fit somewhere + if (item.sizeX > gridster.minSizeX || item.sizeY > gridster.minSizeY) { + if (item.sizeX > item.sizeY || item.sizeY === gridster.minSizeY) { + item.sizeX--; + } else { + item.sizeY--; + } + item.row = startRow; + item.col = startCol; + fitItem(); + break; + } else { + // no space left at all + $rootScope.$broadcast('gridster-item-not-added', item); + item.col = that.columns - 1; + item.row = that.maxRows - 1; + noSpace = true; + return; + } + } } else { - $rootScope.$broadcast('gridster-item-not-added', item); - item.col = this.columns - 1; - item.row = this.maxRows - 1; - return; + if (item.row < maxRow) { + ++item.row; + } else { + item.row = 0; + ++item.col; + } } - } else { - if (item.row < maxRow) { - ++item.row; - } else { - item.row = 0; - ++item.col; + + if (item.row + item.sizeY < that.maxRows && item.col + item.sizeX < that.columns) { + overlap = that.getItems(item.row, item.col, item.sizeX, item.sizeY); } } + }; + fitItem(); - if (item.row + item.sizeY < this.maxRows && item.col + item.sizeX < this.columns) { - overlap = this.getItems(item.row, item.col, item.sizeX, item.sizeY); - } - } + if (noSpace === true) return; this.putItem(item, item.row, item.col, ignoreItems, true); From bedbc4a407c31e74663de19bddcae64365c4f877 Mon Sep 17 00:00:00 2001 From: "heather.roberts" Date: Mon, 4 Jan 2016 11:04:15 +1000 Subject: [PATCH 29/31] Fixed bug when resizing and release mouse outside of gridster item --- bower.json | 2 +- dist/angular-gridster.min.js | 4 ++-- package.json | 2 +- src/angular-gridster.js | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index b7b0015b..c46f2c5f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.9", + "version": "0.13.10", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index d7999962..cb81ab84 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -2,7 +2,7 @@ * angular-gridster * http://manifestwebdesign.github.io/angular-gridster * - * @version: 0.13.8 + * @version: 0.13.9 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;bg;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var e,f,g,h={};for(f=0,g=a.length;g>f;++f){e=a[f];var i=h[e.col];("undefined"==typeof i||e.row0;){if(e.row===k&&e.col===l){if(o)return d.$broadcast("gridster-item-not-added",e),e.col=this.columns-1,void(e.row=this.maxRows-1);o=!0,e.col=0,e.row=0,k=m,l=n}else e.rowf;++f){e=a[f];var p=b-h[e.col];this.moveItemDown(e,e.row+p,c),c.push(e)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;be.minSizeX||e.sizeY>e.minSizeY?(a.sizeX>a.sizeY||a.sizeY===e.minSizeY?a.sizeX--:a.sizeY--,this.autoSetItemPosition(a)):d.$broadcast("gridster-item-not-added",a)},this.getItems=function(a,b,c,d,e){var f=[];c&&d||(c=d=1),!e||e instanceof Array||(e=[e]);for(var g=0;d>g;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,d.$broadcast("gridster-item-added",a),this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){var f=this;a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var g,h,i,j={};for(h=0,i=a.length;i>h;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.row0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.rowh;++h){g=a[h];var n=b-j[g.col];this.moveItemDown(g,g.row+n,c),c.push(g)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),document.addEventListener("mouseup",l),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),document.removeEventListener("mouseup",l),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file diff --git a/package.json b/package.json index ded8388d..248eaefa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.9", + "version": "0.13.10", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 78552783..ba8a0576 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -535,7 +535,9 @@ }; fitItem(); - if (noSpace === true) return; + if (noSpace === true) { + return; + } this.putItem(item, item.row, item.col, ignoreItems, true); @@ -1862,6 +1864,7 @@ function resizeStart(e) { $el.addClass('gridster-item-moving'); $el.addClass('gridster-item-resizing'); + document.addEventListener('mouseup', mouseUp); gridster.movingItem = item; @@ -1971,6 +1974,8 @@ scope.$broadcast('gridster-draggable-changed', gridster); } + document.removeEventListener('mouseup', mouseUp); + mOffX = mOffY = 0; resizeStop(e); From 454efbe5f1e8cbea0b313ecf6dbb67fd9910515e Mon Sep 17 00:00:00 2001 From: "heather.roberts" Date: Tue, 5 Jan 2016 12:56:22 +1000 Subject: [PATCH 30/31] Improving behaviour of bounding box restriction --- bower.json | 2 +- dist/angular-gridster.min.js | 4 ++-- package.json | 2 +- src/angular-gridster.js | 36 +++++++++++++++++++----------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/bower.json b/bower.json index c46f2c5f..cd39cf0b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.10", + "version": "0.13.11", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index cb81ab84..b47a0f34 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -2,7 +2,7 @@ * angular-gridster * http://manifestwebdesign.github.io/angular-gridster * - * @version: 0.13.9 + * @version: 0.13.10 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;be.minSizeX||e.sizeY>e.minSizeY?(a.sizeX>a.sizeY||a.sizeY===e.minSizeY?a.sizeX--:a.sizeY--,this.autoSetItemPosition(a)):d.$broadcast("gridster-item-not-added",a)},this.getItems=function(a,b,c,d,e){var f=[];c&&d||(c=d=1),!e||e instanceof Array||(e=[e]);for(var g=0;d>g;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,d.$broadcast("gridster-item-added",a),this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){var f=this;a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var g,h,i,j={};for(h=0,i=a.length;i>h;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.row0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.rowh;++h){g=a[h];var n=b-j[g.col];this.moveItemDown(g,g.row+n,c),c.push(g)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(m,function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+f?(c=D-p,z=f-c):p+r+f>b&&(c=b-p-r,z=f-c),B>q+h?(d=B-q,A=h-d):q+s+h>C&&(d=C-q-s,A=h-d),p+=c,q+=d,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,D=o.length;D>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-E.body.scrollTopb;++b)I[b].disable();I=[],g.draggable&&g.draggable.handle?(H=a.element(e[0].querySelectorAll(g.draggable.handle)),0===H.length&&(H=e)):H=e;for(var f=0,h=H.length;h>f;++f)I[f]=new d(H[f],j,k,l),I[f].enable()}}))},this.disable=function(){if(G!==!1){G=!1;for(var a=0,b=I.length;b>a;++a)I[a].disable();I=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=parseInt(c.css("left"),10),p=parseInt(c.css("top"),10),q=c[0].offsetWidth,r=c[0].offsetHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),document.addEventListener("mouseup",l),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;var d=e.curWidth-1;x=b.pageX,y=b.pageY;var f=x-z+B,g=y-A+C;B=C=0,z=x,A=y;var h=g,i=f;return w.indexOf("n")>=0&&(r-hp+h&&(g=D-p,C=h-g),p+=g,r-=g),w.indexOf("s")>=0&&(r+hE&&(g=E-p-r,C=h-g),r+=g),w.indexOf("w")>=0&&(q-io+i&&(f=F-o,B=i-f),o+=f,q-=f),w.indexOf("e")>=0&&(q+id&&(f=d-o-q,B=i-f),q+=f),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),document.removeEventListener("mouseup",l),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=9999,F=0,G=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},H=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},I=null;this.enable=function(){I||(I=a.element('
'),c.append(I)),v=new b(I[0],i,k,l),v.enable()},this.disable=function(){I&&(I.remove(),I=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;be.minSizeX||e.sizeY>e.minSizeY?(a.sizeX>a.sizeY||a.sizeY===e.minSizeY?a.sizeX--:a.sizeY--,this.autoSetItemPosition(a)):d.$broadcast("gridster-item-not-added",a)},this.getItems=function(a,b,c,d,e){var f=[];c&&d||(c=d=1),!e||e instanceof Array||(e=[e]);for(var g=0;d>g;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,d.$broadcast("gridster-item-added",a),this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){var f=this;a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var g,h,i,j={};for(h=0,i=a.length;i>h;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.row0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.rowh;++h){g=a[h];var n=b-j[g.col];this.moveItemDown(g,g.row+n,c),c.push(g)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(function(){return f.$eval(m)},function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+h?(b=C-p,z=h-b):p+r+h>d&&(b=d-p-r,z=h-b),B>q+i?(c=B-q,A=i-c):q+i>=f&&(c=f-q,A=i-c),p+=b,q+=c,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,E=o.length;E>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-D.body.scrollTopb;++b)H[b].disable();H=[],g.draggable&&g.draggable.handle?(G=a.element(e[0].querySelectorAll(g.draggable.handle)),0===G.length&&(G=e)):G=e;for(var f=0,h=G.length;h>f;++f)H[f]=new d(G[f],j,k,l),H[f].enable()}}))},this.disable=function(){if(F!==!1){F=!1;for(var a=0,b=H.length;b>a;++a)H[a].disable();H=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=f.col*e.curColWidth,p=f.row*e.curRowHeight,q=f.sizeX*e.curColWidth,r=f.sizeY*e.curRowHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),document.addEventListener("mouseup",l),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;x=b.pageX,y=b.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d,i=e.curWidth-1,j=e.calcGridsterHeight();return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gj&&(f=j-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=E-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hi&&(d=i-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),document.removeEventListener("mouseup",l),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},G=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},H=null;this.enable=function(){H||(H=a.element('
'),c.append(H)),v=new b(H[0],i,k,l),v.enable()},this.disable=function(){H&&(H.remove(),H=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file diff --git a/package.json b/package.json index 248eaefa..59c49545 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.10", + "version": "0.13.11", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", diff --git a/src/angular-gridster.js b/src/angular-gridster.js index ba8a0576..9d7171ee 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -819,7 +819,9 @@ var optionsKey = attrs.gridster; if (optionsKey) { - scope.$parent.$watch(optionsKey, function(newConfig) { + scope.$parent.$watch(function() { + return scope.$eval(optionsKey); + }, function(newConfig) { refresh(newConfig); }, true); } else { @@ -1475,7 +1477,6 @@ mOffY = 0, minTop = 0, - maxTop = gridster.calcGridsterHeight(), minLeft = 0, realdocument = $document[0]; @@ -1524,10 +1525,10 @@ lastMouseX = e.pageX; lastMouseY = e.pageY; - elmX = parseInt($el.css('left'), 10); - elmY = parseInt($el.css('top'), 10); - elmW = $el[0].offsetWidth; - elmH = $el[0].offsetHeight; + elmX = item.col * gridster.curColWidth; + elmY = item.row * gridster.curRowHeight; + elmW = item.sizeX * gridster.curColWidth; + elmH = item.sizeY * gridster.curRowHeight; originalCol = item.col; originalRow = item.row; @@ -1542,8 +1543,6 @@ return false; } - var maxLeft = gridster.curWidth - 1; - // Get the current mouse position. mouseX = e.pageX; mouseY = e.pageY; @@ -1557,6 +1556,9 @@ lastMouseX = mouseX; lastMouseY = mouseY; + var maxLeft = gridster.curWidth - 1, + maxTop = gridster.calcGridsterHeight(); + var dX = diffX, dY = diffY; if (elmX + dX < minLeft) { @@ -1570,8 +1572,8 @@ if (elmY + dY < minTop) { diffY = minTop - elmY; mOffY = dY - diffY; - } else if (elmY + elmH + dY > maxTop) { - diffY = maxTop - elmY - elmH; + } else if (elmY + dY >= maxTop) { + diffY = maxTop - elmY; mOffY = dY - diffY; } elmX += diffX; @@ -1805,7 +1807,6 @@ mOffY = 0, minTop = 0, - maxTop = 9999, minLeft = 0; var getMinHeight = function() { @@ -1848,10 +1849,10 @@ lastMouseY = e.pageY; // Record current widget dimensions - elmX = parseInt($el.css('left'), 10); - elmY = parseInt($el.css('top'), 10); - elmW = $el[0].offsetWidth; - elmH = $el[0].offsetHeight; + elmX = item.col * gridster.curColWidth; + elmY = item.row * gridster.curRowHeight; + elmW = item.sizeX * gridster.curColWidth; + elmH = item.sizeY * gridster.curRowHeight; originalWidth = item.sizeX; originalHeight = item.sizeY; @@ -1887,8 +1888,6 @@ return false; } - var maxLeft = gridster.curWidth - 1; - // Get the current mouse position. mouseX = e.pageX; mouseY = e.pageY; @@ -1905,6 +1904,9 @@ var dY = diffY, dX = diffX; + var maxLeft = gridster.curWidth - 1, + maxTop = gridster.calcGridsterHeight(); + if (hClass.indexOf('n') >= 0) { if (elmH - dY < getMinHeight()) { diffY = elmH - getMinHeight(); From ac3bfd6f778976be9568707d3bdb1656b633f34c Mon Sep 17 00:00:00 2001 From: "heather.roberts" Date: Mon, 25 Jan 2016 12:42:43 +1000 Subject: [PATCH 31/31] Added config option "layout" to control direction items are added in --- bower.json | 2 +- dist/angular-gridster.min.js | 4 +- package.json | 2 +- src/angular-gridster.js | 144 ++++++++++++++++++++++++++++++++++- 4 files changed, 146 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index cd39cf0b..c41429e1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.11", + "version": "0.13.12", "main": ["src/angular-gridster.js", "dist/angular-gridster.min.css"], "dependencies": { "angular": ">= 1.2.0", diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index b47a0f34..42fe1067 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -2,7 +2,7 @@ * angular-gridster * http://manifestwebdesign.github.io/angular-gridster * - * @version: 0.13.10 + * @version: 0.13.11 * @license: MIT */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;be.minSizeX||e.sizeY>e.minSizeY?(a.sizeX>a.sizeY||a.sizeY===e.minSizeY?a.sizeX--:a.sizeY--,this.autoSetItemPosition(a)):d.$broadcast("gridster-item-not-added",a)},this.getItems=function(a,b,c,d,e){var f=[];c&&d||(c=d=1),!e||e instanceof Array||(e=[e]);for(var g=0;d>g;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,d.$broadcast("gridster-item-added",a),this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&this.moveItemsDown([a],a.row+a.sizeY,b)):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),this.moveItemsDown(c,a.row+a.sizeY,b))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){var f=this;a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var g,h,i,j={};for(h=0,i=a.length;i>h;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.row0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.rowh;++h){g=a[h];var n=b-j[g.col];this.moveItemDown(g,g.row+n,c),c.push(g)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowa;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(function(){return f.$eval(m)},function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+h?(b=C-p,z=h-b):p+r+h>d&&(b=d-p-r,z=h-b),B>q+i?(c=B-q,A=i-c):q+i>=f&&(c=f-q,A=i-c),p+=b,q+=c,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,E=o.length;E>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-D.body.scrollTopb;++b)H[b].disable();H=[],g.draggable&&g.draggable.handle?(G=a.element(e[0].querySelectorAll(g.draggable.handle)),0===G.length&&(G=e)):G=e;for(var f=0,h=G.length;h>f;++f)H[f]=new d(G[f],j,k,l),H[f].enable()}}))},this.disable=function(){if(F!==!1){F=!1;for(var a=0,b=H.length;b>a;++a)H[a].disable();H=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=f.col*e.curColWidth,p=f.row*e.curRowHeight,q=f.sizeX*e.curColWidth,r=f.sizeY*e.curRowHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),document.addEventListener("mouseup",l),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;x=b.pageX,y=b.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d,i=e.curWidth-1,j=e.calcGridsterHeight();return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gj&&(f=j-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=E-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hi&&(d=i-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),document.removeEventListener("mouseup",l),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},G=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},H=null;this.enable=function(){H||(H=a.element('
'),c.append(H)),v=new b(H[0],i,k,l),v.enable()},this.disable=function(){H&&(H.remove(),H=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?(require("angular"),module.exports=b(angular)):b(a.angular)}(this,function(a){"use strict";return a.module("gridster",[]).constant("gridsterConfig",{columns:6,pushing:!0,floating:!0,swapping:!1,locking:!1,width:"auto",colWidth:"auto",rowHeight:"match",margins:[10,10],outerMargin:!0,isMobile:!1,layout:"vertical",mobileBreakPoint:600,mobileModeEnabled:!0,minColumns:1,minRows:1,maxRows:100,defaultSizeX:2,defaultSizeY:1,minSizeX:1,maxSizeX:null,minSizeY:1,maxSizeY:null,saveGridItemCalculatedHeightInMobile:!1,resizable:{enabled:!0,handles:["s","e","n","w","se","ne","sw","nw"]},draggable:{enabled:!0,scrollSensitivity:20,scrollSpeed:15}}).controller("GridsterCtrl",["gridsterConfig","$timeout","$rootScope",function(b,c,d){var e=this;a.extend(this,b),this.resizable=a.extend({},b.resizable||{}),this.draggable=a.extend({},b.draggable||{});var f=!1;this.layoutChanged=function(){f||(f=!0,c(function(){f=!1,e.loaded&&e.floatItemsUp(),e.updateHeight(e.movingItem?e.movingItem.sizeY:0)},30))},this.grid=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null},this.setOptions=function(b){if(b)if(b=a.extend({},b),b.draggable&&(a.extend(this.draggable,b.draggable),delete b.draggable),b.resizable&&(a.extend(this.resizable,b.resizable),delete b.resizable),a.extend(this,b),this.margins&&2===this.margins.length)for(var c=0,d=this.margins.length;d>c;++c)this.margins[c]=parseInt(this.margins[c],10),isNaN(this.margins[c])&&(this.margins[c]=0);else this.margins=[0,0]},this.canItemOccupy=function(a,b,c){return b>-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;be.minSizeX||e.sizeY>e.minSizeY?(a.sizeX>a.sizeY||a.sizeY===e.minSizeY?a.sizeX--:a.sizeY--,this.autoSetItemPosition(a)):d.$broadcast("gridster-item-not-added",a)},this.getItems=function(a,b,c,d,e){var f=[];c&&d||(c=d=1),!e||e instanceof Array||(e=[e]);for(var g=0;d>g;++g)for(var h=0;c>h;++h){var i=this.getItem(a+g,b+h,e);!i||e&&-1!==e.indexOf(i)||-1!==f.indexOf(i)||f.push(i)}return f},this.getBoundingBox=function(a){if(0===a.length)return null;if(1===a.length)return{row:a[0].row,col:a[0].col,sizeY:a[0].sizeY,sizeX:a[0].sizeX};for(var b=0,c=0,d=9999,e=9999,f=0,g=a.length;g>f;++f){var h=a[f];d=Math.min(h.row,d),e=Math.min(h.col,e),b=Math.max(h.row+h.sizeY,b),c=Math.max(h.col+h.sizeX,c)}return{row:d,col:e,sizeY:b-d,sizeX:c-e}},this.removeItem=function(a){for(var b=0,c=this.grid.length;c>b;++b){var d=this.grid[b];if(d){var e=d.indexOf(a);if(-1!==e){d[e]=null;break}}}this.layoutChanged()},this.getItem=function(a,b,c){!c||c instanceof Array||(c=[c]);for(var d=1;a>-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||-1===c.indexOf(h))&&h.sizeX>=e&&h.sizeY>=d)return h}++e,--f}--a,++d}return null},this.putItems=function(a){for(var b=0,c=a.length;c>b;++b)this.putItem(a[b])},this.putItem=function(a,b,c,e,f){if(("undefined"==typeof b||null===b)&&(b=a.row,c=a.col,"undefined"==typeof b||null===b))return void this.autoSetItemPosition(a);if(this.canItemOccupy(a,b,c)||(c=Math.min(this.columns-a.sizeX,Math.max(0,c)),b=Math.min(this.maxRows-a.sizeY,Math.max(0,b))),null!==a.oldRow&&"undefined"!=typeof a.oldRow){var g=a.oldRow===b&&a.oldColumn===c,h=this.grid[b]&&this.grid[b][c]===a;if(g&&h)return a.row=b,void(a.col=c);var i=this.grid[a.oldRow];i&&i[a.oldColumn]===a&&delete i[a.oldColumn]}return a.oldRow=a.row=b,a.oldColumn=a.col=c,f!==!0&&this.moveOverlappingItems(a,e),a.row>=this.maxRows-1||a.col>=this.columns-1?(this.removeItem(a),void d.$broadcast("gridster-item-removed",a)):(this.grid[a.row]||(this.grid[a.row]=[]),this.grid[a.row][a.col]=a,d.$broadcast("gridster-item-added",a),this.movingItem===a&&this.floatItemUp(a),void this.layoutChanged())},this.swapItems=function(a,b){this.grid[a.row][a.col]=b,this.grid[b.row][b.col]=a;var c=a.row,d=a.col;a.row=b.row,a.col=b.col,b.row=c,b.col=d},this.moveOverlappingItems=function(a,b){var c;this.locking===!0?(b=b||this.getItems(0,0,this.columns,this.maxRows,[a]),c=this.getItems(a.row,a.col,a.sizeX,a.sizeY),c.length>0&&("vertical"===this.layout?this.moveItemsDown([a],a.row+a.sizeY,b):"horizontal"===this.layout?this.moveItemsRight([a],a.col+a.sizeX,b):console.warn("Invalid value for layout "+this.layout))):(b?-1===b.indexOf(a)&&(b=b.slice(0),b.push(a)):b=[a],c=this.getItems(a.row,a.col,a.sizeX,a.sizeY,b),"vertical"===this.layout?this.moveItemsDown(c,a.row+a.sizeY,b):"horizontal"===this.layout?this.moveItemsRight(c,a.col+a.sizeX,b):console.warn("Invalid value for layout "+this.layout))},this.moveItemsDown=function(a,b,c){if(a&&0!==a.length){var f=this;a.sort(function(a,b){return a.row-b.row}),c=c?c.slice(0):[];var g,h,i,j={};for(h=0,i=a.length;i>h;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.row0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.rowh;++h){g=a[h];var n=b-j[g.col];this.moveItemDown(g,g.row+n,c),c.push(g)}}},this.moveItemDown=function(a,b,c){if(!(a.row>=b)){for(;a.rowh;++h){g=a[h];var k=j[g.col];("undefined"==typeof k||g.col0;){if(g.row===b&&g.col===c){if(j){if(g.sizeX>e.minSizeX||g.sizeY>e.minSizeY){g.sizeX>g.sizeY||g.sizeY===e.minSizeY?g.sizeX--:g.sizeY--,g.row=h,g.col=i,m();break}return d.$broadcast("gridster-item-not-added",g),g.col=f.columns-1,g.row=f.maxRows-1,void(l=!0)}j=!0,g.col=0,g.row=0,b=h,c=i}else g.colh;++h){g=a[h];var n=b-j[g.row];this.moveItemRight(g,g.col+n,c),c.push(g)}}},this.moveItemRight=function(a,b,c){if(!(a.col>=b)){for(;a.cola;++a){var c=this.grid[a];if(c)for(var d=0,e=c.length;e>d;++d){var f=c[d];f&&this.floatItemUp(f)}}},this.floatItemUp=function(a){if(this.floating!==!1&&this.locking!==!0){for(var b=a.col,c=a.sizeY,d=a.sizeX,e=null,f=null,g=a.row-1;g>-1;){var h=this.getItems(g,b,d,c,a);if(0!==h.length)break;e=g,f=b,--g}null!==e&&this.putItem(a,e,f)}},this.updateHeight=function(a){var b=this.minRows;a=a||0;for(var c=this.grid.length;c>=0;--c){var d=this.grid[c];if(d)for(var e=0,f=d.length;f>e;++e)d[e]&&(b=Math.max(b,c+a+d[e].sizeY))}this.gridHeight=this.maxRows-b>0?Math.min(this.maxRows,b):Math.max(this.maxRows,b)},this.pixelsToRows=function(a,b){return this.outerMargin||(a+=this.margins[0]/2),b===!0?Math.ceil(a/this.curRowHeight):b===!1?Math.floor(a/this.curRowHeight):Math.round(a/this.curRowHeight)},this.pixelsToColumns=function(a,b){return this.outerMargin||(a+=this.margins[1]/2),b===!0?Math.ceil(a/this.curColWidth):b===!1?Math.floor(a/this.curColWidth):Math.round(a/this.curColWidth)},this.calcGridsterHeight=function(){return this.gridHeight*this.curRowHeight+(this.outerMargin?this.margins[0]:-this.margins[0])}}]).directive("gridsterPreview",function(){return{replace:!0,scope:!0,require:"^gridster",template:'
',link:function(a,b,c,d){a.previewStyle=function(){return d.movingItem?{display:"block",height:d.movingItem.sizeY*d.curRowHeight-d.margins[0]+"px",width:d.movingItem.sizeX*d.curColWidth-d.margins[1]+"px",top:d.movingItem.row*d.curRowHeight+(d.outerMargin?d.margins[0]:0)+"px",left:d.movingItem.col*d.curColWidth+(d.outerMargin?d.margins[1]:0)+"px"}:{display:"none"}}}}}).directive("gridster",["$timeout","$window","$rootScope","gridsterDebounce",function(b,c,d,e){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(f){return f.prepend('
'),function(f,g,h,i){function j(a){if(i.setOptions(a),l(g[0])){if("auto"===i.width?i.curWidth=g[0].offsetWidth||parseInt(g.css("width"),10):i.curWidth=i.width,"auto"===i.colWidth?i.curColWidth=(i.curWidth+(i.outerMargin?-i.margins[1]:i.margins[1]))/i.columns:i.curColWidth=i.colWidth,i.curRowHeight=i.rowHeight,"string"==typeof i.rowHeight)if("match"===i.rowHeight)i.curRowHeight=Math.round(i.curColWidth);else if(-1!==i.rowHeight.indexOf("screen-height")){var b=document.getElementsByTagName("body")[0],c=b.clientHeight,d=i.rowHeight.split("screen-height"),e=d.length>1?parseInt(d[1].replace(/\s/g,"")):0;i.curRowHeight=(c+e)/i.minRows}else-1!==i.rowHeight.indexOf("*")?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):-1!==i.rowHeight.indexOf("/")&&(i.curRowHeight=Math.round(i.curColWidth/i.rowHeight.replace("/","").replace(" ","")));i.isMobile=i.mobileModeEnabled&&i.curWidth<=i.mobileBreakPoint;for(var f=0,h=i.grid.length;h>f;++f){var j=i.grid[f];if(j)for(var m=0,n=j.length;n>m;++m)if(j[m]){var o=j[m];o.setElementPosition(),o.setElementSizeY(),o.setElementSizeX()}}k()}}function k(){g.css("height",i.calcGridsterHeight()+"px")}i.loaded=!1,i.$element=g,f.gridster=i,g.addClass("gridster");var l=function(a){return"hidden"!==a.style.visibility&&"none"!==a.style.display},m=h.gridster;m?f.$parent.$watch(function(){return f.$eval(m)},function(a){j(a)},!0):j({}),f.$watch(function(){return i.loaded},function(){i.loaded?g.addClass("gridster-loaded"):g.removeClass("gridster-loaded")}),f.$watch(function(){return i.isMobile},function(){i.isMobile?g.addClass("gridster-mobile").removeClass("gridster-desktop"):g.removeClass("gridster-mobile").addClass("gridster-desktop"),d.$broadcast("gridster-mobile-changed",i)}),f.$watch(function(){return i.draggable},function(){d.$broadcast("gridster-draggable-changed",i)},!0),f.$watch(function(){return i.resizable},function(){d.$broadcast("gridster-resizable-changed",i)},!0),f.$watch(function(){return i.gridHeight},k),f.$watch(function(){return i.movingItem},function(){i.updateHeight(i.movingItem?i.movingItem.sizeY:0)});var n=g[0].offsetWidth||parseInt(g.css("width"),10),o=function(){var a=g[0].offsetWidth||parseInt(g.css("width"),10);a&&a!==n&&!i.movingItem&&(n=a,i.loaded&&g.removeClass("gridster-loaded"),j(),i.loaded&&g.addClass("gridster-loaded"),d.$broadcast("gridster-resized",[a,g[0].offsetHeight],i))},p=e(function(){o(),b(function(){f.$apply()})},100);f.$watch(function(){return l(g[0])},p),"function"==typeof window.addResizeListener?window.addResizeListener(g[0],p):f.$watch(function(){return g[0].offsetWidth||parseInt(g.css("width"),10)},o);var q=a.element(c);q.on("resize",p),f.$on("$destroy",function(){i.destroy(),q.off("resize",p),"function"==typeof window.removeResizeListener&&window.removeResizeListener(g[0],p)}),b(function(){f.$watch("gridster.floating",function(){i.floatItemsUp()}),i.loaded=!0},100)}}}}]).controller("GridsterItemCtrl",function(){this.$element=null,this.gridster=null,this.row=null,this.col=null,this.sizeX=null,this.sizeY=null,this.minSizeX=0,this.minSizeY=0,this.maxSizeX=null,this.maxSizeY=null,this.init=function(a,b){this.$element=a,this.gridster=b,this.sizeX=b.defaultSizeX,this.sizeY=b.defaultSizeY},this.destroy=function(){this.gridster=null,this.$element=null},this.toJSON=function(){return{row:this.row,col:this.col,sizeY:this.sizeY,sizeX:this.sizeX}},this.isMoving=function(){return this.gridster.movingItem===this},this.setPosition=function(a,b){this.gridster.putItem(this,a,b),this.isMoving()||this.setElementPosition()},this.setSize=function(a,b,c){a=a.toUpperCase();var d="size"+a,e="Size"+a;if(""!==b){b=parseInt(b,10),(isNaN(b)||0===b)&&(b=this.gridster["default"+e]);var f="X"===a?this.gridster.columns:this.gridster.maxRows;this["max"+e]&&(f=Math.min(this["max"+e],f)),this.gridster["max"+e]&&(f=Math.min(this.gridster["max"+e],f)),"X"===a&&this.cols?f-=this.cols:"Y"===a&&this.rows&&(f-=this.rows);var g=0;this["min"+e]&&(g=Math.max(this["min"+e],g)),this.gridster["min"+e]&&(g=Math.max(this.gridster["min"+e],g)),b=Math.max(Math.min(b,f),g);var h=this[d]!==b||this["old"+e]&&this["old"+e]!==b;return this["old"+e]=this[d]=b,this.isMoving()||this["setElement"+e](),!c&&h&&(this.gridster.moveOverlappingItems(this),this.gridster.layoutChanged()),h}},this.setSizeY=function(a,b){return this.setSize("Y",a,b)},this.setSizeX=function(a,b){return this.setSize("X",a,b)},this.setElementPosition=function(){this.gridster.isMobile?this.$element.css({marginLeft:this.gridster.margins[0]+"px",marginRight:this.gridster.margins[0]+"px",marginTop:this.gridster.margins[1]+"px",marginBottom:this.gridster.margins[1]+"px",top:"",left:""}):this.$element.css({margin:0,top:this.row*this.gridster.curRowHeight+(this.gridster.outerMargin?this.gridster.margins[0]:0)+"px",left:this.col*this.gridster.curColWidth+(this.gridster.outerMargin?this.gridster.margins[1]:0)+"px"})},this.setElementSizeY=function(){this.gridster.isMobile&&!this.gridster.saveGridItemCalculatedHeightInMobile?this.$element.css("height",""):this.$element.css("height",this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]+"px")},this.setElementSizeX=function(){this.gridster.isMobile?this.$element.css("width",""):this.$element.css("width",this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]+"px")},this.getElementSizeX=function(){return this.sizeX*this.gridster.curColWidth-this.gridster.margins[1]},this.getElementSizeY=function(){return this.sizeY*this.gridster.curRowHeight-this.gridster.margins[0]}}).factory("GridsterTouch",[function(){return function(a,b,c,d){var e,f,g={},h=function(a){if(Object.keys)return Object.keys(a).length;var b,c=0;for(b in a)++c;return c},i=function(a){for(var b=0,c=0,d=navigator.userAgent.match(/\bMSIE\b/),e=a;null!=e;e=e.offsetParent)d&&(!document.documentMode||document.documentMode<8)&&"relative"===e.currentStyle.position&&e.offsetParent&&"relative"===e.offsetParent.currentStyle.position&&e.offsetLeft===e.offsetParent.offsetLeft?c+=e.offsetTop:(b+=e.offsetLeft,c+=e.offsetTop);return{x:b,y:c}},j=i(a),k=function(e){if("mousemove"!==e.type||0!==h(g)){for(var f=!0,m=e.changedTouches?e.changedTouches:[e],n=0;np+h?(b=C-p,z=h-b):p+r+h>d&&(b=d-p-r,z=h-b),B>q+i?(c=B-q,A=i-c):q+i>=f&&(c=f-q,A=i-c),p+=b,q+=c,e.css({top:q+"px",left:p+"px"}),n(a),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing")?!1:(z=A=0,o(b),!0)}function m(a){e.addClass("gridster-item-moving"),g.movingItem=h,g.updateHeight(h.sizeY),f.$apply(function(){g.draggable&&g.draggable.start&&g.draggable.start(a,e,i)})}function n(a){var b=h.row,d=h.col,j=g.draggable&&g.draggable.drag,k=g.draggable.scrollSensitivity,l=g.draggable.scrollSpeed,m=g.pixelsToRows(q),n=g.pixelsToColumns(p),o=g.getItems(m,n,h.sizeX,h.sizeY,h),r=0!==o.length;if(g.swapping===!0&&r&&!g.locking){var s=g.getBoundingBox(o),t=s.sizeX===h.sizeX&&s.sizeY===h.sizeY,u=s.row===b,v=s.col===d,w=s.row===m&&s.col===n,x=u||v;if(t&&1===o.length){if(w)g.swapItems(h,o[0]);else if(x)return}else if(s.sizeX<=h.sizeX&&s.sizeY<=h.sizeY&&x)for(var y=h.row<=m?h.row:m+h.sizeY,z=h.col<=n?h.col:n+h.sizeX,A=y-s.row,B=z-s.col,C=0,E=o.length;E>C;++C){var F=o[C],G=g.getItems(F.row+A,F.col+B,F.sizeX,F.sizeY,h);0===G.length&&g.putItem(F,F.row+A,F.col+B)}}(g.pushing!==!1&&!g.locking||!r)&&(h.row=m,h.col=n),a.pageY-D.body.scrollTopb;++b)H[b].disable();H=[],g.draggable&&g.draggable.handle?(G=a.element(e[0].querySelectorAll(g.draggable.handle)),0===G.length&&(G=e)):G=e;for(var f=0,h=G.length;h>f;++f)H[f]=new d(G[f],j,k,l),H[f].enable()}}))},this.disable=function(){if(F!==!1){F=!1;for(var a=0,b=H.length;b>a;++a)H[a].disable();H=[]}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){this.disable()},this.updateDraggable=function(a){i.draggable=a}}return e}]).factory("GridsterResizable",["GridsterTouch",function(b){function c(c,d,e,f,g){function h(h){function i(b){if(g.resizable===!1)return a.element(document).find("body").addClass("action-not-allowed"),!1;switch(b.which){case 1:break;case 2:case 3:return}return u=e.draggable.enabled,u&&(e.draggable.enabled=!1,d.$broadcast("gridster-draggable-changed",e)),z=b.pageX,A=b.pageY,o=f.col*e.curColWidth,p=f.row*e.curRowHeight,q=f.sizeX*e.curColWidth,r=f.sizeY*e.curRowHeight,s=f.sizeX,t=f.sizeY,j(b),!0}function j(a){c.addClass("gridster-item-moving"),c.addClass("gridster-item-resizing"),document.addEventListener("mouseup",l),e.movingItem=f,f.setElementSizeX(),f.setElementSizeY(),f.setElementPosition(),e.updateHeight(1),d.$apply(function(){e.resizable&&e.resizable.start&&e.resizable.start(a,c,g)})}function k(b){if(a.element(document).find("body").hasClass("action-not-allowed"))return!1;x=b.pageX,y=b.pageY;var d=x-z+B,f=y-A+C;B=C=0,z=x,A=y;var g=f,h=d,i=e.curWidth-1,j=e.calcGridsterHeight();return w.indexOf("n")>=0&&(r-gp+g&&(f=D-p,C=g-f),p+=f,r-=f),w.indexOf("s")>=0&&(r+gj&&(f=j-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-ho+h&&(d=E-o,B=h-d),o+=d,q-=d),w.indexOf("e")>=0&&(q+hi&&(d=i-o-q,B=h-d),q+=d),c.css({top:p+"px",left:o+"px",width:q+"px",height:r+"px"}),m(b),!0}function l(b){return a.element(document).find("body").hasClass("action-not-allowed")?(a.element(document).find("body").removeClass("action-not-allowed"),!1):(e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),document.removeEventListener("mouseup",l),B=C=0,n(b),!0)}function m(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;-1!==["w","nw","sw"].indexOf(h)&&(m=e.pixelsToColumns(o,!1));var n=f.row;-1!==["n","ne","nw"].indexOf(h)&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;-1===["n","s"].indexOf(h)&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;-1===["e","w"].indexOf(h)&&(t=e.pixelsToRows(r,!0));var u=n>-1&&m>-1&&s+m<=e.columns&&t+n<=e.maxRows;u&&(e.pushing!==!1&&!e.locking||0===e.getItems(n,m,s,t,f).length)&&(f.row=n,f.col=m,f.sizeX=s,f.sizeY=t);var v=f.row!==b||f.col!==i||f.sizeX!==j||f.sizeY!==k;(l||v)&&d.$apply(function(){l&&e.resizable.resize(a,c,g)})}function n(a){c.removeClass("gridster-item-moving"),c.removeClass("gridster-item-resizing"),e.movingItem=null,f.setPosition(f.row,f.col),f.setSizeY(Math.min(e.curRowHeight-f.row,f.sizeY)),f.setSizeX(Math.min(e.columns-f.col,f.sizeX)),d.$apply(function(){e.resizable&&e.resizable.stop&&e.resizable.stop(a,c,g)})}var o,p,q,r,s,t,u,v,w=h,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=function(){return(f.minSizeY?f.minSizeY:1)*e.curRowHeight-e.margins[0]},G=function(){return(f.minSizeX?f.minSizeX:1)*e.curColWidth-e.margins[1]},H=null;this.enable=function(){H||(H=a.element('
'),c.append(H)),v=new b(H[0],i,k,l),v.enable()},this.disable=function(){H&&(H.remove(),H=null),v.disable(),v=void 0},this.destroy=function(){this.disable()}}var i=[],j=e.resizable.handles;"string"==typeof j&&(j=e.resizable.handles.split(","));for(var k=!1,l=0,m=j.length;m>l;l++)i.push(new h(j[l]));this.enable=function(){if(!k){for(var a=0,b=i.length;b>a;a++)i[a].enable();k=!0}},this.disable=function(){if(k){for(var a=0,b=i.length;b>a;a++)i[a].disable();k=!1}},this.toggle=function(a){a?this.enable():this.disable()},this.destroy=function(){for(var a=0,b=i.length;b>a;a++)i[a].destroy()},this.updateResizable=function(a){g.resizable=a}}return c}]).factory("gridsterDebounce",function(){return function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}}).directive("gridsterItem",["$parse","GridsterDraggable","GridsterResizable","gridsterDebounce",function(a,b,c,d){return{scope:!0,restrict:"EA",controller:"GridsterItemCtrl",controllerAs:"gridsterItem",require:["^gridster","gridsterItem"],link:function(e,f,g,h){function i(){o.setPosition(o.row,o.col),r.row&&r.row.assign&&r.row.assign(e,o.row),r.col&&r.col.assign&&r.col.assign(e,o.col)}function j(){var a=o.setSizeX(o.sizeX,!0);a&&r.sizeX&&r.sizeX.assign&&r.sizeX.assign(e,o.sizeX);var b=o.setSizeY(o.sizeY,!0);b&&r.sizeY&&r.sizeY.assign&&r.sizeY.assign(e,o.sizeY),n.locking||!a&&!b||(n.moveOverlappingItems(o),n.layoutChanged(),e.$broadcast("gridster-item-resized",o))}function k(){var a=document.createElement("div"),b={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var c in b)if(void 0!==a.style[c])return b[c]}var l,m=g.gridsterItem,n=h[0],o=h[1];if(e.gridster=n,e.myGridsterItem=e.$eval(g.gridsterItem),m){var p=a(m);l=p(e)||{},!l&&p.assign&&(l={row:o.row,col:o.col,sizeX:o.sizeX,sizeY:o.sizeY,minSizeX:0,minSizeY:0,maxSizeX:null,maxSizeY:null,draggable:!0,resizable:!0},p.assign(e,l))}else l=g;o.init(f,n),f.addClass("gridster-item");for(var q=["minSizeX","maxSizeX","minSizeY","maxSizeY","sizeX","sizeY","row","col","draggable","resizable"],r={},s=[],t=function(b){var c;if("string"==typeof l[b])c=l[b];else if("string"==typeof l[b.toLowerCase()])c=l[b.toLowerCase()];else{if(!m)return;c=m+"."+b}s.push('"'+b+'":'+c),r[b]=a(c);var d=r[b](e);"number"==typeof d&&(o[b]=d)},u=0,v=q.length;v>u;++u)t(q[u]);var w="{"+s.join(",")+"}";e.$watchCollection(w,function(a,b){for(var c in a){var d=a[c],e=b[c];e!==d&&(d=parseInt(d,10),isNaN(d)||(o[c]=d))}}),e.$watch(function(){return o.row+","+o.col},i),e.$watch(function(){return o.sizeY+","+o.sizeX+","+o.minSizeX+","+o.maxSizeX+","+o.minSizeY+","+o.maxSizeY},j);var x=new b(f,e,n,o,l),y=new c(f,e,n,o,l),z=function(){y.toggle(!n.isMobile&&n.resizable&&n.resizable.enabled)};z();var A=function(){x.toggle(!n.isMobile&&n.draggable&&n.draggable.enabled)};A(),e.$on("gridster-draggable-changed",A),e.$on("gridster-resizable-changed",z),e.$on("gridster-resized",z),e.$on("gridster-mobile-changed",function(){z(),A()}),e.$watch("myGridsterItem.draggable",function(a){x.updateDraggable(a)},!0),e.$watch("myGridsterItem.resizable",function(a){y.updateResizable(a)},!0);var B=d(function(){e.$apply(function(){e.$broadcast("gridster-item-transition-end",o)})},50);return f.on(k(),B),e.$broadcast("gridster-item-initialized",o),e.$on("$destroy",function(){try{y.destroy(),x.destroy()}catch(a){}try{n.removeItem(o)}catch(a){}try{o.destroy()}catch(a){}})}}}]).directive("gridsterNoDrag",function(){return{restrict:"A",link:function(a,b){b.addClass("gridster-no-drag")}}})}); \ No newline at end of file diff --git a/package.json b/package.json index 59c49545..590cb983 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.11", + "version": "0.13.12", "description": "This directive gives you gridster behavior", "license": "MIT", "homepage": "http://manifestwebdesign.github.io/angular-gridster", diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 9d7171ee..4f30da69 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -34,6 +34,7 @@ margins: [10, 10], // margins in between grid items outerMargin: true, isMobile: false, // toggle mobile view + layout: 'vertical', // "vertical" add new items top -> bottom "horizontal" left -> right mobileBreakPoint: 600, // width threshold to toggle mobile mode mobileModeEnabled: true, // whether or not to toggle mobile mode when screen width is less than mobileBreakPoint minColumns: 1, // minimum amount of columns the grid can scale down to @@ -422,7 +423,13 @@ // move this item down if it overlaps any if (overlappingItems.length > 0) { - this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); + if (this.layout === 'vertical') { + this.moveItemsDown([item], item.row + item.sizeY, ignoreItems); + } else if (this.layout === 'horizontal') { + this.moveItemsRight([item], item.col + item.sizeX, ignoreItems); + } else { + console.warn('Invalid value for layout ' + this.layout); + } } } else { // don't move item, so ignore it @@ -441,7 +448,13 @@ item.sizeY, ignoreItems ); - this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + if (this.layout === 'vertical') { + this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + } else if (this.layout === 'horizontal') { + this.moveItemsRight(overlappingItems, item.col + item.sizeX, ignoreItems); + } else { + console.warn('Invalid value for layout ' + this.layout); + } } }; @@ -572,6 +585,133 @@ this.putItem(item, item.row, item.col, ignoreItems, this.locking); }; + /** + * Moves an array of items to a specified col + * + * @param {Array} items The items to move + * @param {Number} newCol The target col + * @param {Array} ignoreItems + */ + this.moveItemsRight = function(items, newCol, ignoreItems) { + if (!items || items.length === 0) { + return; + } + + var that = this; + + items.sort(function(a, b) { + return a.col - b.col; + }); + + ignoreItems = ignoreItems ? ignoreItems.slice(0) : []; + var topCols = {}, + item, i, l; + + // calculate the top cols in each row + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var topCol = topCols[item.col]; + if (typeof topCol === 'undefined' || item.col < topCol) { + topCols[item.row] = item.col; + } + } + + //calculate next free position to place item + if (this.locking === true) { + + var noSpace = false; + + var fitItem = function() { + var overlap = that.getItems(item.row, item.col, item.sizeX, item.sizeY); + var maxRow = that.maxRows - 1, + maxCol = that.columns - 1, + startRow = item.row, + startCol = item.col, + restarted = false; + + while (overlap.length > 0) { + if (item.row === maxRow && item.col === maxCol) { + // if checked all space after item, now check space before it + if (!restarted) { + restarted = true; + item.col = 0; + item.row = 0; + maxRow = startRow; + maxCol = startCol; + } else { + // if item couldn't be added, shrink it until it can fit somewhere + if (item.sizeX > gridster.minSizeX || item.sizeY > gridster.minSizeY) { + if (item.sizeX > item.sizeY || item.sizeY === gridster.minSizeY) { + item.sizeX--; + } else { + item.sizeY--; + } + item.row = startRow; + item.col = startCol; + fitItem(); + break; + } else { + // no space left at all + $rootScope.$broadcast('gridster-item-not-added', item); + item.col = that.columns - 1; + item.row = that.maxRows - 1; + noSpace = true; + return; + } + } + } else { + if (item.col < maxCol) { + ++item.col; + } else { + item.col = 0; + ++item.row; + } + } + + if (item.row + item.sizeY < that.maxRows && item.col + item.sizeX < that.columns) { + overlap = that.getItems(item.row, item.col, item.sizeX, item.sizeY); + } + } + }; + fitItem(); + + if (noSpace === true) { + return; + } + + this.putItem(item, item.row, item.col, ignoreItems, true); + + } else { + // move each item down from the top row in its column to the row + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var colsToMove = newCol - topCols[item.row]; + this.moveItemRight(item, item.col + colsToMove, ignoreItems); + ignoreItems.push(item); + } + } + }; + + /** + * Moves an item right to a specified col + * + * @param {Object} item The item to move + * @param {Number} newCol The target col + * @param {Array} ignoreItems + */ + this.moveItemRight = function(item, newCol, ignoreItems) { + if (item.col >= newCol) { + return; + } + while (item.col < newCol) { + ++item.col; + if (!this.locking) { + this.moveOverlappingItems(item, ignoreItems); + } + } + this.putItem(item, item.row, item.col, ignoreItems, this.locking); + }; + /** * Moves all items up as much as possible */