|
6 | 6 | * @license MIT |
7 | 7 | */ |
8 | 8 | (function() { |
9 | | - 'use strict'; |
| 9 | +'use strict'; |
10 | 10 |
|
11 | | - angular.module('gridstack-angular', []); |
| 11 | +angular.module('gridstack-angular', []); |
12 | 12 |
|
13 | | - var app = angular.module('gridstack-angular'); |
| 13 | +var app = angular.module('gridstack-angular'); |
14 | 14 |
|
15 | | - /** @ngInject */ |
16 | | - app.controller('GridstackController', ['$scope', function($scope) { |
| 15 | +app.controller('GridstackController', ['$scope', function($scope) { |
17 | 16 |
|
18 | | - var gridstack = null; |
| 17 | + var gridstack = null; |
19 | 18 |
|
20 | | - this.init = function(element, options) { |
21 | | - gridstack = element.gridstack(options).data('gridstack'); |
22 | | - return gridstack; |
23 | | - }; |
| 19 | + this.init = function(element, options) { |
| 20 | + gridstack = element.gridstack(options).data('gridstack'); |
| 21 | + return gridstack; |
| 22 | + }; |
24 | 23 |
|
25 | | - this.removeItem = function(element) { |
26 | | - if(gridstack) { |
27 | | - return gridstack.removeWidget(element, false); |
28 | | - } |
29 | | - return null; |
30 | | - }; |
| 24 | + this.removeItem = function(element) { |
| 25 | + if(gridstack) { |
| 26 | + return gridstack.removeWidget(element, false); |
| 27 | + } |
| 28 | + return null; |
| 29 | + }; |
31 | 30 |
|
32 | | - this.addItem = function(element) { |
33 | | - if(gridstack) { |
34 | | - gridstack.makeWidget(element); |
35 | | - return element; |
36 | | - } |
37 | | - return null; |
38 | | - }; |
| 31 | + this.addItem = function(element) { |
| 32 | + if(gridstack) { |
| 33 | + gridstack.makeWidget(element); |
| 34 | + return element; |
| 35 | + } |
| 36 | + return null; |
| 37 | + }; |
39 | 38 |
|
40 | | - }]); |
| 39 | +}]); |
41 | 40 | })(); |
42 | 41 | (function() { |
43 | | - 'use strict'; |
44 | | - |
45 | | - var app = angular.module('gridstack-angular'); |
46 | | - |
47 | | - /** @ngInject */ |
48 | | - app.directive('gridstack', ['$timeout', function($timeout) { |
49 | | - |
50 | | - return { |
51 | | - restrict: "A", |
52 | | - controller: 'GridstackController', |
53 | | - scope: { |
54 | | - onChange: '&', |
55 | | - onDragStart: '&', |
56 | | - onDragStop: '&', |
57 | | - onResizeStart: '&', |
58 | | - onResizeStop: '&', |
59 | | - gridstackHandler: '=', |
60 | | - options: '=' |
61 | | - }, |
62 | | - link: function (scope, element, attrs, controller, ngModel) { |
63 | | - |
64 | | - var gridstack = controller.init(element, scope.options); |
65 | | - scope.gridstackHandler = gridstack; |
66 | | - |
67 | | - element.on('change', function (e, items) { |
68 | | - $timeout(function() { |
69 | | - scope.$apply(); |
70 | | - scope.onChange({event: e, items: items}); |
71 | | - }); |
| 42 | +'use strict'; |
| 43 | + |
| 44 | +var app = angular.module('gridstack-angular'); |
| 45 | + |
| 46 | +app.directive('gridstack', ['$timeout', function($timeout) { |
| 47 | + |
| 48 | + return { |
| 49 | + restrict: 'A', |
| 50 | + controller: 'GridstackController', |
| 51 | + scope: { |
| 52 | + onChange: '&', |
| 53 | + onDragStart: '&', |
| 54 | + onDragStop: '&', |
| 55 | + onResizeStart: '&', |
| 56 | + onResizeStop: '&', |
| 57 | + gridstackHandler: '=', |
| 58 | + options: '=' |
| 59 | + }, |
| 60 | + link: function(scope, element, attrs, controller, ngModel) { |
| 61 | + |
| 62 | + var gridstack = controller.init(element, scope.options); |
| 63 | + scope.gridstackHandler = gridstack; |
| 64 | + |
| 65 | + element.on('change', function(e, items) { |
| 66 | + $timeout(function() { |
| 67 | + scope.$apply(); |
| 68 | + scope.onChange({event: e, items: items}); |
72 | 69 | }); |
| 70 | + }); |
73 | 71 |
|
74 | | - element.on('dragstart', function(e, ui) { |
75 | | - scope.onDragStart({event: e, ui: ui}); |
76 | | - }); |
| 72 | + element.on('dragstart', function(e, ui) { |
| 73 | + scope.onDragStart({event: e, ui: ui}); |
| 74 | + }); |
77 | 75 |
|
78 | | - element.on('dragstop', function(e, ui) { |
79 | | - $timeout(function() { |
80 | | - scope.$apply(); |
81 | | - scope.onDragStop({event: e, ui: ui}); |
82 | | - }); |
| 76 | + element.on('dragstop', function(e, ui) { |
| 77 | + $timeout(function() { |
| 78 | + scope.$apply(); |
| 79 | + scope.onDragStop({event: e, ui: ui}); |
83 | 80 | }); |
| 81 | + }); |
84 | 82 |
|
85 | | - element.on('resizestart', function(e, ui) { |
86 | | - scope.onResizeStart({event: e, ui: ui}); |
87 | | - }); |
| 83 | + element.on('resizestart', function(e, ui) { |
| 84 | + scope.onResizeStart({event: e, ui: ui}); |
| 85 | + }); |
88 | 86 |
|
89 | | - element.on('resizestop', function(e, ui) { |
90 | | - $timeout(function() { |
91 | | - scope.$apply(); |
92 | | - scope.onResizeStop({event: e, ui: ui}); |
93 | | - }); |
| 87 | + element.on('resizestop', function(e, ui) { |
| 88 | + $timeout(function() { |
| 89 | + scope.$apply(); |
| 90 | + scope.onResizeStop({event: e, ui: ui}); |
94 | 91 | }); |
| 92 | + }); |
95 | 93 |
|
96 | | - } |
97 | | - }; |
| 94 | + } |
| 95 | + }; |
98 | 96 |
|
99 | | - }]); |
| 97 | +}]); |
100 | 98 | })(); |
101 | 99 |
|
102 | 100 | (function() { |
103 | | - 'use strict'; |
104 | | - |
105 | | - var app = angular.module('gridstack-angular'); |
106 | | - |
107 | | - /** @ngInject */ |
108 | | - app.directive('gridstackItem', ['$timeout', function($timeout) { |
109 | | - |
110 | | - return { |
111 | | - restrict: "A", |
112 | | - controller: 'GridstackController', |
113 | | - require: '^gridstack', |
114 | | - scope: { |
115 | | - gridstackItem: '=', |
116 | | - onItemAdded: '&', |
117 | | - onItemRemoved: '&', |
118 | | - gsItemId: '=', |
119 | | - gsItemX: '=', |
120 | | - gsItemY: '=', |
121 | | - gsItemWidth: '=', |
122 | | - gsItemHeight: '=', |
123 | | - gsItemAutopos: '=' |
124 | | - }, |
125 | | - link: function (scope, element, attrs, controller) { |
126 | | - $(element).attr('data-gs-id', scope.gsItemId); |
127 | | - $(element).attr('data-gs-x', scope.gsItemX); |
128 | | - $(element).attr('data-gs-y', scope.gsItemY); |
129 | | - $(element).attr('data-gs-width', scope.gsItemWidth); |
130 | | - $(element).attr('data-gs-height', scope.gsItemHeight); |
131 | | - $(element).attr('data-gs-auto-position', scope.gsItemAutopos); |
132 | | - var widget = controller.addItem(element); |
| 101 | +'use strict'; |
| 102 | + |
| 103 | +var app = angular.module('gridstack-angular'); |
| 104 | + |
| 105 | +app.directive('gridstackItem', ['$timeout', function($timeout) { |
| 106 | + |
| 107 | + return { |
| 108 | + restrict: 'A', |
| 109 | + controller: 'GridstackController', |
| 110 | + require: '^gridstack', |
| 111 | + scope: { |
| 112 | + gridstackItem: '=', |
| 113 | + onItemAdded: '&', |
| 114 | + onItemRemoved: '&', |
| 115 | + gsItemId: '=', |
| 116 | + gsItemX: '=', |
| 117 | + gsItemY: '=', |
| 118 | + gsItemWidth: '=', |
| 119 | + gsItemHeight: '=', |
| 120 | + gsItemAutopos: '=' |
| 121 | + }, |
| 122 | + link: function(scope, element, attrs, controller) { |
| 123 | + $(element).attr('data-gs-id', scope.gsItemId); |
| 124 | + $(element).attr('data-gs-x', scope.gsItemX); |
| 125 | + $(element).attr('data-gs-y', scope.gsItemY); |
| 126 | + $(element).attr('data-gs-width', scope.gsItemWidth); |
| 127 | + $(element).attr('data-gs-height', scope.gsItemHeight); |
| 128 | + $(element).attr('data-gs-auto-position', scope.gsItemAutopos); |
| 129 | + var widget = controller.addItem(element); |
| 130 | + var item = element.data('_gridstack_node'); |
| 131 | + $timeout(function() { |
| 132 | + scope.onItemAdded({item: item}); |
| 133 | + }); |
| 134 | + |
| 135 | + scope.$watch(function() { return $(element).attr('data-gs-id'); }, function(val) { |
| 136 | + scope.gsItemId = val; |
| 137 | + }); |
| 138 | + |
| 139 | + scope.$watch(function() { return $(element).attr('data-gs-x'); }, function(val) { |
| 140 | + scope.gsItemX = val; |
| 141 | + }); |
| 142 | + |
| 143 | + scope.$watch(function() { return $(element).attr('data-gs-y'); }, function(val) { |
| 144 | + scope.gsItemY = val; |
| 145 | + }); |
| 146 | + |
| 147 | + scope.$watch(function() { return $(element).attr('data-gs-width'); }, function(val) { |
| 148 | + scope.gsItemWidth = val; |
| 149 | + }); |
| 150 | + |
| 151 | + scope.$watch(function() { return $(element).attr('data-gs-height'); }, function(val) { |
| 152 | + scope.gsItemHeight = val; |
| 153 | + }); |
| 154 | + |
| 155 | + element.bind('$destroy', function() { |
133 | 156 | var item = element.data('_gridstack_node'); |
134 | | - $timeout(function() { |
135 | | - scope.onItemAdded({item: item}); |
136 | | - }); |
137 | | - |
138 | | - scope.$watch(function () { return $(element).attr('data-gs-id'); }, function (val) { |
139 | | - scope.gsItemId = val; |
140 | | - }); |
141 | | - scope.$watch(function(){ return $(element).attr('data-gs-x'); }, function(val) { |
142 | | - scope.gsItemX = val; |
143 | | - }); |
144 | | - |
145 | | - scope.$watch(function(){ return $(element).attr('data-gs-y'); }, function(val) { |
146 | | - scope.gsItemY = val; |
147 | | - }); |
148 | | - |
149 | | - scope.$watch(function(){ return $(element).attr('data-gs-width'); }, function(val) { |
150 | | - scope.gsItemWidth = val; |
151 | | - }); |
152 | | - |
153 | | - scope.$watch(function(){ return $(element).attr('data-gs-height'); }, function(val) { |
154 | | - scope.gsItemHeight = val; |
155 | | - }); |
156 | | - |
157 | | - element.bind('$destroy', function() { |
158 | | - var item = element.data('_gridstack_node'); |
159 | | - scope.onItemRemoved({item: item}); |
160 | | - controller.removeItem(element); |
161 | | - }); |
| 157 | + scope.onItemRemoved({item: item}); |
| 158 | + controller.removeItem(element); |
| 159 | + }); |
162 | 160 |
|
163 | | - } |
| 161 | + } |
164 | 162 |
|
165 | | - }; |
| 163 | + }; |
166 | 164 |
|
167 | | - }]); |
| 165 | +}]); |
168 | 166 | })(); |
0 commit comments