/** * gridstack-angular - Angular Gridstack.js directive * @version v0.6.0-dev * @author Kevin Dietrich * @link https://github.com/kdietrich/gridstack-angular#readme * @license MIT */ (function() { 'use strict'; angular.module('gridstack-angular', []); var app = angular.module('gridstack-angular'); app.controller('GridstackController', ['$scope', function($scope) { this.gridstack = null; this.init = function(element, options) { this.gridstack = element.gridstack(options).data('gridstack'); return this.gridstack; }; this.removeItem = function(element) { if(this.gridstack) { return this.gridstack.removeWidget(element, false); } return null; }; this.addItem = function(element) { if(this.gridstack) { this.gridstack.makeWidget(element); return element; } return null; }; }]); })(); (function() { 'use strict'; var app = angular.module('gridstack-angular'); app.directive('gridstack', ['$timeout', function($timeout) { return { restrict: 'A', controller: 'GridstackController', scope: { onChange: '&', onDragStart: '&', onDragStop: '&', onResizeStart: '&', onResizeStop: '&', gridstackHandler: '=?', options: '=' }, link: function(scope, element, attrs, controller, ngModel) { var gridstack = controller.init(element, scope.options); scope.gridstackHandler = gridstack; element.on('change', function(e, items) { $timeout(function() { scope.$apply(); scope.onChange({event: e, items: items}); }); }); element.on('dragstart', function(e, ui) { scope.onDragStart({event: e, ui: ui}); }); element.on('dragstop', function(e, ui) { $timeout(function() { scope.$apply(); scope.onDragStop({event: e, ui: ui}); }); }); element.on('resizestart', function(e, ui) { scope.onResizeStart({event: e, ui: ui}); }); element.on('resizestop', function(e, ui) { $timeout(function() { scope.$apply(); scope.onResizeStop({event: e, ui: ui}); }); }); } }; }]); })(); (function() { 'use strict'; var app = angular.module('gridstack-angular'); app.directive('gridstackItem', ['$timeout', function($timeout) { return { restrict: 'A', controller: 'GridstackController', require: '^gridstack', scope: { gridstackItem: '=', onItemAdded: '&', onItemRemoved: '&', gsItemId: '=?', gsItemX: '=', gsItemY: '=', gsItemWidth: '=', gsItemHeight: '=', gsItemAutopos: '=', gsItemMinHeight: '=?', gsItemMaxHeight: '=?', gsItemMinWidth: '=?', gsItemMaxWidth: '=?' }, link: function(scope, element, attrs, controller) { if (scope.gsItemId) { $(element).attr('data-gs-id', scope.gsItemId); } $(element).attr('data-gs-x', scope.gsItemX); $(element).attr('data-gs-y', scope.gsItemY); $(element).attr('data-gs-width', scope.gsItemWidth); $(element).attr('data-gs-height', scope.gsItemHeight); $(element).attr('data-gs-min-width', scope.gsItemMinWidth); $(element).attr('data-gs-min-height', scope.gsItemMinHeight); $(element).attr('data-gs-max-width', scope.gsItemMaxWidth); $(element).attr('data-gs-max-height', scope.gsItemMaxHeight); $(element).attr('data-gs-auto-position', scope.gsItemAutopos); var widget = controller.addItem(element); var item = element.data('_gridstack_node'); $timeout(function() { scope.onItemAdded({item: item}); }); var propertyChanged = function(newVal, oldVal) { if(newVal != oldVal) { controller.gridstack.update($(element), scope.gsItemX, scope.gsItemY, scope.gsItemWidth, scope.gsItemHeight); } }; scope.$watch(function() { return $(element).attr('data-gs-id'); }, function(val) { scope.gsItemId = val; }); scope.$watch(function() { return $(element).attr('data-gs-x'); }, function(val) { scope.gsItemX = Number(val); }); scope.$watch(function() { return $(element).attr('data-gs-y'); }, function(val) { scope.gsItemY = Number(val); }); scope.$watch(function() { return $(element).attr('data-gs-width'); }, function(val) { scope.gsItemWidth = Number(val); }); scope.$watch(function() { return $(element).attr('data-gs-height'); }, function(val) { scope.gsItemHeight = Number(val); }); scope.$watch('gsItemX', propertyChanged); scope.$watch('gsItemY', propertyChanged); scope.$watch('gsItemWidth', propertyChanged); scope.$watch('gsItemHeight', propertyChanged); element.bind('$destroy', function() { var item = element.data('_gridstack_node'); scope.onItemRemoved({item: item}); controller.removeItem(element); }); } }; }]); })();