forked from pankajparkar/gridstack-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridstackitem.directive.js
More file actions
77 lines (65 loc) · 2.32 KB
/
Copy pathgridstackitem.directive.js
File metadata and controls
77 lines (65 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(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});
});
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);
});
element.bind('$destroy', function() {
var item = element.data('_gridstack_node');
scope.onItemRemoved({item: item});
controller.removeItem(element);
});
}
};
}]);
})();