Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions src/angular-gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,42 @@
}
})

.controller('GridsterCtrl', ['gridsterConfig', '$timeout',
function(gridsterConfig, $timeout) {
.factory('GridsterDelegate', function() {
var instances = {};
return {
getInstances: function(handle) {
return instances;
},
getByHandle: function(handle) {
if (!handle) {
return instances['current'] || null;
}
return instances[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($scope.delegateHandle || 'current', this);
$scope.$on('$destroy', function() {
GridsterDelegate._unregister($scope.delegateHandle || 'current');
});

var gridster = this;

/**
* Create options from gridsterConfig constant
*/
angular.extend(this, gridsterConfig);

this.itemInstances = [];
this.resizable = angular.extend({}, gridsterConfig.resizable || {});
this.draggable = angular.extend({}, gridsterConfig.draggable || {});

Expand All @@ -82,6 +108,10 @@
}, 30);
};

this.getItemInstances = function() {
return this.itemInstances;
};

/**
* A positional array of the items in the grid
*/
Expand Down Expand Up @@ -242,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) {
Expand Down Expand Up @@ -309,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;
Expand Down Expand Up @@ -606,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',
Expand Down