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
67 lines (56 loc) · 2 KB
/
Copy pathgridstackitem.directive.js
File metadata and controls
67 lines (56 loc) · 2 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
(function() {
'use strict';
var app = angular.module('gridstack-angular');
/** @ngInject */
app.directive('gridstackItem', ['$timeout', function($timeout) {
return {
restrict: "A",
controller: 'GridstackController',
require: '^gridstack',
scope: {
gridstackItem: '=',
onItemAdded: '&',
onItemRemoved: '&',
gsItemId: '=',
gsItemX: '=',
gsItemY: '=',
gsItemWidth: '=',
gsItemHeight: '=',
gsItemAutopos: '='
},
link: function (scope, element, attrs, controller) {
$(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-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 = val;
});
scope.$watch(function(){ return $(element).attr('data-gs-y'); }, function(val) {
scope.gsItemY = val;
});
scope.$watch(function(){ return $(element).attr('data-gs-width'); }, function(val) {
scope.gsItemWidth = val;
});
scope.$watch(function(){ return $(element).attr('data-gs-height'); }, function(val) {
scope.gsItemHeight = val;
});
element.bind('$destroy', function() {
var item = element.data('_gridstack_node');
scope.onItemRemoved({item: item});
controller.removeItem(element);
});
}
};
}]);
})();