From 1c62c2efe13588a73994aeaf29757de818ec4e39 Mon Sep 17 00:00:00 2001 From: Julien Renaux Date: Fri, 22 May 2015 12:02:07 -0500 Subject: [PATCH 1/3] Adding GridsterDelegate factory and register gridster instances --- src/angular-gridster.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index c3998ab1..4d3f0047 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -54,8 +54,34 @@ } }) - .controller('GridsterCtrl', ['gridsterConfig', '$timeout', - function(gridsterConfig, $timeout) { + .factory('GridsterDelegate', function() { + var instances = {}; + return { + getInstances: function(handle) { + return instances; + }, + getByHandle: function(handle) { + if (!handle) { + return this.getInstances['current'] || null; + } + return this.getInstances[handle] || null; + }, + _register: function(handle, instance) { + instances[handle] = instance; + }, + _unregister: function(handle) { + delete instances[handle]; + } + } + }) + + .controller('GridsterCtrl', ['$scope', '$attrs', 'gridsterConfig', '$timeout', 'GridsterDelegate', + function($scope, $attrs, gridsterConfig, $timeout, GridsterDelegate) { + + GridsterDelegate._register($attrs.delegateHandle || 'current', this); + $scope.$on('$destroy', function() { + GridsterDelegate._unregister($attrs.delegateHandle); + }); var gridster = this; From 42d9b5e35f35d545defa22a42b218b7d0ea7778a Mon Sep 17 00:00:00 2001 From: Julien Renaux Date: Fri, 22 May 2015 12:47:14 -0500 Subject: [PATCH 2/3] Register gridsterItem instances --- src/angular-gridster.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index 4d3f0047..f3a52018 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -62,9 +62,9 @@ }, getByHandle: function(handle) { if (!handle) { - return this.getInstances['current'] || null; + return instances['current'] || null; } - return this.getInstances[handle] || null; + return instances[handle] || null; }, _register: function(handle, instance) { instances[handle] = instance; @@ -89,7 +89,7 @@ * Create options from gridsterConfig constant */ angular.extend(this, gridsterConfig); - + this.itemInstances = []; this.resizable = angular.extend({}, gridsterConfig.resizable || {}); this.draggable = angular.extend({}, gridsterConfig.draggable || {}); @@ -108,6 +108,10 @@ }, 30); }; + this.getItemInstances = function() { + return this.itemInstances; + }; + /** * A positional array of the items in the grid */ @@ -268,6 +272,10 @@ * @param {Object} item */ this.removeItem = function(item) { + var index = this.itemInstances.indexOf(item); + if (index >= 0) { + this.itemInstances.splice(index, 1); + } for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { var columns = this.grid[rowIndex]; if (!columns) { @@ -335,6 +343,10 @@ * @param {Array} ignoreItems */ this.putItem = function(item, row, column, ignoreItems) { + // register instance for programmatically calls + if (this.itemInstances.indexOf(item) === -1) { + this.itemInstances.push(item); + } // auto place item if no row specified if (typeof row === 'undefined' || row === null) { row = item.row; From d595a1ef04344f4192e7672ed365a48e04f01f7d Mon Sep 17 00:00:00 2001 From: shprink Date: Thu, 28 May 2015 10:06:09 -0500 Subject: [PATCH 3/3] allow delegateHandle interpretation delegate-handle="dashboard-{{id}}" --- src/angular-gridster.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/angular-gridster.js b/src/angular-gridster.js index f3a52018..acc66197 100755 --- a/src/angular-gridster.js +++ b/src/angular-gridster.js @@ -78,9 +78,9 @@ .controller('GridsterCtrl', ['$scope', '$attrs', 'gridsterConfig', '$timeout', 'GridsterDelegate', function($scope, $attrs, gridsterConfig, $timeout, GridsterDelegate) { - GridsterDelegate._register($attrs.delegateHandle || 'current', this); + GridsterDelegate._register($scope.delegateHandle || 'current', this); $scope.$on('$destroy', function() { - GridsterDelegate._unregister($attrs.delegateHandle); + GridsterDelegate._unregister($scope.delegateHandle || 'current'); }); var gridster = this; @@ -644,7 +644,9 @@ .directive('gridster', ['$timeout', '$window', '$rootScope', 'gridsterDebounce', function($timeout, $window, $rootScope, gridsterDebounce) { return { - scope: true, + scope: { + delegateHandle: "@", + }, restrict: 'EAC', controller: 'GridsterCtrl', controllerAs: 'gridster',