-
Notifications
You must be signed in to change notification settings - Fork 3
/
draggable.js
103 lines (90 loc) · 3.13 KB
/
draggable.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Ext.onReady(function() {
Ext.create('Ext.container.Viewport', {
layout: 'vbox',
items: [{
xtype: 'panel',
title: 'Drop a Panel Here',
listeners: { render: initializeDropTarget },
cls: 'x-dd-drop-ok',
layout: {
type: 'vbox',
stretch: 'align'
},
width: 300,
height: 300
}, {
xtype: 'panel',
title: 'Drag This Panel',
draggable: true,
bodyCls: 'green-body',
width: 300,
height: 100
}, {
xtype: 'panel',
title: 'Drag This Panel',
draggable: true,
bodyCls: 'blue-body',
width: 300,
height: 100
}, {
xtype: 'panel',
title: 'Drag This Panel',
draggable: true,
bodyCls: 'red-body',
width: 300,
height: 100
}]
});
});
/**
Initialize the DropTarget object associated
with our panel. The 'cmp' argument will be
the panel (a Component object).
*/
function initializeDropTarget(targetPanel) {
// Create the DropTarget object and assign it to the panel. Does not
// have to be assigned to the panel but needs to be assigned to something,
// or it will get garbage-collected too soon.
targetPanel.dropTarget = Ext.create('Ext.dd.DropTarget', targetPanel.el);
// Called once, when dragged item is dropped in the target area. Return false
// to indicate an invalid drop. DO NOT MODIFY the UI in
// this function. Use afterDragDrop and the data object.
targetPanel.dropTarget.notifyDrop = function(source, evt, data) {
if(typeof console != "undefined")
console.log("notifyDrop:" + source.id);
// The component that was dropped.
var droppedPanel = Ext.getCmp(source.id);
// We can't modify the component that was dropped in this
// function. However, we can add an event handler on the component
// that will be called shortly.
//
// In the handler we clone the component (not strictly necessary, we could
// do that here) and then remove our old component.
droppedPanel.dd.afterValidDrop = function() {
targetPanel.add(droppedPanel.cloneConfig({
draggable: false,
title: "Can't Drag This Panel."
}));
droppedPanel.destroy();
};
return true;
};
// Called once, when dragged item enters drop area.
targetPanel.dropTarget.notifyEnter = function(source, evt, data) {
if(typeof console != "undefined")
console.log("notifyEnter:" + source.id);
return this.callParent(Array.prototype.slice.call(arguments));
};
// Called once, when dragged item leaves drop area.
targetPanel.dropTarget.notifyOut = function(source, evt, data) {
if(typeof console != "undefined")
console.log("notifyOut:" + source.id);
return this.callParent(Array.prototype.slice.call(arguments));
};
// Called for each mouse movement as dragged item is over the drop area.
targetPanel.dropTarget.notifyOver = function(source, evt, data) {
if(typeof console != "undefined")
console.log("notifyOver:" + source.id);
return this.callParent(Array.prototype.slice.call(arguments));
};
}