diff --git a/bower.json b/bower.json index b5353fe1..c41429e1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "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.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 b1e4ed40..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.5 + * @version: 0.13.11 * @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?(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 9663fa50..590cb983 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-gridster", - "version": "0.13.5", + "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 174f49c5..4f30da69 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -8,7 +8,8 @@ define(['angular'], factory); } else if (typeof exports === 'object') { // CommonJS - module.exports = factory(require('angular')); + require('angular'); + module.exports = factory(angular); } else { // Browser, nothing "exported". Only registered as a module with angular. factory(root.angular); @@ -25,12 +26,15 @@ 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 + // !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, 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 + 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 @@ -54,8 +58,8 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', - function(gridsterConfig, $timeout) { + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', '$rootScope', + function(gridsterConfig, $timeout, $rootScope) { var gridster = this; @@ -164,7 +168,19 @@ } } } - throw new Error('Unable to place 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); + } }; /** @@ -235,7 +251,6 @@ }; }; - /** * Removes an item from the grid * @@ -307,8 +322,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) { + this.putItem = function(item, row, column, ignoreItems, leaveOverlapping) { // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; @@ -345,12 +361,23 @@ item.oldRow = item.row = row; item.oldColumn = item.col = column; - this.moveOverlappingItems(item, ignoreItems); + if (leaveOverlapping !== true) { + this.moveOverlappingItems(item, ignoreItems); + } + + // 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; + } - 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; + + $rootScope.$broadcast('gridster-item-added', item); if (this.movingItem === item) { this.floatItemUp(item); @@ -383,23 +410,52 @@ * @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); + 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 + overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY); + + // move this item down if it overlaps any + if (overlappingItems.length > 0) { + 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 + 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 + overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + 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); + } + } }; /** @@ -413,6 +469,9 @@ if (!items || items.length === 0) { return; } + + var that = this; + items.sort(function(a, b) { return a.row - b.row; }); @@ -430,12 +489,79 @@ } } - // 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.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.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 (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 rowsToMove = newRow - topRows[item.col]; + this.moveItemDown(item, item.row + rowsToMove, ignoreItems); + ignoreItems.push(item); + } } }; @@ -452,16 +578,145 @@ } while (item.row < newRow) { ++item.row; - this.moveOverlappingItems(item, ignoreItems); + if (!this.locking) { + this.moveOverlappingItems(item, ignoreItems); + } } - this.putItem(item, item.row, item.col, ignoreItems); + 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 */ 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) { @@ -484,7 +739,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, @@ -570,6 +825,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]); + }; } ]) @@ -659,6 +922,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) { @@ -690,7 +959,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 { @@ -731,7 +1002,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() { @@ -999,7 +1270,6 @@ this.getElementSizeY = function() { return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); }; - }) .factory('GridsterTouch', [function() { @@ -1142,6 +1412,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 +1456,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 +1525,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 +1545,11 @@ window.event.returnValue = false; return false; }); + target.attachEvent('dragend', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); } }; @@ -1309,6 +1587,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 +1595,7 @@ target.detachEvent('onmousedown'); target.detachEvent('onmousemove'); target.detachEvent('onmouseup'); + target.detachEvent('ondragend'); } }; @@ -1337,7 +1617,6 @@ mOffY = 0, minTop = 0, - maxTop = 9999, minLeft = 0, realdocument = $document[0]; @@ -1345,10 +1624,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 @@ -1379,10 +1665,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; @@ -1397,8 +1683,6 @@ return false; } - var maxLeft = gridster.curWidth - 1; - // Get the current mouse position. mouseX = e.pageX; mouseY = e.pageY; @@ -1412,6 +1696,9 @@ lastMouseX = mouseX; lastMouseY = mouseY; + var maxLeft = gridster.curWidth - 1, + maxTop = gridster.calcGridsterHeight(); + var dX = diffX, dY = diffY; if (elmX + dX < minLeft) { @@ -1425,8 +1712,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; @@ -1444,6 +1731,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; } @@ -1480,7 +1773,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, @@ -1518,7 +1811,7 @@ } } - if (gridster.pushing !== false || !hasItemsInTheWay) { + if ((gridster.pushing !== false && !gridster.locking) || !hasItemsInTheWay) { item.row = row; item.col = col; } @@ -1548,7 +1841,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; } @@ -1627,6 +1920,10 @@ this.destroy = function() { this.disable(); }; + + this.updateDraggable = function(draggable) { + itemOptions.draggable = draggable; + }; } return GridsterDraggable; @@ -1650,7 +1947,6 @@ mOffY = 0, minTop = 0, - maxTop = 9999, minLeft = 0; var getMinHeight = function() { @@ -1664,6 +1960,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 @@ -1686,10 +1989,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; @@ -1702,6 +2005,7 @@ function resizeStart(e) { $el.addClass('gridster-item-moving'); $el.addClass('gridster-item-resizing'); + document.addEventListener('mouseup', mouseUp); gridster.movingItem = item; @@ -1719,7 +2023,10 @@ } function mouseMove(e) { - var maxLeft = gridster.curWidth - 1; + + if (angular.element(document).find('body').hasClass('action-not-allowed')) { + return false; + } // Get the current mouse position. mouseX = e.pageX; @@ -1737,6 +2044,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(); @@ -1794,12 +2104,20 @@ } 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; scope.$broadcast('gridster-draggable-changed', gridster); } + document.removeEventListener('mouseup', mouseUp); + mOffX = mOffY = 0; resizeStop(e); @@ -1838,9 +2156,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; @@ -1864,8 +2181,8 @@ gridster.movingItem = null; item.setPosition(item.row, item.col); - item.setSizeY(item.sizeY); - item.setSizeX(item.sizeX); + item.setSizeY(Math.min(gridster.curRowHeight - item.row, item.sizeY)); + item.setSizeX(Math.min(gridster.columns - item.col, item.sizeX)); scope.$apply(function() { if (gridster.resizable && gridster.resizable.stop) { @@ -1946,6 +2263,10 @@ handles[c].destroy(); } }; + + this.updateResizable = function(resizable) { + itemOptions.resizable = resizable; + }; } return GridsterResizable; }]) @@ -1995,6 +2316,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" @@ -2011,7 +2333,9 @@ minSizeX: 0, minSizeY: 0, maxSizeX: null, - maxSizeY: null + maxSizeY: null, + draggable: true, + resizable: true }; $optionsGetter.assign(scope, options); } @@ -2023,7 +2347,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 = []; @@ -2097,8 +2421,8 @@ $getters.sizeY.assign(scope, item.sizeY); } - if (changedX || changedY) { - item.gridster.moveOverlappingItems(item); + if (!gridster.locking && (changedX || changedY)) { + gridster.moveOverlappingItems(item); gridster.layoutChanged(); scope.$broadcast('gridster-item-resized', item); } @@ -2129,6 +2453,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