forked from gridstack/gridstack.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
59 lines (57 loc) · 2.51 KB
/
events.js
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
function addEvents(grid, id) {
let g = (id !== undefined ? 'grid' + id + ' ' : '');
grid.on('added removed change', function(event, items) {
let str = '';
items.forEach(function(item) { str += ' (' + item.x + ',' + item.y + ' ' + item.w + 'x' + item.h + ')'; });
console.log(g + event.type + ' ' + items.length + ' items (x,y w h):' + str );
})
.on('enable', function(event) {
let grid = event.target;
console.log(g + 'enable');
})
.on('disable', function(event) {
let grid = event.target;
console.log(g + 'disable');
})
.on('dragstart', function(event, el) {
let n = el.gridstackNode;
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
let y = el.getAttribute('gs-y');
console.log(g + 'dragstart ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')');
})
.on('drag', function(event, el) {
let n = el.gridstackNode;
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
let y = el.getAttribute('gs-y');
// console.log(g + 'drag ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')');
})
.on('dragstop', function(event, el) {
let n = el.gridstackNode;
let x = el.getAttribute('gs-x'); // verify node (easiest) and attr are the same
let y = el.getAttribute('gs-y');
console.log(g + 'dragstop ' + (n.content || '') + ' pos: (' + n.x + ',' + n.y + ') = (' + x + ',' + y + ')');
})
.on('dropped', function(event, previousNode, newNode) {
if (previousNode) {
console.log(g + 'dropped - Removed widget from grid:', previousNode);
}
if (newNode) {
console.log(g + 'dropped - Added widget in grid:', newNode);
}
})
.on('resizestart', function(event, el) {
let n = el.gridstackNode;
let rec = el.getBoundingClientRect();
console.log(`${g} resizestart ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
})
.on('resize', function(event, el) {
let n = el.gridstackNode;
let rec = el.getBoundingClientRect();
console.log(`${g} resize ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
})
.on('resizestop', function(event, el) {
let n = el.gridstackNode;
let rec = el.getBoundingClientRect();
console.log(`${g} resizestop ${n.content || ''} size: (${n.w}x${n.h}) = (${Math.round(rec.width)}x${Math.round(rec.height)})px`);
});
}