diff --git a/demo/common/script.js b/demo/common/script.js new file mode 100644 index 00000000..287be662 --- /dev/null +++ b/demo/common/script.js @@ -0,0 +1,24 @@ +'use strict'; +angular.module('app', ['gridster', 'ui.bootstrap', 'ngRoute']) + .config(['$routeProvider', + function($routeProvider) { + $routeProvider + .when('/main', { + templateUrl: 'demo/main/view.html', + controller: 'MainCtrl' + }) + .when('/dashboard', { + templateUrl: 'demo/dashboard/view.html', + controller: 'DashboardCtrl' + }) + .otherwise({ + redirectTo: '/main' + }); + } + ]) + .controller('RootCtrl', function($scope) { + $scope.$on('$locationChangeStart', function(e, next, current) { + $scope.page = next.split('/').splice(-1); + $scope.styleUrl = 'demo/' + $scope.page + '/style.css' + }); + }); diff --git a/demo/dashboard/script.js b/demo/dashboard/script.js index 21b0cf9c..49dcde56 100644 --- a/demo/dashboard/script.js +++ b/demo/dashboard/script.js @@ -1,152 +1,154 @@ angular.module('app') -.controller('DashboardCtrl', ['$scope', '$timeout', - function($scope, $timeout) { - $scope.gridsterOptions = { - margins: [20, 20], - columns: 4, - draggable: { - handle: 'h3' - } - }; - - $scope.dashboards = { - '1': { - id: '1', - name: 'Home', - widgets: [{ - col: 0, - row: 0, - sizeY: 1, - sizeX: 1, - name: "Widget 1" - }, { - col: 2, - row: 1, - sizeY: 1, - sizeX: 1, - name: "Widget 2" - }] - }, - '2': { - id: '2', - name: 'Other', - widgets: [{ - col: 1, - row: 1, - sizeY: 1, - sizeX: 2, - name: "Other Widget 1" - }, { - col: 1, - row: 3, - sizeY: 1, - sizeX: 1, - name: "Other Widget 2" - }] - } - }; + .controller('DashboardCtrl', ['$scope', '$timeout', + function($scope, $timeout) { + $scope.gridsterOptions = { + margins: [20, 20], + columns: 4, + draggable: { + handle: 'h3' + } + }; + + $scope.visible = false; + + $scope.dashboards = { + '1': { + id: '1', + name: 'Home', + widgets: [{ + col: 0, + row: 0, + sizeY: 1, + sizeX: 1, + name: "Widget 1" + }, { + col: 2, + row: 1, + sizeY: 1, + sizeX: 1, + name: "Widget 2" + }] + }, + '2': { + id: '2', + name: 'Other', + widgets: [{ + col: 1, + row: 1, + sizeY: 1, + sizeX: 2, + name: "Other Widget 1" + }, { + col: 1, + row: 3, + sizeY: 1, + sizeX: 1, + name: "Other Widget 2" + }] + } + }; - $scope.clear = function() { - $scope.dashboard.widgets = []; - }; + $scope.clear = function() { + $scope.dashboard.widgets = []; + }; - $scope.addWidget = function() { - $scope.dashboard.widgets.push({ - name: "New Widget", - sizeX: 1, - sizeY: 1 + $scope.addWidget = function() { + $scope.dashboard.widgets.push({ + name: "New Widget", + sizeX: 1, + sizeY: 1 + }); + }; + + $scope.$watch('selectedDashboardId', function(newVal, oldVal) { + if (newVal !== oldVal) { + $scope.dashboard = $scope.dashboards[newVal]; + } else { + $scope.dashboard = $scope.dashboards[1]; + } }); - }; - $scope.$watch('selectedDashboardId', function(newVal, oldVal) { - if (newVal !== oldVal) { - $scope.dashboard = $scope.dashboards[newVal]; - } else { - $scope.dashboard = $scope.dashboards[1]; - } - }); + // init dashboard + $scope.selectedDashboardId = '1'; - // init dashboard - $scope.selectedDashboardId = '1'; + } + ]) + + .controller('CustomWidgetCtrl', ['$scope', '$uibModal', + function($scope, $modal) { + + $scope.remove = function(widget) { + $scope.dashboard.widgets.splice($scope.dashboard.widgets.indexOf(widget), 1); + }; + + $scope.openSettings = function(widget) { + $modal.open({ + scope: $scope, + templateUrl: 'demo/dashboard/widget_settings.html', + controller: 'WidgetSettingsCtrl', + resolve: { + widget: function() { + return widget; + } + } + }); + }; - } -]) + } + ]) -.controller('CustomWidgetCtrl', ['$scope', '$modal', - function($scope, $modal) { + .controller('WidgetSettingsCtrl', ['$scope', '$timeout', '$rootScope', '$uibModalInstance', 'widget', + function($scope, $timeout, $rootScope, $modalInstance, widget) { + $scope.widget = widget; - $scope.remove = function(widget) { - $scope.dashboard.widgets.splice($scope.dashboard.widgets.indexOf(widget), 1); - }; + $scope.form = { + name: widget.name, + sizeX: widget.sizeX, + sizeY: widget.sizeY, + col: widget.col, + row: widget.row + }; - $scope.openSettings = function(widget) { - $modal.open({ - scope: $scope, - templateUrl: 'demo/dashboard/widget_settings.html', - controller: 'WidgetSettingsCtrl', - resolve: { - widget: function() { - return widget; - } - } - }); - }; - - } -]) - -.controller('WidgetSettingsCtrl', ['$scope', '$timeout', '$rootScope', '$modalInstance', 'widget', - function($scope, $timeout, $rootScope, $modalInstance, widget) { - $scope.widget = widget; - - $scope.form = { - name: widget.name, - sizeX: widget.sizeX, - sizeY: widget.sizeY, - col: widget.col, - row: widget.row - }; - - $scope.sizeOptions = [{ - id: '1', - name: '1' - }, { - id: '2', - name: '2' - }, { - id: '3', - name: '3' - }, { - id: '4', - name: '4' - }]; - - $scope.dismiss = function() { - $modalInstance.dismiss(); - }; - - $scope.remove = function() { - $scope.dashboard.widgets.splice($scope.dashboard.widgets.indexOf(widget), 1); - $modalInstance.close(); - }; - - $scope.submit = function() { - angular.extend(widget, $scope.form); - - $modalInstance.close(widget); - }; - - } -]) - -// helper code -.filter('object2Array', function() { - return function(input) { - var out = []; - for (i in input) { - out.push(input[i]); + $scope.sizeOptions = [{ + id: '1', + name: '1' + }, { + id: '2', + name: '2' + }, { + id: '3', + name: '3' + }, { + id: '4', + name: '4' + }]; + + $scope.dismiss = function() { + $modalInstance.dismiss(); + }; + + $scope.remove = function() { + $scope.dashboard.widgets.splice($scope.dashboard.widgets.indexOf(widget), 1); + $modalInstance.close(); + }; + + $scope.submit = function() { + angular.extend(widget, $scope.form); + + $modalInstance.close(widget); + }; + + } + ]) + + // helper code + .filter('object2Array', function() { + return function(input) { + var out = []; + for (i in input) { + out.push(input[i]); + } + return out; } - return out; - } -}); + }); diff --git a/demo/dashboard/view.html b/demo/dashboard/view.html index fa61b8db..0fe14ad8 100644 --- a/demo/dashboard/view.html +++ b/demo/dashboard/view.html @@ -4,9 +4,8 @@

Dashboard

- -
+
-
\ No newline at end of file +
diff --git a/demo/main/script.js b/demo/main/script.js index e97ff89f..476ea2c4 100644 --- a/demo/main/script.js +++ b/demo/main/script.js @@ -1,178 +1,178 @@ angular.module('app') -.directive('integer', function() { - return { - require: 'ngModel', - link: function(scope, ele, attr, ctrl) { - ctrl.$parsers.unshift(function(viewValue) { - if (viewValue === '' || viewValue === null || typeof viewValue === 'undefined') { - return null; - } - return parseInt(viewValue, 10); - }); - } - }; -}) + .directive('integer', function() { + return { + require: 'ngModel', + link: function(scope, ele, attr, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + if (viewValue === '' || viewValue === null || typeof viewValue === 'undefined') { + return null; + } + return parseInt(viewValue, 10); + }); + } + }; + }) -.controller('MainCtrl', function($scope) { + .controller('MainCtrl', function($scope) { - $scope.gridsterOpts = { - margins: [20, 20], - outerMargin: false, - pushing: true, - floating: true, - draggable: { - enabled: false - }, - resizable: { - enabled: false, - handles: ['n', 'e', 's', 'w', 'se', 'sw'] - } - }; + $scope.gridsterOpts = { + margins: [20, 20], + outerMargin: false, + pushing: true, + floating: true, + draggable: { + enabled: false + }, + resizable: { + enabled: false, + handles: ['n', 'e', 's', 'w', 'se', 'sw'] + } + }; - // these map directly to gridsterItem options - $scope.standardItems = [{ - sizeX: 2, - sizeY: 1, - row: 0, - col: 0 - }, { - sizeX: 2, - sizeY: 2, - row: 0, - col: 2 - }, { - sizeX: 2, - sizeY: 1, - row: 2, - col: 1 - }, { - sizeX: 1, - sizeY: 1, - row: 2, - col: 3 - }, { - sizeX: 1, - sizeY: 1, - row: 2, - col: 4 - }, { - sizeX: 1, - sizeY: 1, - row: 0, - col: 4 - }, { - sizeX: 1, - sizeY: 1, - row: 0, - col: 5 - }, { - sizeX: 2, - sizeY: 1, - row: 1, - col: 0 - }, { - sizeX: 1, - sizeY: 1, - row: 1, - col: 4 - }, { - sizeX: 1, - sizeY: 2, - row: 1, - col: 5 - }, { - sizeX: 1, - sizeY: 1, - row: 2, - col: 0 - }]; + // these map directly to gridsterItem options + $scope.standardItems = [{ + sizeX: 2, + sizeY: 1, + row: 0, + col: 0 + }, { + sizeX: 2, + sizeY: 2, + row: 0, + col: 2 + }, { + sizeX: 2, + sizeY: 1, + row: 2, + col: 1 + }, { + sizeX: 1, + sizeY: 1, + row: 2, + col: 3 + }, { + sizeX: 1, + sizeY: 1, + row: 2, + col: 4 + }, { + sizeX: 1, + sizeY: 1, + row: 0, + col: 4 + }, { + sizeX: 1, + sizeY: 1, + row: 0, + col: 5 + }, { + sizeX: 2, + sizeY: 1, + row: 1, + col: 0 + }, { + sizeX: 1, + sizeY: 1, + row: 1, + col: 4 + }, { + sizeX: 1, + sizeY: 2, + row: 1, + col: 5 + }, { + sizeX: 1, + sizeY: 1, + row: 2, + col: 0 + }]; - // these are non-standard, so they require mapping options - $scope.customItems = [{ - size: { - x: 2, - y: 1 - }, - position: [0, 0] - }, { - size: { - x: 2, - y: 2 - }, - position: [0, 2] - }, { - size: { - x: 1, - y: 1 - }, - position: [1, 4] - }, { - size: { - x: 1, - y: 2 - }, - position: [1, 5] - }, { - size: { - x: 1, - y: 1 - }, - position: [2, 0] - }, { - size: { - x: 2, - y: 1 - }, - position: [2, 1] - }, { - size: { - x: 1, - y: 1 - }, - position: [2, 3] - }, { - size: { - x: 1, - y: 1 - }, - position: [0, 4] - }, { - size: { - x: 1, - y: 1 - }, - position: [0, 5] - }, { - size: { - x: 2, - y: 1 - }, - position: [1, 0] - }, { - size: { - x: 1, - y: 1 - }, - position: [2, 4] - }]; + // these are non-standard, so they require mapping options + $scope.customItems = [{ + size: { + x: 2, + y: 1 + }, + position: [0, 0] + }, { + size: { + x: 2, + y: 2 + }, + position: [0, 2] + }, { + size: { + x: 1, + y: 1 + }, + position: [1, 4] + }, { + size: { + x: 1, + y: 2 + }, + position: [1, 5] + }, { + size: { + x: 1, + y: 1 + }, + position: [2, 0] + }, { + size: { + x: 2, + y: 1 + }, + position: [2, 1] + }, { + size: { + x: 1, + y: 1 + }, + position: [2, 3] + }, { + size: { + x: 1, + y: 1 + }, + position: [0, 4] + }, { + size: { + x: 1, + y: 1 + }, + position: [0, 5] + }, { + size: { + x: 2, + y: 1 + }, + position: [1, 0] + }, { + size: { + x: 1, + y: 1 + }, + position: [2, 4] + }]; - $scope.emptyItems = [{ - name: 'Item1' - }, { - name: 'Item2' - }, { - name: 'Item3' - }, { - name: 'Item4' - }]; + $scope.emptyItems = [{ + name: 'Item1' + }, { + name: 'Item2' + }, { + name: 'Item3' + }, { + name: 'Item4' + }]; - // map the gridsterItem to the custom item structure - $scope.customItemMap = { - sizeX: 'item.size.x', - sizeY: 'item.size.y', - row: 'item.position[0]', - col: 'item.position[1]' - }; + // map the gridsterItem to the custom item structure + $scope.customItemMap = { + sizeX: 'item.size.x', + sizeY: 'item.size.y', + row: 'item.position[0]', + col: 'item.position[1]' + }; -}); + }); diff --git a/dist/angular-gridster.min.js b/dist/angular-gridster.min.js index 07d7c878..86f61099 100644 --- a/dist/angular-gridster.min.js +++ b/dist/angular-gridster.min.js @@ -5,4 +5,4 @@ * @version: 0.13.14 * @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,sparse:!1,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.allItems=[],this.destroy=function(){this.grid&&(this.grid=[]),this.$element=null,this.allItems&&(this.allItems.length=0,this.allItems=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;c-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;b=a.col&&d<=a.row+a.sizeY-1&&e>=a.row},this.removeItem=function(a){for(var b,c=0,d=this.grid.length;c-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||c.indexOf(h)===-1)&&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;b=b)){for(;a.row-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;e0?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(){g.css("height",i.gridHeight*i.curRowHeight+(i.outerMargin?i.margins[0]:-i.margins[0])+"px")}function k(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):i.rowHeight.indexOf("*")!==-1?i.curRowHeight=Math.round(i.curColWidth*i.rowHeight.replace("*","").replace(" ","")):i.rowHeight.indexOf("/")!==-1&&(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;bb&&(d=b-p-r,z=h-d),q+ic&&(f=c-q-s,A=i-f),p+=d,q+=f,e.css({top:q+"px",left:p+"px"}),k(a),!0}function o(a){return!(!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing"))&&(z=A=0,l(a),!0)}var p,q,r,s,t,u,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=b[0],E=["select","option","input","textarea","button"],F=null,G=null;this.enable=function(){if(F!==!0){if(F=!0,G)return void G.enable();G=new d(e[0],m,n,o),G.enable()}},this.disable=function(){F!==!1&&(F=!1,G&&G.disable())},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){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,f)})}function j(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;["w","nw","sw"].indexOf(h)!==-1&&(m=e.pixelsToColumns(o,!1));var n=f.row;["n","ne","nw"].indexOf(h)!==-1&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;["n","s"].indexOf(h)===-1&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;["e","w"].indexOf(h)===-1&&(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,f)})}function k(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,f)})}function l(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,i(a),!0}function m(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-g=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-h=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"}),j(a),!0}function n(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,k(a),!0}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],l,m,n),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;l-1&&c>-1&&a.sizeX+c<=this.columns&&a.sizeY+b<=this.maxRows},this.autoSetItemPosition=function(a){for(var b=0;b=a.col&&d<=a.row+a.sizeY-1&&e>=a.row},this.removeItem=function(a){for(var b,c=0,d=this.grid.length;c-1;){for(var e=1,f=b;f>-1;){var g=this.grid[a];if(g){var h=g[f];if(h&&(!c||c.indexOf(h)===-1)&&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;b=b)){for(;a.row-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;e0?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",function(a,c,d){return{scope:!0,restrict:"EAC",controller:"GridsterCtrl",controllerAs:"gridster",compile:function(c){return c.prepend('
'),function(c,e,f,g){function h(){e.css("height",g.gridHeight*g.curRowHeight+(g.outerMargin?g.margins[0]:-g.margins[0])+"px")}function i(a){if(g.setOptions(a),j(e[0])){"auto"===g.width?g.curWidth=e[0].offsetWidth||parseInt(e.css("width"),10):g.curWidth=g.width,"auto"===g.colWidth?g.curColWidth=(g.curWidth+(g.outerMargin?-g.margins[1]:g.margins[1]))/g.columns:g.curColWidth=g.colWidth,g.curRowHeight=g.rowHeight,"string"==typeof g.rowHeight&&("match"===g.rowHeight?g.curRowHeight=Math.round(g.curColWidth):g.rowHeight.indexOf("*")!==-1?g.curRowHeight=Math.round(g.curColWidth*g.rowHeight.replace("*","").replace(" ","")):g.rowHeight.indexOf("/")!==-1&&(g.curRowHeight=Math.round(g.curColWidth/g.rowHeight.replace("/","").replace(" ","")))),g.isMobile=g.mobileModeEnabled&&g.curWidth<=g.mobileBreakPoint;for(var b=0,c=g.grid.length;bb&&(d=b-p-r,z=h-d),q+ic&&(f=c-q-s,A=i-f),p+=d,q+=f,e.css({top:q+"px",left:p+"px"}),k(a),!0}function o(a){return!(!e.hasClass("gridster-item-moving")||e.hasClass("gridster-item-resizing"))&&(z=A=0,l(a),!0)}var p,q,r,s,t,u,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=b[0],E=["select","option","input","textarea","button"],F=null,G=null;this.enable=function(){if(F!==!0){if(F=!0,G)return void G.enable();G=new d(e[0],m,n,o),G.enable()}},this.disable=function(){F!==!1&&(F=!1,G&&G.disable())},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){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,f)})}function j(a){var b=f.row,i=f.col,j=f.sizeX,k=f.sizeY,l=e.resizable&&e.resizable.resize,m=f.col;["w","nw","sw"].indexOf(h)!==-1&&(m=e.pixelsToColumns(o,!1));var n=f.row;["n","ne","nw"].indexOf(h)!==-1&&(n=e.pixelsToRows(p,!1));var s=f.sizeX;["n","s"].indexOf(h)===-1&&(s=e.pixelsToColumns(q,!0));var t=f.sizeY;["e","w"].indexOf(h)===-1&&(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,f)})}function k(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,f)})}function l(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,i(a),!0}function m(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-g=0&&(r+gE&&(f=E-p-r,C=g-f),r+=f),w.indexOf("w")>=0&&(q-h=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"}),j(a),!0}function n(a){return e.draggable.enabled!==u&&(e.draggable.enabled=u,d.$broadcast("gridster-draggable-changed",e)),B=C=0,k(a),!0}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],l,m,n),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;l - + Angular Gridster - + - + - - - + + + - + @@ -59,9 +33,9 @@ Angular Gridster